splide.esm.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863
  1. /*!
  2. * Splide.js
  3. * Version : 3.6.14
  4. * License : MIT
  5. * Copyright: 2022 Naotoshi Fujita
  6. */
  7. const CREATED = 1;
  8. const MOUNTED = 2;
  9. const IDLE = 3;
  10. const MOVING = 4;
  11. const DRAGGING = 5;
  12. const DESTROYED = 6;
  13. const STATES = {
  14. CREATED,
  15. MOUNTED,
  16. IDLE,
  17. MOVING,
  18. DRAGGING,
  19. DESTROYED
  20. };
  21. const DEFAULT_EVENT_PRIORITY = 10;
  22. const DEFAULT_USER_EVENT_PRIORITY = 20;
  23. function empty(array) {
  24. array.length = 0;
  25. }
  26. function isObject(subject) {
  27. return !isNull(subject) && typeof subject === "object";
  28. }
  29. function isArray(subject) {
  30. return Array.isArray(subject);
  31. }
  32. function isFunction(subject) {
  33. return typeof subject === "function";
  34. }
  35. function isString(subject) {
  36. return typeof subject === "string";
  37. }
  38. function isUndefined(subject) {
  39. return typeof subject === "undefined";
  40. }
  41. function isNull(subject) {
  42. return subject === null;
  43. }
  44. function isHTMLElement(subject) {
  45. return subject instanceof HTMLElement;
  46. }
  47. function toArray(value) {
  48. return isArray(value) ? value : [value];
  49. }
  50. function forEach(values, iteratee) {
  51. toArray(values).forEach(iteratee);
  52. }
  53. function includes(array, value) {
  54. return array.indexOf(value) > -1;
  55. }
  56. function push(array, items) {
  57. array.push(...toArray(items));
  58. return array;
  59. }
  60. const arrayProto = Array.prototype;
  61. function slice(arrayLike, start, end) {
  62. return arrayProto.slice.call(arrayLike, start, end);
  63. }
  64. function find(arrayLike, predicate) {
  65. return slice(arrayLike).filter(predicate)[0];
  66. }
  67. function toggleClass(elm, classes, add) {
  68. if (elm) {
  69. forEach(classes, (name) => {
  70. if (name) {
  71. elm.classList[add ? "add" : "remove"](name);
  72. }
  73. });
  74. }
  75. }
  76. function addClass(elm, classes) {
  77. toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
  78. }
  79. function append(parent, children) {
  80. forEach(children, parent.appendChild.bind(parent));
  81. }
  82. function before(nodes, ref) {
  83. forEach(nodes, (node) => {
  84. const parent = ref.parentNode;
  85. if (parent) {
  86. parent.insertBefore(node, ref);
  87. }
  88. });
  89. }
  90. function matches(elm, selector) {
  91. return isHTMLElement(elm) && (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
  92. }
  93. function children(parent, selector) {
  94. return parent ? slice(parent.children).filter((child) => matches(child, selector)) : [];
  95. }
  96. function child(parent, selector) {
  97. return selector ? children(parent, selector)[0] : parent.firstElementChild;
  98. }
  99. function forOwn(object, iteratee, right) {
  100. if (object) {
  101. let keys = Object.keys(object);
  102. keys = right ? keys.reverse() : keys;
  103. for (let i = 0; i < keys.length; i++) {
  104. const key = keys[i];
  105. if (key !== "__proto__") {
  106. if (iteratee(object[key], key) === false) {
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. return object;
  113. }
  114. function assign(object) {
  115. slice(arguments, 1).forEach((source) => {
  116. forOwn(source, (value, key) => {
  117. object[key] = source[key];
  118. });
  119. });
  120. return object;
  121. }
  122. function merge(object, source) {
  123. forOwn(source, (value, key) => {
  124. if (isArray(value)) {
  125. object[key] = value.slice();
  126. } else if (isObject(value)) {
  127. object[key] = merge(isObject(object[key]) ? object[key] : {}, value);
  128. } else {
  129. object[key] = value;
  130. }
  131. });
  132. return object;
  133. }
  134. function removeAttribute(elms, attrs) {
  135. forEach(elms, (elm) => {
  136. forEach(attrs, (attr) => {
  137. elm && elm.removeAttribute(attr);
  138. });
  139. });
  140. }
  141. function setAttribute(elms, attrs, value) {
  142. if (isObject(attrs)) {
  143. forOwn(attrs, (value2, name) => {
  144. setAttribute(elms, name, value2);
  145. });
  146. } else {
  147. forEach(elms, (elm) => {
  148. isNull(value) ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
  149. });
  150. }
  151. }
  152. function create(tag, attrs, parent) {
  153. const elm = document.createElement(tag);
  154. if (attrs) {
  155. isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
  156. }
  157. parent && append(parent, elm);
  158. return elm;
  159. }
  160. function style(elm, prop, value) {
  161. if (isUndefined(value)) {
  162. return getComputedStyle(elm)[prop];
  163. }
  164. if (!isNull(value)) {
  165. const { style: style2 } = elm;
  166. value = `${value}`;
  167. if (style2[prop] !== value) {
  168. style2[prop] = value;
  169. }
  170. }
  171. }
  172. function display(elm, display2) {
  173. style(elm, "display", display2);
  174. }
  175. function focus(elm) {
  176. elm["setActive"] && elm["setActive"]() || elm.focus({ preventScroll: true });
  177. }
  178. function getAttribute(elm, attr) {
  179. return elm.getAttribute(attr);
  180. }
  181. function hasClass(elm, className) {
  182. return elm && elm.classList.contains(className);
  183. }
  184. function rect(target) {
  185. return target.getBoundingClientRect();
  186. }
  187. function remove(nodes) {
  188. forEach(nodes, (node) => {
  189. if (node && node.parentNode) {
  190. node.parentNode.removeChild(node);
  191. }
  192. });
  193. }
  194. function measure(parent, value) {
  195. if (isString(value)) {
  196. const div = create("div", { style: `width: ${value}; position: absolute;` }, parent);
  197. value = rect(div).width;
  198. remove(div);
  199. }
  200. return value;
  201. }
  202. function parseHtml(html) {
  203. return child(new DOMParser().parseFromString(html, "text/html").body);
  204. }
  205. function prevent(e, stopPropagation) {
  206. e.preventDefault();
  207. if (stopPropagation) {
  208. e.stopPropagation();
  209. e.stopImmediatePropagation();
  210. }
  211. }
  212. function query(parent, selector) {
  213. return parent && parent.querySelector(selector);
  214. }
  215. function queryAll(parent, selector) {
  216. return slice(parent.querySelectorAll(selector));
  217. }
  218. function removeClass(elm, classes) {
  219. toggleClass(elm, classes, false);
  220. }
  221. function unit(value) {
  222. return isString(value) ? value : value ? `${value}px` : "";
  223. }
  224. const PROJECT_CODE = "splide";
  225. const DATA_ATTRIBUTE = `data-${PROJECT_CODE}`;
  226. function assert(condition, message) {
  227. if (!condition) {
  228. throw new Error(`[${PROJECT_CODE}] ${message || ""}`);
  229. }
  230. }
  231. function apply(func) {
  232. return func.bind(null, ...slice(arguments, 1));
  233. }
  234. const nextTick = setTimeout;
  235. const noop = () => {
  236. };
  237. function raf(func) {
  238. return requestAnimationFrame(func);
  239. }
  240. const { min, max, floor, ceil, abs } = Math;
  241. function approximatelyEqual(x, y, epsilon) {
  242. return abs(x - y) < epsilon;
  243. }
  244. function between(number, minOrMax, maxOrMin, exclusive) {
  245. const minimum = min(minOrMax, maxOrMin);
  246. const maximum = max(minOrMax, maxOrMin);
  247. return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
  248. }
  249. function clamp(number, x, y) {
  250. const minimum = min(x, y);
  251. const maximum = max(x, y);
  252. return min(max(minimum, number), maximum);
  253. }
  254. function sign(x) {
  255. return +(x > 0) - +(x < 0);
  256. }
  257. function camelToKebab(string) {
  258. return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
  259. }
  260. function format(string, replacements) {
  261. forEach(replacements, (replacement) => {
  262. string = string.replace("%s", `${replacement}`);
  263. });
  264. return string;
  265. }
  266. function pad(number) {
  267. return number < 10 ? `0${number}` : `${number}`;
  268. }
  269. const ids = {};
  270. function uniqueId(prefix) {
  271. return `${prefix}${pad(ids[prefix] = (ids[prefix] || 0) + 1)}`;
  272. }
  273. function EventBus() {
  274. let handlers = {};
  275. function on(events, callback, key, priority = DEFAULT_EVENT_PRIORITY) {
  276. forEachEvent(events, (event, namespace) => {
  277. handlers[event] = handlers[event] || [];
  278. push(handlers[event], {
  279. _event: event,
  280. _callback: callback,
  281. _namespace: namespace,
  282. _priority: priority,
  283. _key: key
  284. }).sort((handler1, handler2) => handler1._priority - handler2._priority);
  285. });
  286. }
  287. function off(events, key) {
  288. forEachEvent(events, (event, namespace) => {
  289. const eventHandlers = handlers[event];
  290. handlers[event] = eventHandlers && eventHandlers.filter((handler) => {
  291. return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
  292. });
  293. });
  294. }
  295. function offBy(key) {
  296. forOwn(handlers, (eventHandlers, event) => {
  297. off(event, key);
  298. });
  299. }
  300. function emit(event) {
  301. (handlers[event] || []).forEach((handler) => {
  302. handler._callback.apply(handler, slice(arguments, 1));
  303. });
  304. }
  305. function destroy() {
  306. handlers = {};
  307. }
  308. function forEachEvent(events, iteratee) {
  309. toArray(events).join(" ").split(" ").forEach((eventNS) => {
  310. const fragments = eventNS.split(".");
  311. iteratee(fragments[0], fragments[1]);
  312. });
  313. }
  314. return {
  315. on,
  316. off,
  317. offBy,
  318. emit,
  319. destroy
  320. };
  321. }
  322. const EVENT_MOUNTED = "mounted";
  323. const EVENT_READY = "ready";
  324. const EVENT_MOVE = "move";
  325. const EVENT_MOVED = "moved";
  326. const EVENT_SHIFTED = "shifted";
  327. const EVENT_CLICK = "click";
  328. const EVENT_ACTIVE = "active";
  329. const EVENT_INACTIVE = "inactive";
  330. const EVENT_VISIBLE = "visible";
  331. const EVENT_HIDDEN = "hidden";
  332. const EVENT_SLIDE_KEYDOWN = "slide:keydown";
  333. const EVENT_REFRESH = "refresh";
  334. const EVENT_UPDATED = "updated";
  335. const EVENT_RESIZE = "resize";
  336. const EVENT_RESIZED = "resized";
  337. const EVENT_REPOSITIONED = "repositioned";
  338. const EVENT_DRAG = "drag";
  339. const EVENT_DRAGGING = "dragging";
  340. const EVENT_DRAGGED = "dragged";
  341. const EVENT_SCROLL = "scroll";
  342. const EVENT_SCROLLED = "scrolled";
  343. const EVENT_DESTROY = "destroy";
  344. const EVENT_ARROWS_MOUNTED = "arrows:mounted";
  345. const EVENT_ARROWS_UPDATED = "arrows:updated";
  346. const EVENT_PAGINATION_MOUNTED = "pagination:mounted";
  347. const EVENT_PAGINATION_UPDATED = "pagination:updated";
  348. const EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
  349. const EVENT_AUTOPLAY_PLAY = "autoplay:play";
  350. const EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
  351. const EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
  352. const EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
  353. function EventInterface(Splide2) {
  354. const { event } = Splide2;
  355. const key = {};
  356. let listeners = [];
  357. function on(events, callback, priority) {
  358. event.on(events, callback, key, priority);
  359. }
  360. function off(events) {
  361. event.off(events, key);
  362. }
  363. function bind(targets, events, callback, options) {
  364. forEachEvent(targets, events, (target, event2) => {
  365. listeners.push([target, event2, callback, options]);
  366. target.addEventListener(event2, callback, options);
  367. });
  368. }
  369. function unbind(targets, events, callback) {
  370. forEachEvent(targets, events, (target, event2) => {
  371. listeners = listeners.filter((listener) => {
  372. if (listener[0] === target && listener[1] === event2 && (!callback || listener[2] === callback)) {
  373. target.removeEventListener(event2, listener[2], listener[3]);
  374. return false;
  375. }
  376. return true;
  377. });
  378. });
  379. }
  380. function forEachEvent(targets, events, iteratee) {
  381. forEach(targets, (target) => {
  382. if (target) {
  383. events.split(" ").forEach(apply(iteratee, target));
  384. }
  385. });
  386. }
  387. function destroy() {
  388. listeners = listeners.filter((data) => unbind(data[0], data[1]));
  389. event.offBy(key);
  390. }
  391. event.on(EVENT_DESTROY, destroy, key);
  392. return {
  393. on,
  394. off,
  395. emit: event.emit,
  396. bind,
  397. unbind,
  398. destroy
  399. };
  400. }
  401. function RequestInterval(interval, onInterval, onUpdate, limit) {
  402. const { now } = Date;
  403. let startTime;
  404. let rate = 0;
  405. let id;
  406. let paused = true;
  407. let count = 0;
  408. function update() {
  409. if (!paused) {
  410. const elapsed = now() - startTime;
  411. if (elapsed >= interval) {
  412. rate = 1;
  413. startTime = now();
  414. } else {
  415. rate = elapsed / interval;
  416. }
  417. if (onUpdate) {
  418. onUpdate(rate);
  419. }
  420. if (rate === 1) {
  421. onInterval();
  422. if (limit && ++count >= limit) {
  423. return pause();
  424. }
  425. }
  426. raf(update);
  427. }
  428. }
  429. function start(resume) {
  430. !resume && cancel();
  431. startTime = now() - (resume ? rate * interval : 0);
  432. paused = false;
  433. raf(update);
  434. }
  435. function pause() {
  436. paused = true;
  437. }
  438. function rewind() {
  439. startTime = now();
  440. rate = 0;
  441. if (onUpdate) {
  442. onUpdate(rate);
  443. }
  444. }
  445. function cancel() {
  446. cancelAnimationFrame(id);
  447. rate = 0;
  448. id = 0;
  449. paused = true;
  450. }
  451. function set(time) {
  452. interval = time;
  453. }
  454. function isPaused() {
  455. return paused;
  456. }
  457. return {
  458. start,
  459. rewind,
  460. pause,
  461. cancel,
  462. set,
  463. isPaused
  464. };
  465. }
  466. function State(initialState) {
  467. let state = initialState;
  468. function set(value) {
  469. state = value;
  470. }
  471. function is(states) {
  472. return includes(toArray(states), state);
  473. }
  474. return { set, is };
  475. }
  476. function Throttle(func, duration) {
  477. let interval;
  478. function throttled() {
  479. if (!interval) {
  480. interval = RequestInterval(duration || 0, () => {
  481. func.apply(this, arguments);
  482. interval = null;
  483. }, null, 1);
  484. interval.start();
  485. }
  486. }
  487. return throttled;
  488. }
  489. function Options(Splide2, Components2, options) {
  490. const throttledObserve = Throttle(observe);
  491. let initialOptions;
  492. let points;
  493. let currPoint;
  494. function setup() {
  495. initialOptions = merge({}, options);
  496. const { breakpoints } = options;
  497. if (breakpoints) {
  498. const isMin = options.mediaQuery === "min";
  499. points = Object.keys(breakpoints).sort((n, m) => isMin ? +m - +n : +n - +m).map((point) => [
  500. point,
  501. matchMedia(`(${isMin ? "min" : "max"}-width:${point}px)`)
  502. ]);
  503. observe();
  504. }
  505. }
  506. function mount() {
  507. if (points) {
  508. addEventListener("resize", throttledObserve);
  509. }
  510. }
  511. function destroy(completely) {
  512. if (completely) {
  513. removeEventListener("resize", throttledObserve);
  514. }
  515. }
  516. function observe() {
  517. const item = find(points, (item2) => item2[1].matches) || [];
  518. if (item[0] !== currPoint) {
  519. onMatch(currPoint = item[0]);
  520. }
  521. }
  522. function onMatch(point) {
  523. const newOptions = options.breakpoints[point] || initialOptions;
  524. if (newOptions.destroy) {
  525. Splide2.options = initialOptions;
  526. Splide2.destroy(newOptions.destroy === "completely");
  527. } else {
  528. if (Splide2.state.is(DESTROYED)) {
  529. destroy(true);
  530. Splide2.mount();
  531. }
  532. Splide2.options = newOptions;
  533. }
  534. }
  535. return {
  536. setup,
  537. mount,
  538. destroy
  539. };
  540. }
  541. const RTL = "rtl";
  542. const TTB = "ttb";
  543. const ORIENTATION_MAP = {
  544. marginRight: ["marginBottom", "marginLeft"],
  545. autoWidth: ["autoHeight"],
  546. fixedWidth: ["fixedHeight"],
  547. paddingLeft: ["paddingTop", "paddingRight"],
  548. paddingRight: ["paddingBottom", "paddingLeft"],
  549. width: ["height"],
  550. left: ["top", "right"],
  551. right: ["bottom", "left"],
  552. x: ["y"],
  553. X: ["Y"],
  554. Y: ["X"],
  555. ArrowLeft: ["ArrowUp", "ArrowRight"],
  556. ArrowRight: ["ArrowDown", "ArrowLeft"]
  557. };
  558. function Direction(Splide2, Components2, options) {
  559. function resolve(prop, axisOnly) {
  560. const { direction } = options;
  561. const index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
  562. return ORIENTATION_MAP[prop][index] || prop;
  563. }
  564. function orient(value) {
  565. return value * (options.direction === RTL ? 1 : -1);
  566. }
  567. return {
  568. resolve,
  569. orient
  570. };
  571. }
  572. const ROLE = "role";
  573. const TAB_INDEX = "tabindex";
  574. const DISABLED = "disabled";
  575. const ARIA_PREFIX = "aria-";
  576. const ARIA_CONTROLS = `${ARIA_PREFIX}controls`;
  577. const ARIA_CURRENT = `${ARIA_PREFIX}current`;
  578. const ARIA_LABEL = `${ARIA_PREFIX}label`;
  579. const ARIA_HIDDEN = `${ARIA_PREFIX}hidden`;
  580. const ARIA_ORIENTATION = `${ARIA_PREFIX}orientation`;
  581. const ARIA_ROLEDESCRIPTION = `${ARIA_PREFIX}roledescription`;
  582. const ARIA_ATOMIC = `${ARIA_PREFIX}atomic`;
  583. const ARIA_LIVE = `${ARIA_PREFIX}live`;
  584. const ALL_ATTRIBUTES = [
  585. ROLE,
  586. TAB_INDEX,
  587. DISABLED,
  588. ARIA_CONTROLS,
  589. ARIA_CURRENT,
  590. ARIA_LABEL,
  591. ARIA_HIDDEN,
  592. ARIA_ORIENTATION,
  593. ARIA_ROLEDESCRIPTION,
  594. ARIA_ATOMIC,
  595. ARIA_LIVE
  596. ];
  597. const CLASS_ROOT = PROJECT_CODE;
  598. const CLASS_SLIDER = `${PROJECT_CODE}__slider`;
  599. const CLASS_TRACK = `${PROJECT_CODE}__track`;
  600. const CLASS_LIST = `${PROJECT_CODE}__list`;
  601. const CLASS_SLIDE = `${PROJECT_CODE}__slide`;
  602. const CLASS_CLONE = `${CLASS_SLIDE}--clone`;
  603. const CLASS_CONTAINER = `${CLASS_SLIDE}__container`;
  604. const CLASS_ARROWS = `${PROJECT_CODE}__arrows`;
  605. const CLASS_ARROW = `${PROJECT_CODE}__arrow`;
  606. const CLASS_ARROW_PREV = `${CLASS_ARROW}--prev`;
  607. const CLASS_ARROW_NEXT = `${CLASS_ARROW}--next`;
  608. const CLASS_PAGINATION = `${PROJECT_CODE}__pagination`;
  609. const CLASS_PAGINATION_PAGE = `${CLASS_PAGINATION}__page`;
  610. const CLASS_PROGRESS = `${PROJECT_CODE}__progress`;
  611. const CLASS_PROGRESS_BAR = `${CLASS_PROGRESS}__bar`;
  612. const CLASS_AUTOPLAY = `${PROJECT_CODE}__autoplay`;
  613. const CLASS_PLAY = `${PROJECT_CODE}__play`;
  614. const CLASS_PAUSE = `${PROJECT_CODE}__pause`;
  615. const CLASS_SPINNER = `${PROJECT_CODE}__spinner`;
  616. const CLASS_SR = `${PROJECT_CODE}__sr`;
  617. const CLASS_INITIALIZED = "is-initialized";
  618. const CLASS_ACTIVE = "is-active";
  619. const CLASS_PREV = "is-prev";
  620. const CLASS_NEXT = "is-next";
  621. const CLASS_VISIBLE = "is-visible";
  622. const CLASS_LOADING = "is-loading";
  623. const STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING];
  624. const CLASSES = {
  625. slide: CLASS_SLIDE,
  626. clone: CLASS_CLONE,
  627. arrows: CLASS_ARROWS,
  628. arrow: CLASS_ARROW,
  629. prev: CLASS_ARROW_PREV,
  630. next: CLASS_ARROW_NEXT,
  631. pagination: CLASS_PAGINATION,
  632. page: CLASS_PAGINATION_PAGE,
  633. spinner: CLASS_SPINNER
  634. };
  635. function Elements(Splide2, Components2, options) {
  636. const { on } = EventInterface(Splide2);
  637. const { root } = Splide2;
  638. const { i18n } = options;
  639. const elements = {};
  640. const slides = [];
  641. let classes;
  642. let slider;
  643. let track;
  644. let list;
  645. function setup() {
  646. collect();
  647. init();
  648. addClass(root, classes = getClasses());
  649. }
  650. function mount() {
  651. const priority = DEFAULT_EVENT_PRIORITY - 2;
  652. on(EVENT_REFRESH, destroy, priority);
  653. on(EVENT_REFRESH, setup, priority);
  654. on(EVENT_UPDATED, update);
  655. }
  656. function destroy() {
  657. empty(slides);
  658. removeClass(root, classes);
  659. removeAttribute([root, track, list], ALL_ATTRIBUTES.concat("style"));
  660. }
  661. function update() {
  662. removeClass(root, classes);
  663. addClass(root, classes = getClasses());
  664. }
  665. function collect() {
  666. slider = child(root, `.${CLASS_SLIDER}`);
  667. track = query(root, `.${CLASS_TRACK}`);
  668. list = child(track, `.${CLASS_LIST}`);
  669. assert(track && list, "A track/list element is missing.");
  670. push(slides, children(list, `.${CLASS_SLIDE}:not(.${CLASS_CLONE})`));
  671. const autoplay = find(`.${CLASS_AUTOPLAY}`);
  672. const arrows = find(`.${CLASS_ARROWS}`);
  673. assign(elements, {
  674. root,
  675. slider,
  676. track,
  677. list,
  678. slides,
  679. arrows,
  680. autoplay,
  681. prev: query(arrows, `.${CLASS_ARROW_PREV}`),
  682. next: query(arrows, `.${CLASS_ARROW_NEXT}`),
  683. bar: query(find(`.${CLASS_PROGRESS}`), `.${CLASS_PROGRESS_BAR}`),
  684. play: query(autoplay, `.${CLASS_PLAY}`),
  685. pause: query(autoplay, `.${CLASS_PAUSE}`)
  686. });
  687. }
  688. function init() {
  689. const id = root.id || uniqueId(PROJECT_CODE);
  690. root.id = id;
  691. track.id = track.id || `${id}-track`;
  692. list.id = list.id || `${id}-list`;
  693. setAttribute(root, ARIA_ROLEDESCRIPTION, i18n.carousel);
  694. setAttribute(root, ROLE, root.tagName !== "SECTION" && options.role || null);
  695. setAttribute(list, ROLE, "none");
  696. }
  697. function find(selector) {
  698. return child(root, selector) || child(slider, selector);
  699. }
  700. function getClasses() {
  701. return [
  702. `${CLASS_ROOT}--${options.type}`,
  703. `${CLASS_ROOT}--${options.direction}`,
  704. options.drag && `${CLASS_ROOT}--draggable`,
  705. options.isNavigation && `${CLASS_ROOT}--nav`,
  706. CLASS_ACTIVE
  707. ];
  708. }
  709. return assign(elements, {
  710. setup,
  711. mount,
  712. destroy
  713. });
  714. }
  715. const SLIDE = "slide";
  716. const LOOP = "loop";
  717. const FADE = "fade";
  718. function Slide$1(Splide2, index, slideIndex, slide) {
  719. const { on, emit, bind, destroy: destroyEvents } = EventInterface(Splide2);
  720. const { Components, root, options } = Splide2;
  721. const { isNavigation, updateOnMove, i18n } = options;
  722. const { resolve } = Components.Direction;
  723. const styles = getAttribute(slide, "style");
  724. const isClone = slideIndex > -1;
  725. const container = child(slide, `.${CLASS_CONTAINER}`);
  726. const focusableNodes = options.focusableNodes && queryAll(slide, options.focusableNodes);
  727. let destroyed;
  728. function mount() {
  729. if (!isClone) {
  730. slide.id = `${root.id}-slide${pad(index + 1)}`;
  731. setAttribute(slide, ROLE, "group");
  732. setAttribute(slide, ARIA_ROLEDESCRIPTION, i18n.slide);
  733. setAttribute(slide, ARIA_LABEL, format(i18n.slideLabel, [index + 1, Splide2.length]));
  734. }
  735. listen();
  736. }
  737. function listen() {
  738. bind(slide, "click keydown", (e) => {
  739. emit(e.type === "click" ? EVENT_CLICK : EVENT_SLIDE_KEYDOWN, self, e);
  740. });
  741. on([EVENT_REFRESH, EVENT_REPOSITIONED, EVENT_SHIFTED, EVENT_MOVED, EVENT_SCROLLED], update);
  742. on(EVENT_NAVIGATION_MOUNTED, initNavigation);
  743. if (updateOnMove) {
  744. on(EVENT_MOVE, onMove);
  745. }
  746. }
  747. function destroy() {
  748. destroyed = true;
  749. destroyEvents();
  750. removeClass(slide, STATUS_CLASSES);
  751. removeAttribute(slide, ALL_ATTRIBUTES);
  752. setAttribute(slide, "style", styles);
  753. }
  754. function initNavigation() {
  755. const idx = isClone ? slideIndex : index;
  756. const label = format(i18n.slideX, idx + 1);
  757. const controls = Splide2.splides.map((target) => target.splide.root.id).join(" ");
  758. setAttribute(slide, ARIA_LABEL, label);
  759. setAttribute(slide, ARIA_CONTROLS, controls);
  760. setAttribute(slide, ROLE, "menuitem");
  761. updateActivity(isActive());
  762. }
  763. function onMove() {
  764. if (!destroyed) {
  765. update();
  766. }
  767. }
  768. function update() {
  769. if (!destroyed) {
  770. const { index: currIndex } = Splide2;
  771. updateActivity(isActive());
  772. updateVisibility(isVisible());
  773. toggleClass(slide, CLASS_PREV, index === currIndex - 1);
  774. toggleClass(slide, CLASS_NEXT, index === currIndex + 1);
  775. }
  776. }
  777. function updateActivity(active) {
  778. if (active !== hasClass(slide, CLASS_ACTIVE)) {
  779. toggleClass(slide, CLASS_ACTIVE, active);
  780. if (isNavigation) {
  781. setAttribute(slide, ARIA_CURRENT, active || null);
  782. }
  783. emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, self);
  784. }
  785. }
  786. function updateVisibility(visible) {
  787. const hidden = !visible && (!isActive() || isClone);
  788. setAttribute(slide, ARIA_HIDDEN, hidden || null);
  789. setAttribute(slide, TAB_INDEX, !hidden && options.slideFocus ? 0 : null);
  790. setAttribute(focusableNodes || [], TAB_INDEX, hidden ? -1 : null);
  791. if (visible !== hasClass(slide, CLASS_VISIBLE)) {
  792. toggleClass(slide, CLASS_VISIBLE, visible);
  793. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
  794. }
  795. }
  796. function style$1(prop, value, useContainer) {
  797. style(useContainer && container || slide, prop, value);
  798. }
  799. function isActive() {
  800. const { index: curr } = Splide2;
  801. return curr === index || options.cloneStatus && curr === slideIndex;
  802. }
  803. function isVisible() {
  804. if (Splide2.is(FADE)) {
  805. return isActive();
  806. }
  807. const trackRect = rect(Components.Elements.track);
  808. const slideRect = rect(slide);
  809. const left = resolve("left");
  810. const right = resolve("right");
  811. return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
  812. }
  813. function isWithin(from, distance) {
  814. let diff = abs(from - index);
  815. if (!isClone && (options.rewind || Splide2.is(LOOP))) {
  816. diff = min(diff, Splide2.length - diff);
  817. }
  818. return diff <= distance;
  819. }
  820. const self = {
  821. index,
  822. slideIndex,
  823. slide,
  824. container,
  825. isClone,
  826. mount,
  827. destroy,
  828. update,
  829. style: style$1,
  830. isWithin
  831. };
  832. return self;
  833. }
  834. function Slides(Splide2, Components2, options) {
  835. const { on, emit, bind } = EventInterface(Splide2);
  836. const { slides, list } = Components2.Elements;
  837. const Slides2 = [];
  838. function mount() {
  839. init();
  840. on(EVENT_REFRESH, destroy);
  841. on(EVENT_REFRESH, init);
  842. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  843. Slides2.sort((Slide1, Slide2) => Slide1.index - Slide2.index);
  844. });
  845. }
  846. function init() {
  847. slides.forEach((slide, index) => {
  848. register(slide, index, -1);
  849. });
  850. }
  851. function destroy() {
  852. forEach$1((Slide2) => {
  853. Slide2.destroy();
  854. });
  855. empty(Slides2);
  856. }
  857. function update() {
  858. forEach$1((Slide2) => {
  859. Slide2.update();
  860. });
  861. }
  862. function register(slide, index, slideIndex) {
  863. const object = Slide$1(Splide2, index, slideIndex, slide);
  864. object.mount();
  865. Slides2.push(object);
  866. }
  867. function get(excludeClones) {
  868. return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
  869. }
  870. function getIn(page) {
  871. const { Controller } = Components2;
  872. const index = Controller.toIndex(page);
  873. const max = Controller.hasFocus() ? 1 : options.perPage;
  874. return filter((Slide2) => between(Slide2.index, index, index + max - 1));
  875. }
  876. function getAt(index) {
  877. return filter(index)[0];
  878. }
  879. function add(items, index) {
  880. forEach(items, (slide) => {
  881. if (isString(slide)) {
  882. slide = parseHtml(slide);
  883. }
  884. if (isHTMLElement(slide)) {
  885. const ref = slides[index];
  886. ref ? before(slide, ref) : append(list, slide);
  887. addClass(slide, options.classes.slide);
  888. observeImages(slide, apply(emit, EVENT_RESIZE));
  889. }
  890. });
  891. emit(EVENT_REFRESH);
  892. }
  893. function remove$1(matcher) {
  894. remove(filter(matcher).map((Slide2) => Slide2.slide));
  895. emit(EVENT_REFRESH);
  896. }
  897. function forEach$1(iteratee, excludeClones) {
  898. get(excludeClones).forEach(iteratee);
  899. }
  900. function filter(matcher) {
  901. return Slides2.filter(isFunction(matcher) ? matcher : (Slide2) => isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index));
  902. }
  903. function style(prop, value, useContainer) {
  904. forEach$1((Slide2) => {
  905. Slide2.style(prop, value, useContainer);
  906. });
  907. }
  908. function observeImages(elm, callback) {
  909. const images = queryAll(elm, "img");
  910. let { length } = images;
  911. if (length) {
  912. images.forEach((img) => {
  913. bind(img, "load error", () => {
  914. if (!--length) {
  915. callback();
  916. }
  917. });
  918. });
  919. } else {
  920. callback();
  921. }
  922. }
  923. function getLength(excludeClones) {
  924. return excludeClones ? slides.length : Slides2.length;
  925. }
  926. function isEnough() {
  927. return Slides2.length > options.perPage;
  928. }
  929. return {
  930. mount,
  931. destroy,
  932. update,
  933. register,
  934. get,
  935. getIn,
  936. getAt,
  937. add,
  938. remove: remove$1,
  939. forEach: forEach$1,
  940. filter,
  941. style,
  942. getLength,
  943. isEnough
  944. };
  945. }
  946. function Layout(Splide2, Components2, options) {
  947. const { on, bind, emit } = EventInterface(Splide2);
  948. const { Slides } = Components2;
  949. const { resolve } = Components2.Direction;
  950. const { root, track, list } = Components2.Elements;
  951. const { getAt } = Slides;
  952. let vertical;
  953. let rootRect;
  954. function mount() {
  955. init();
  956. bind(window, "resize load", Throttle(emit.bind(this, EVENT_RESIZE)));
  957. on([EVENT_UPDATED, EVENT_REFRESH], init);
  958. on(EVENT_RESIZE, resize);
  959. }
  960. function init() {
  961. rootRect = null;
  962. vertical = options.direction === TTB;
  963. style(root, "maxWidth", unit(options.width));
  964. style(track, resolve("paddingLeft"), cssPadding(false));
  965. style(track, resolve("paddingRight"), cssPadding(true));
  966. resize();
  967. }
  968. function resize() {
  969. const newRect = rect(root);
  970. if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  971. style(track, "height", cssTrackHeight());
  972. Slides.style(resolve("marginRight"), unit(options.gap));
  973. Slides.style("width", cssSlideWidth() || null);
  974. setSlidesHeight();
  975. rootRect = newRect;
  976. emit(EVENT_RESIZED);
  977. }
  978. }
  979. function setSlidesHeight() {
  980. Slides.style("height", cssSlideHeight() || null, true);
  981. }
  982. function cssPadding(right) {
  983. const { padding } = options;
  984. const prop = resolve(right ? "right" : "left");
  985. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  986. }
  987. function cssTrackHeight() {
  988. let height = "";
  989. if (vertical) {
  990. height = cssHeight();
  991. assert(height, "height or heightRatio is missing.");
  992. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  993. }
  994. return height;
  995. }
  996. function cssHeight() {
  997. return unit(options.height || rect(list).width * options.heightRatio);
  998. }
  999. function cssSlideWidth() {
  1000. return options.autoWidth ? "" : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  1001. }
  1002. function cssSlideHeight() {
  1003. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? "" : cssSlideSize() : cssHeight());
  1004. }
  1005. function cssSlideSize() {
  1006. const gap = unit(options.gap);
  1007. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  1008. }
  1009. function listSize() {
  1010. return rect(list)[resolve("width")];
  1011. }
  1012. function slideSize(index, withoutGap) {
  1013. const Slide = getAt(index || 0);
  1014. return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
  1015. }
  1016. function totalSize(index, withoutGap) {
  1017. const Slide = getAt(index);
  1018. if (Slide) {
  1019. const right = rect(Slide.slide)[resolve("right")];
  1020. const left = rect(list)[resolve("left")];
  1021. return abs(right - left) + (withoutGap ? 0 : getGap());
  1022. }
  1023. return 0;
  1024. }
  1025. function sliderSize() {
  1026. return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
  1027. }
  1028. function getGap() {
  1029. const Slide = getAt(0);
  1030. return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
  1031. }
  1032. function getPadding(right) {
  1033. return parseFloat(style(track, resolve(`padding${right ? "Right" : "Left"}`))) || 0;
  1034. }
  1035. return {
  1036. mount,
  1037. listSize,
  1038. slideSize,
  1039. sliderSize,
  1040. totalSize,
  1041. getPadding
  1042. };
  1043. }
  1044. function Clones(Splide2, Components2, options) {
  1045. const { on, emit } = EventInterface(Splide2);
  1046. const { Elements, Slides } = Components2;
  1047. const { resolve } = Components2.Direction;
  1048. const clones = [];
  1049. let cloneCount;
  1050. function mount() {
  1051. init();
  1052. on(EVENT_REFRESH, destroy);
  1053. on(EVENT_REFRESH, init);
  1054. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1055. }
  1056. function init() {
  1057. if (cloneCount = computeCloneCount()) {
  1058. generate(cloneCount);
  1059. emit(EVENT_RESIZE);
  1060. }
  1061. }
  1062. function destroy() {
  1063. remove(clones);
  1064. empty(clones);
  1065. }
  1066. function observe() {
  1067. if (cloneCount < computeCloneCount()) {
  1068. emit(EVENT_REFRESH);
  1069. }
  1070. }
  1071. function generate(count) {
  1072. const slides = Slides.get().slice();
  1073. const { length } = slides;
  1074. if (length) {
  1075. while (slides.length < count) {
  1076. push(slides, slides);
  1077. }
  1078. push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  1079. const isHead = index < count;
  1080. const clone = cloneDeep(Slide.slide, index);
  1081. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1082. push(clones, clone);
  1083. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1084. });
  1085. }
  1086. }
  1087. function cloneDeep(elm, index) {
  1088. const clone = elm.cloneNode(true);
  1089. addClass(clone, options.classes.clone);
  1090. clone.id = `${Splide2.root.id}-clone${pad(index + 1)}`;
  1091. return clone;
  1092. }
  1093. function computeCloneCount() {
  1094. let { clones: clones2 } = options;
  1095. if (!Splide2.is(LOOP)) {
  1096. clones2 = 0;
  1097. } else if (!clones2) {
  1098. const fixedSize = measure(Elements.list, options[resolve("fixedWidth")]);
  1099. const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1100. const baseCount = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage;
  1101. clones2 = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  1102. }
  1103. return clones2;
  1104. }
  1105. return {
  1106. mount,
  1107. destroy
  1108. };
  1109. }
  1110. function Move(Splide2, Components2, options) {
  1111. const { on, emit } = EventInterface(Splide2);
  1112. const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
  1113. const { resolve, orient } = Components2.Direction;
  1114. const { list, track } = Components2.Elements;
  1115. let Transition;
  1116. function mount() {
  1117. Transition = Components2.Transition;
  1118. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1119. }
  1120. function destroy() {
  1121. removeAttribute(list, "style");
  1122. }
  1123. function reposition() {
  1124. if (!isBusy()) {
  1125. Components2.Scroll.cancel();
  1126. jump(Splide2.index);
  1127. emit(EVENT_REPOSITIONED);
  1128. }
  1129. }
  1130. function move(dest, index, prev, callback) {
  1131. if (!isBusy()) {
  1132. const { set } = Splide2.state;
  1133. const position = getPosition();
  1134. if (dest !== index) {
  1135. Transition.cancel();
  1136. translate(shift(position, dest > index), true);
  1137. }
  1138. set(MOVING);
  1139. emit(EVENT_MOVE, index, prev, dest);
  1140. Transition.start(index, () => {
  1141. set(IDLE);
  1142. emit(EVENT_MOVED, index, prev, dest);
  1143. if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
  1144. Components2.Controller.go(dest > prev ? ">" : "<", false, callback);
  1145. } else {
  1146. callback && callback();
  1147. }
  1148. });
  1149. }
  1150. }
  1151. function jump(index) {
  1152. translate(toPosition(index, true));
  1153. }
  1154. function translate(position, preventLoop) {
  1155. if (!Splide2.is(FADE)) {
  1156. const destination = preventLoop ? position : loop(position);
  1157. list.style.transform = `translate${resolve("X")}(${destination}px)`;
  1158. position !== destination && emit(EVENT_SHIFTED);
  1159. }
  1160. }
  1161. function loop(position) {
  1162. if (Splide2.is(LOOP)) {
  1163. const diff = orient(position - getPosition());
  1164. const exceededMin = exceededLimit(false, position) && diff < 0;
  1165. const exceededMax = exceededLimit(true, position) && diff > 0;
  1166. if (exceededMin || exceededMax) {
  1167. position = shift(position, exceededMax);
  1168. }
  1169. }
  1170. return position;
  1171. }
  1172. function shift(position, backwards) {
  1173. const excess = position - getLimit(backwards);
  1174. const size = sliderSize();
  1175. position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
  1176. return position;
  1177. }
  1178. function cancel() {
  1179. translate(getPosition());
  1180. Transition.cancel();
  1181. }
  1182. function toIndex(position) {
  1183. const Slides = Components2.Slides.get();
  1184. let index = 0;
  1185. let minDistance = Infinity;
  1186. for (let i = 0; i < Slides.length; i++) {
  1187. const slideIndex = Slides[i].index;
  1188. const distance = abs(toPosition(slideIndex, true) - position);
  1189. if (distance <= minDistance) {
  1190. minDistance = distance;
  1191. index = slideIndex;
  1192. } else {
  1193. break;
  1194. }
  1195. }
  1196. return index;
  1197. }
  1198. function toPosition(index, trimming) {
  1199. const position = orient(totalSize(index - 1) - offset(index));
  1200. return trimming ? trim(position) : position;
  1201. }
  1202. function getPosition() {
  1203. const left = resolve("left");
  1204. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1205. }
  1206. function trim(position) {
  1207. if (options.trimSpace && Splide2.is(SLIDE)) {
  1208. position = clamp(position, 0, orient(sliderSize() - listSize()));
  1209. }
  1210. return position;
  1211. }
  1212. function offset(index) {
  1213. const { focus } = options;
  1214. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1215. }
  1216. function getLimit(max) {
  1217. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1218. }
  1219. function isBusy() {
  1220. return Splide2.state.is(MOVING) && options.waitForTransition;
  1221. }
  1222. function exceededLimit(max, position) {
  1223. position = isUndefined(position) ? getPosition() : position;
  1224. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1225. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1226. return exceededMin || exceededMax;
  1227. }
  1228. return {
  1229. mount,
  1230. destroy,
  1231. move,
  1232. jump,
  1233. translate,
  1234. shift,
  1235. cancel,
  1236. toIndex,
  1237. toPosition,
  1238. getPosition,
  1239. getLimit,
  1240. isBusy,
  1241. exceededLimit
  1242. };
  1243. }
  1244. function Controller(Splide2, Components2, options) {
  1245. const { on } = EventInterface(Splide2);
  1246. const { Move } = Components2;
  1247. const { getPosition, getLimit } = Move;
  1248. const { isEnough, getLength } = Components2.Slides;
  1249. const isLoop = Splide2.is(LOOP);
  1250. const isSlide = Splide2.is(SLIDE);
  1251. let currIndex = options.start || 0;
  1252. let prevIndex = currIndex;
  1253. let slideCount;
  1254. let perMove;
  1255. let perPage;
  1256. function mount() {
  1257. init();
  1258. on([EVENT_UPDATED, EVENT_REFRESH], init, DEFAULT_EVENT_PRIORITY - 1);
  1259. }
  1260. function init() {
  1261. slideCount = getLength(true);
  1262. perMove = options.perMove;
  1263. perPage = options.perPage;
  1264. currIndex = clamp(currIndex, 0, slideCount - 1);
  1265. }
  1266. function go(control, allowSameIndex, callback) {
  1267. const dest = parse(control);
  1268. if (options.useScroll) {
  1269. scroll(dest, true, true, options.speed, callback);
  1270. } else {
  1271. const index = loop(dest);
  1272. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  1273. setIndex(index);
  1274. Move.move(dest, index, prevIndex, callback);
  1275. }
  1276. }
  1277. }
  1278. function scroll(destination, useIndex, snap, duration, callback) {
  1279. const dest = useIndex ? destination : toDest(destination);
  1280. Components2.Scroll.scroll(useIndex || snap ? Move.toPosition(dest, true) : destination, duration, () => {
  1281. setIndex(Move.toIndex(Move.getPosition()));
  1282. callback && callback();
  1283. });
  1284. }
  1285. function parse(control) {
  1286. let index = currIndex;
  1287. if (isString(control)) {
  1288. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1289. if (indicator === "+" || indicator === "-") {
  1290. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex, true);
  1291. } else if (indicator === ">") {
  1292. index = number ? toIndex(+number) : getNext(true);
  1293. } else if (indicator === "<") {
  1294. index = getPrev(true);
  1295. }
  1296. } else {
  1297. index = isLoop ? control : clamp(control, 0, getEnd());
  1298. }
  1299. return index;
  1300. }
  1301. function getNext(destination) {
  1302. return getAdjacent(false, destination);
  1303. }
  1304. function getPrev(destination) {
  1305. return getAdjacent(true, destination);
  1306. }
  1307. function getAdjacent(prev, destination) {
  1308. const number = perMove || (hasFocus() ? 1 : perPage);
  1309. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
  1310. if (dest === -1 && isSlide) {
  1311. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1312. return prev ? 0 : getEnd();
  1313. }
  1314. }
  1315. return destination ? dest : loop(dest);
  1316. }
  1317. function computeDestIndex(dest, from, incremental) {
  1318. if (isEnough()) {
  1319. const end = getEnd();
  1320. if (dest < 0 || dest > end) {
  1321. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  1322. dest = toIndex(toPage(dest));
  1323. } else {
  1324. if (isLoop) {
  1325. dest = perMove || hasFocus() ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  1326. } else if (options.rewind) {
  1327. dest = dest < 0 ? end : 0;
  1328. } else {
  1329. dest = -1;
  1330. }
  1331. }
  1332. } else {
  1333. if (!incremental && dest !== from) {
  1334. dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
  1335. }
  1336. }
  1337. } else {
  1338. dest = -1;
  1339. }
  1340. return dest;
  1341. }
  1342. function getEnd() {
  1343. let end = slideCount - perPage;
  1344. if (hasFocus() || isLoop && perMove) {
  1345. end = slideCount - 1;
  1346. }
  1347. return max(end, 0);
  1348. }
  1349. function loop(index) {
  1350. if (isLoop) {
  1351. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  1352. }
  1353. return index;
  1354. }
  1355. function toIndex(page) {
  1356. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  1357. }
  1358. function toPage(index) {
  1359. if (!hasFocus()) {
  1360. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  1361. index = floor(index / perPage);
  1362. }
  1363. return index;
  1364. }
  1365. function toDest(destination) {
  1366. const closest = Move.toIndex(destination);
  1367. return isSlide ? clamp(closest, 0, getEnd()) : closest;
  1368. }
  1369. function setIndex(index) {
  1370. if (index !== currIndex) {
  1371. prevIndex = currIndex;
  1372. currIndex = index;
  1373. }
  1374. }
  1375. function getIndex(prev) {
  1376. return prev ? prevIndex : currIndex;
  1377. }
  1378. function hasFocus() {
  1379. return !isUndefined(options.focus) || options.isNavigation;
  1380. }
  1381. return {
  1382. mount,
  1383. go,
  1384. scroll,
  1385. getNext,
  1386. getPrev,
  1387. getAdjacent,
  1388. getEnd,
  1389. setIndex,
  1390. getIndex,
  1391. toIndex,
  1392. toPage,
  1393. toDest,
  1394. hasFocus
  1395. };
  1396. }
  1397. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1398. const PATH = "m15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z";
  1399. const SIZE = 40;
  1400. function Arrows(Splide2, Components2, options) {
  1401. const { on, bind, emit } = EventInterface(Splide2);
  1402. const { classes, i18n } = options;
  1403. const { Elements, Controller } = Components2;
  1404. let wrapper = Elements.arrows;
  1405. let prev = Elements.prev;
  1406. let next = Elements.next;
  1407. let created;
  1408. const arrows = {};
  1409. function mount() {
  1410. init();
  1411. on(EVENT_UPDATED, init);
  1412. }
  1413. function init() {
  1414. if (options.arrows) {
  1415. if (!prev || !next) {
  1416. createArrows();
  1417. }
  1418. }
  1419. if (prev && next) {
  1420. if (!arrows.prev) {
  1421. setAttribute([prev, next], ARIA_CONTROLS, Elements.list.id);
  1422. arrows.prev = prev;
  1423. arrows.next = next;
  1424. listen();
  1425. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1426. }
  1427. display(wrapper, options.arrows === false ? "none" : "");
  1428. }
  1429. }
  1430. function destroy() {
  1431. if (created) {
  1432. remove(wrapper);
  1433. } else {
  1434. removeAttribute([prev, next], ALL_ATTRIBUTES);
  1435. }
  1436. }
  1437. function listen() {
  1438. const { go } = Controller;
  1439. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  1440. bind(next, "click", apply(go, ">", true, void 0));
  1441. bind(prev, "click", apply(go, "<", true, void 0));
  1442. }
  1443. function createArrows() {
  1444. wrapper = create("div", classes.arrows);
  1445. prev = createArrow(true);
  1446. next = createArrow(false);
  1447. created = true;
  1448. append(wrapper, [prev, next]);
  1449. before(wrapper, child(options.arrows === "slider" && Elements.slider || Splide2.root));
  1450. }
  1451. function createArrow(prev2) {
  1452. const arrow = `<button class="${classes.arrow} ${prev2 ? classes.prev : classes.next}" type="button"><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${options.arrowPath || PATH}" />`;
  1453. return parseHtml(arrow);
  1454. }
  1455. function update() {
  1456. const index = Splide2.index;
  1457. const prevIndex = Controller.getPrev();
  1458. const nextIndex = Controller.getNext();
  1459. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1460. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1461. prev.disabled = prevIndex < 0;
  1462. next.disabled = nextIndex < 0;
  1463. setAttribute(prev, ARIA_LABEL, prevLabel);
  1464. setAttribute(next, ARIA_LABEL, nextLabel);
  1465. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1466. }
  1467. return {
  1468. arrows,
  1469. mount,
  1470. destroy
  1471. };
  1472. }
  1473. const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
  1474. function Autoplay(Splide2, Components2, options) {
  1475. const { on, bind, emit } = EventInterface(Splide2);
  1476. const interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), update);
  1477. const { isPaused } = interval;
  1478. const { Elements } = Components2;
  1479. let hovered;
  1480. let focused;
  1481. let paused;
  1482. function mount() {
  1483. const { autoplay } = options;
  1484. if (autoplay) {
  1485. initButton(true);
  1486. initButton(false);
  1487. listen();
  1488. if (autoplay !== "pause") {
  1489. play();
  1490. }
  1491. }
  1492. }
  1493. function initButton(forPause) {
  1494. const prop = forPause ? "pause" : "play";
  1495. const button = Elements[prop];
  1496. if (button) {
  1497. setAttribute(button, ARIA_CONTROLS, Elements.track.id);
  1498. setAttribute(button, ARIA_LABEL, options.i18n[prop]);
  1499. bind(button, "click", forPause ? pause : play);
  1500. }
  1501. }
  1502. function listen() {
  1503. const { root } = Elements;
  1504. if (options.pauseOnHover) {
  1505. bind(root, "mouseenter mouseleave", (e) => {
  1506. hovered = e.type === "mouseenter";
  1507. autoToggle();
  1508. });
  1509. }
  1510. if (options.pauseOnFocus) {
  1511. bind(root, "focusin focusout", (e) => {
  1512. focused = e.type === "focusin";
  1513. autoToggle();
  1514. });
  1515. }
  1516. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1517. on(EVENT_MOVE, updateInterval);
  1518. }
  1519. function play() {
  1520. if (isPaused() && Components2.Slides.isEnough()) {
  1521. interval.start(!options.resetProgress);
  1522. focused = hovered = paused = false;
  1523. emit(EVENT_AUTOPLAY_PLAY);
  1524. }
  1525. }
  1526. function pause(manual = true) {
  1527. if (!isPaused()) {
  1528. interval.pause();
  1529. emit(EVENT_AUTOPLAY_PAUSE);
  1530. }
  1531. paused = manual;
  1532. }
  1533. function autoToggle() {
  1534. if (!paused) {
  1535. if (!hovered && !focused) {
  1536. play();
  1537. } else {
  1538. pause(false);
  1539. }
  1540. }
  1541. }
  1542. function update(rate) {
  1543. const { bar } = Elements;
  1544. bar && style(bar, "width", `${rate * 100}%`);
  1545. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1546. }
  1547. function updateInterval() {
  1548. const Slide = Components2.Slides.getAt(Splide2.index);
  1549. interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1550. }
  1551. return {
  1552. mount,
  1553. destroy: interval.cancel,
  1554. play,
  1555. pause,
  1556. isPaused
  1557. };
  1558. }
  1559. function Cover(Splide2, Components2, options) {
  1560. const { on } = EventInterface(Splide2);
  1561. function mount() {
  1562. if (options.cover) {
  1563. on(EVENT_LAZYLOAD_LOADED, apply(toggle, true));
  1564. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply(cover, true));
  1565. }
  1566. }
  1567. function cover(cover2) {
  1568. Components2.Slides.forEach((Slide) => {
  1569. const img = child(Slide.container || Slide.slide, "img");
  1570. if (img && img.src) {
  1571. toggle(cover2, img, Slide);
  1572. }
  1573. });
  1574. }
  1575. function toggle(cover2, img, Slide) {
  1576. Slide.style("background", cover2 ? `center/cover no-repeat url("${img.src}")` : "", true);
  1577. display(img, cover2 ? "none" : "");
  1578. }
  1579. return {
  1580. mount,
  1581. destroy: apply(cover, false)
  1582. };
  1583. }
  1584. const BOUNCE_DIFF_THRESHOLD = 10;
  1585. const BOUNCE_DURATION = 600;
  1586. const FRICTION_FACTOR = 0.6;
  1587. const BASE_VELOCITY = 1.5;
  1588. const MIN_DURATION = 800;
  1589. function Scroll(Splide2, Components2, options) {
  1590. const { on, emit } = EventInterface(Splide2);
  1591. const { Move } = Components2;
  1592. const { getPosition, getLimit, exceededLimit } = Move;
  1593. let interval;
  1594. let scrollCallback;
  1595. function mount() {
  1596. on(EVENT_MOVE, clear);
  1597. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1598. }
  1599. function scroll(destination, duration, callback, suppressConstraint) {
  1600. const start = getPosition();
  1601. let friction = 1;
  1602. duration = duration || computeDuration(abs(destination - start));
  1603. scrollCallback = callback;
  1604. clear();
  1605. interval = RequestInterval(duration, onScrolled, (rate) => {
  1606. const position = getPosition();
  1607. const target = start + (destination - start) * easing(rate);
  1608. const diff = (target - getPosition()) * friction;
  1609. Move.translate(position + diff);
  1610. if (Splide2.is(SLIDE) && !suppressConstraint && exceededLimit()) {
  1611. friction *= FRICTION_FACTOR;
  1612. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1613. bounce(exceededLimit(false));
  1614. }
  1615. }
  1616. }, 1);
  1617. emit(EVENT_SCROLL);
  1618. interval.start();
  1619. }
  1620. function bounce(backwards) {
  1621. scroll(getLimit(!backwards), BOUNCE_DURATION, null, true);
  1622. }
  1623. function onScrolled() {
  1624. const position = getPosition();
  1625. const index = Move.toIndex(position);
  1626. if (!between(index, 0, Splide2.length - 1)) {
  1627. Move.translate(Move.shift(position, index > 0), true);
  1628. }
  1629. scrollCallback && scrollCallback();
  1630. emit(EVENT_SCROLLED);
  1631. }
  1632. function computeDuration(distance) {
  1633. return max(distance / BASE_VELOCITY, MIN_DURATION);
  1634. }
  1635. function clear() {
  1636. if (interval) {
  1637. interval.cancel();
  1638. }
  1639. }
  1640. function cancel() {
  1641. if (interval && !interval.isPaused()) {
  1642. clear();
  1643. onScrolled();
  1644. }
  1645. }
  1646. function easing(t) {
  1647. const { easingFunc } = options;
  1648. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1649. }
  1650. return {
  1651. mount,
  1652. destroy: clear,
  1653. scroll,
  1654. cancel
  1655. };
  1656. }
  1657. const SCROLL_LISTENER_OPTIONS = { passive: false, capture: true };
  1658. const FRICTION = 5;
  1659. const LOG_INTERVAL = 200;
  1660. const POINTER_DOWN_EVENTS = "touchstart mousedown";
  1661. const POINTER_MOVE_EVENTS = "touchmove mousemove";
  1662. const POINTER_UP_EVENTS = "touchend touchcancel mouseup";
  1663. function Drag(Splide2, Components2, options) {
  1664. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1665. const { state } = Splide2;
  1666. const { Move, Scroll, Controller } = Components2;
  1667. const { track } = Components2.Elements;
  1668. const { resolve, orient } = Components2.Direction;
  1669. const { getPosition, exceededLimit } = Move;
  1670. let basePosition;
  1671. let baseEvent;
  1672. let prevBaseEvent;
  1673. let isFree;
  1674. let dragging;
  1675. let exceeded = false;
  1676. let clickPrevented;
  1677. let disabled;
  1678. let target;
  1679. function mount() {
  1680. bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1681. bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1682. bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
  1683. bind(track, "click", onClick, { capture: true });
  1684. bind(track, "dragstart", prevent);
  1685. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1686. }
  1687. function init() {
  1688. const { drag } = options;
  1689. disable(!drag);
  1690. isFree = drag === "free";
  1691. }
  1692. function onPointerDown(e) {
  1693. clickPrevented = false;
  1694. if (!disabled) {
  1695. const { noDrag } = options;
  1696. const isTouch = isTouchEvent(e);
  1697. const isDraggable = !noDrag || !matches(e.target, noDrag);
  1698. if (isDraggable && (isTouch || !e.button)) {
  1699. if (!Move.isBusy()) {
  1700. target = isTouch ? track : window;
  1701. dragging = state.is(MOVING);
  1702. prevBaseEvent = null;
  1703. bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
  1704. bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
  1705. Move.cancel();
  1706. Scroll.cancel();
  1707. save(e);
  1708. } else {
  1709. prevent(e, true);
  1710. }
  1711. }
  1712. }
  1713. }
  1714. function onPointerMove(e) {
  1715. if (!state.is(DRAGGING)) {
  1716. state.set(DRAGGING);
  1717. emit(EVENT_DRAG);
  1718. }
  1719. if (e.cancelable) {
  1720. if (dragging) {
  1721. Move.translate(basePosition + constrain(diffCoord(e)));
  1722. const expired = diffTime(e) > LOG_INTERVAL;
  1723. const hasExceeded = exceeded !== (exceeded = exceededLimit());
  1724. if (expired || hasExceeded) {
  1725. save(e);
  1726. }
  1727. clickPrevented = true;
  1728. emit(EVENT_DRAGGING);
  1729. prevent(e);
  1730. } else if (isSliderDirection(e)) {
  1731. dragging = shouldStart(e);
  1732. prevent(e);
  1733. }
  1734. }
  1735. }
  1736. function onPointerUp(e) {
  1737. if (state.is(DRAGGING)) {
  1738. state.set(IDLE);
  1739. emit(EVENT_DRAGGED);
  1740. }
  1741. if (dragging) {
  1742. move(e);
  1743. prevent(e);
  1744. }
  1745. unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1746. unbind(target, POINTER_UP_EVENTS, onPointerUp);
  1747. dragging = false;
  1748. }
  1749. function onClick(e) {
  1750. if (!disabled && clickPrevented) {
  1751. prevent(e, true);
  1752. }
  1753. }
  1754. function save(e) {
  1755. prevBaseEvent = baseEvent;
  1756. baseEvent = e;
  1757. basePosition = getPosition();
  1758. }
  1759. function move(e) {
  1760. const velocity = computeVelocity(e);
  1761. const destination = computeDestination(velocity);
  1762. const rewind = options.rewind && options.rewindByDrag;
  1763. if (isFree) {
  1764. Controller.scroll(destination);
  1765. } else if (Splide2.is(FADE)) {
  1766. Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
  1767. } else if (Splide2.is(SLIDE) && exceeded && rewind) {
  1768. Controller.go(exceededLimit(true) ? ">" : "<");
  1769. } else {
  1770. Controller.go(Controller.toDest(destination), true);
  1771. }
  1772. }
  1773. function shouldStart(e) {
  1774. const { dragMinThreshold: thresholds } = options;
  1775. const isObj = isObject(thresholds);
  1776. const mouse = isObj && thresholds.mouse || 0;
  1777. const touch = (isObj ? thresholds.touch : +thresholds) || 10;
  1778. return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
  1779. }
  1780. function isSliderDirection(e) {
  1781. return abs(diffCoord(e)) > abs(diffCoord(e, true));
  1782. }
  1783. function computeVelocity(e) {
  1784. if (Splide2.is(LOOP) || !exceeded) {
  1785. const time = diffTime(e);
  1786. if (time && time < LOG_INTERVAL) {
  1787. return diffCoord(e) / time;
  1788. }
  1789. }
  1790. return 0;
  1791. }
  1792. function computeDestination(velocity) {
  1793. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1794. }
  1795. function diffCoord(e, orthogonal) {
  1796. return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
  1797. }
  1798. function diffTime(e) {
  1799. return e.timeStamp - getBaseEvent(e).timeStamp;
  1800. }
  1801. function getBaseEvent(e) {
  1802. return baseEvent === e && prevBaseEvent || baseEvent;
  1803. }
  1804. function coordOf(e, orthogonal) {
  1805. return (isTouchEvent(e) ? e.changedTouches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
  1806. }
  1807. function constrain(diff) {
  1808. return diff / (exceeded && Splide2.is(SLIDE) ? FRICTION : 1);
  1809. }
  1810. function isTouchEvent(e) {
  1811. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1812. }
  1813. function isDragging() {
  1814. return dragging;
  1815. }
  1816. function disable(value) {
  1817. disabled = value;
  1818. }
  1819. return {
  1820. mount,
  1821. disable,
  1822. isDragging
  1823. };
  1824. }
  1825. const IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1826. const KEYBOARD_EVENT = "keydown";
  1827. function Keyboard(Splide2, Components2, options) {
  1828. const { on, bind, unbind } = EventInterface(Splide2);
  1829. const { root } = Splide2;
  1830. const { resolve } = Components2.Direction;
  1831. let target;
  1832. let disabled;
  1833. function mount() {
  1834. init();
  1835. on(EVENT_UPDATED, onUpdated);
  1836. on(EVENT_MOVE, onMove);
  1837. }
  1838. function init() {
  1839. const { keyboard } = options;
  1840. if (keyboard) {
  1841. if (keyboard === "focused") {
  1842. target = root;
  1843. setAttribute(root, TAB_INDEX, 0);
  1844. } else {
  1845. target = window;
  1846. }
  1847. bind(target, KEYBOARD_EVENT, onKeydown);
  1848. }
  1849. }
  1850. function destroy() {
  1851. unbind(target, KEYBOARD_EVENT);
  1852. }
  1853. function disable(value) {
  1854. disabled = value;
  1855. }
  1856. function onMove() {
  1857. const _disabled = disabled;
  1858. disabled = true;
  1859. nextTick(() => {
  1860. disabled = _disabled;
  1861. });
  1862. }
  1863. function onUpdated() {
  1864. destroy();
  1865. init();
  1866. }
  1867. function onKeydown(e) {
  1868. if (!disabled) {
  1869. const { key } = e;
  1870. const normalizedKey = includes(IE_ARROW_KEYS, key) ? `Arrow${key}` : key;
  1871. if (normalizedKey === resolve("ArrowLeft")) {
  1872. Splide2.go("<");
  1873. } else if (normalizedKey === resolve("ArrowRight")) {
  1874. Splide2.go(">");
  1875. }
  1876. }
  1877. }
  1878. return {
  1879. mount,
  1880. destroy,
  1881. disable
  1882. };
  1883. }
  1884. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1885. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1886. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1887. function LazyLoad(Splide2, Components2, options) {
  1888. const { on, off, bind, emit } = EventInterface(Splide2);
  1889. const isSequential = options.lazyLoad === "sequential";
  1890. let images = [];
  1891. let index = 0;
  1892. function mount() {
  1893. if (options.lazyLoad) {
  1894. init();
  1895. on(EVENT_REFRESH, destroy);
  1896. on(EVENT_REFRESH, init);
  1897. if (!isSequential) {
  1898. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED, EVENT_SCROLLED], observe);
  1899. }
  1900. }
  1901. }
  1902. function init() {
  1903. Components2.Slides.forEach((_Slide) => {
  1904. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach((_img) => {
  1905. const src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  1906. const srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  1907. if (src !== _img.src || srcset !== _img.srcset) {
  1908. const className = options.classes.spinner;
  1909. const parent = _img.parentElement;
  1910. const _spinner = child(parent, `.${className}`) || create("span", className, parent);
  1911. setAttribute(_spinner, ROLE, "presentation");
  1912. images.push({ _img, _Slide, src, srcset, _spinner });
  1913. !_img.src && display(_img, "none");
  1914. }
  1915. });
  1916. });
  1917. if (isSequential) {
  1918. loadNext();
  1919. }
  1920. }
  1921. function destroy() {
  1922. index = 0;
  1923. images = [];
  1924. }
  1925. function observe() {
  1926. images = images.filter((data) => {
  1927. const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  1928. if (data._Slide.isWithin(Splide2.index, distance)) {
  1929. return load(data);
  1930. }
  1931. return true;
  1932. });
  1933. if (!images.length) {
  1934. off(EVENT_MOVED);
  1935. }
  1936. }
  1937. function load(data) {
  1938. const { _img } = data;
  1939. addClass(data._Slide.slide, CLASS_LOADING);
  1940. bind(_img, "load error", (e) => {
  1941. onLoad(data, e.type === "error");
  1942. });
  1943. ["srcset", "src"].forEach((name) => {
  1944. if (data[name]) {
  1945. setAttribute(_img, name, data[name]);
  1946. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  1947. }
  1948. });
  1949. }
  1950. function onLoad(data, error) {
  1951. const { _Slide } = data;
  1952. removeClass(_Slide.slide, CLASS_LOADING);
  1953. if (!error) {
  1954. remove(data._spinner);
  1955. display(data._img, "");
  1956. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  1957. emit(EVENT_RESIZE);
  1958. }
  1959. if (isSequential) {
  1960. loadNext();
  1961. }
  1962. }
  1963. function loadNext() {
  1964. if (index < images.length) {
  1965. load(images[index++]);
  1966. }
  1967. }
  1968. return {
  1969. mount,
  1970. destroy
  1971. };
  1972. }
  1973. function Pagination(Splide2, Components2, options) {
  1974. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1975. const { Slides, Elements, Controller } = Components2;
  1976. const { hasFocus, getIndex } = Controller;
  1977. const items = [];
  1978. let list;
  1979. function mount() {
  1980. init();
  1981. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1982. on([EVENT_MOVE, EVENT_SCROLLED], update);
  1983. }
  1984. function init() {
  1985. destroy();
  1986. if (options.pagination && Slides.isEnough()) {
  1987. createPagination();
  1988. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
  1989. update();
  1990. }
  1991. }
  1992. function destroy() {
  1993. if (list) {
  1994. remove(list);
  1995. items.forEach((item) => {
  1996. unbind(item.button, "click");
  1997. });
  1998. empty(items);
  1999. list = null;
  2000. }
  2001. }
  2002. function createPagination() {
  2003. const { length } = Splide2;
  2004. const { classes, i18n, perPage } = options;
  2005. const parent = options.pagination === "slider" && Elements.slider || Elements.root;
  2006. const max = hasFocus() ? length : ceil(length / perPage);
  2007. list = create("ul", classes.pagination, parent);
  2008. for (let i = 0; i < max; i++) {
  2009. const li = create("li", null, list);
  2010. const button = create("button", { class: classes.page, type: "button" }, li);
  2011. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  2012. bind(button, "click", apply(onClick, i));
  2013. setAttribute(button, ARIA_CONTROLS, Components2.Elements.list.id);
  2014. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  2015. items.push({ li, button, page: i });
  2016. }
  2017. }
  2018. function onClick(page) {
  2019. Controller.go(`>${page}`, true, () => {
  2020. const Slide = Slides.getAt(Controller.toIndex(page));
  2021. Slide && focus(Slide.slide);
  2022. });
  2023. }
  2024. function getAt(index) {
  2025. return items[Controller.toPage(index)];
  2026. }
  2027. function update() {
  2028. const prev = getAt(getIndex(true));
  2029. const curr = getAt(getIndex());
  2030. if (prev) {
  2031. removeClass(prev.button, CLASS_ACTIVE);
  2032. removeAttribute(prev.button, ARIA_CURRENT);
  2033. }
  2034. if (curr) {
  2035. addClass(curr.button, CLASS_ACTIVE);
  2036. setAttribute(curr.button, ARIA_CURRENT, true);
  2037. }
  2038. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  2039. }
  2040. return {
  2041. items,
  2042. mount,
  2043. destroy,
  2044. getAt,
  2045. update
  2046. };
  2047. }
  2048. const TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2049. function Sync(Splide2, Components2, options) {
  2050. const { list } = Components2.Elements;
  2051. const events = [];
  2052. function mount() {
  2053. Splide2.splides.forEach((target) => {
  2054. !target.isParent && sync(target.splide);
  2055. });
  2056. if (options.isNavigation) {
  2057. navigate();
  2058. }
  2059. }
  2060. function destroy() {
  2061. removeAttribute(list, ALL_ATTRIBUTES);
  2062. events.forEach((event) => {
  2063. event.destroy();
  2064. });
  2065. empty(events);
  2066. }
  2067. function remount() {
  2068. destroy();
  2069. mount();
  2070. }
  2071. function sync(splide) {
  2072. [Splide2, splide].forEach((instance) => {
  2073. const event = EventInterface(instance);
  2074. const target = instance === Splide2 ? splide : Splide2;
  2075. event.on(EVENT_MOVE, (index, prev, dest) => {
  2076. target.go(target.is(LOOP) ? dest : index);
  2077. });
  2078. events.push(event);
  2079. });
  2080. }
  2081. function navigate() {
  2082. const event = EventInterface(Splide2);
  2083. const { on } = event;
  2084. on(EVENT_CLICK, onClick);
  2085. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2086. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2087. setAttribute(list, ROLE, "menu");
  2088. events.push(event);
  2089. event.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2090. }
  2091. function update() {
  2092. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2093. }
  2094. function onClick(Slide) {
  2095. Splide2.go(Slide.index);
  2096. }
  2097. function onKeydown(Slide, e) {
  2098. if (includes(TRIGGER_KEYS, e.key)) {
  2099. onClick(Slide);
  2100. prevent(e);
  2101. }
  2102. }
  2103. return {
  2104. mount,
  2105. destroy,
  2106. remount
  2107. };
  2108. }
  2109. function Live(Splide2, Components2, options) {
  2110. const { on } = EventInterface(Splide2);
  2111. const { list } = Components2.Elements;
  2112. const { live } = options;
  2113. function mount() {
  2114. if (live) {
  2115. setAttribute(list, ARIA_ATOMIC, false);
  2116. disable(!Components2.Autoplay.isPaused());
  2117. on(EVENT_AUTOPLAY_PLAY, apply(disable, true));
  2118. on(EVENT_AUTOPLAY_PAUSE, apply(disable, false));
  2119. }
  2120. }
  2121. function disable(disabled) {
  2122. if (live) {
  2123. setAttribute(list, ARIA_LIVE, disabled ? "off" : "polite");
  2124. }
  2125. }
  2126. return {
  2127. mount,
  2128. disable
  2129. };
  2130. }
  2131. function Wheel(Splide2, Components2, options) {
  2132. const { bind } = EventInterface(Splide2);
  2133. function mount() {
  2134. if (options.wheel) {
  2135. bind(Components2.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
  2136. }
  2137. }
  2138. function onWheel(e) {
  2139. if (e.cancelable) {
  2140. const { deltaY } = e;
  2141. if (deltaY) {
  2142. const backwards = deltaY < 0;
  2143. Splide2.go(backwards ? "<" : ">");
  2144. shouldPrevent(backwards) && prevent(e);
  2145. }
  2146. }
  2147. }
  2148. function shouldPrevent(backwards) {
  2149. return !options.releaseWheel || Splide2.state.is(MOVING) || Components2.Controller.getAdjacent(backwards) !== -1;
  2150. }
  2151. return {
  2152. mount
  2153. };
  2154. }
  2155. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2156. __proto__: null,
  2157. Options: Options,
  2158. Direction: Direction,
  2159. Elements: Elements,
  2160. Slides: Slides,
  2161. Layout: Layout,
  2162. Clones: Clones,
  2163. Move: Move,
  2164. Controller: Controller,
  2165. Arrows: Arrows,
  2166. Autoplay: Autoplay,
  2167. Cover: Cover,
  2168. Scroll: Scroll,
  2169. Drag: Drag,
  2170. Keyboard: Keyboard,
  2171. LazyLoad: LazyLoad,
  2172. Pagination: Pagination,
  2173. Sync: Sync,
  2174. Live: Live,
  2175. Wheel: Wheel
  2176. });
  2177. const I18N = {
  2178. prev: "Previous slide",
  2179. next: "Next slide",
  2180. first: "Go to first slide",
  2181. last: "Go to last slide",
  2182. slideX: "Go to slide %s",
  2183. pageX: "Go to page %s",
  2184. play: "Start autoplay",
  2185. pause: "Pause autoplay",
  2186. carousel: "carousel",
  2187. slide: "slide",
  2188. slideLabel: "%s of %s"
  2189. };
  2190. const DEFAULTS = {
  2191. type: "slide",
  2192. role: "region",
  2193. speed: 400,
  2194. waitForTransition: true,
  2195. perPage: 1,
  2196. cloneStatus: true,
  2197. arrows: true,
  2198. pagination: true,
  2199. interval: 5e3,
  2200. pauseOnHover: true,
  2201. pauseOnFocus: true,
  2202. resetProgress: true,
  2203. keyboard: true,
  2204. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  2205. drag: true,
  2206. direction: "ltr",
  2207. slideFocus: true,
  2208. trimSpace: true,
  2209. focusableNodes: "a, button, textarea, input, select, iframe",
  2210. classes: CLASSES,
  2211. i18n: I18N
  2212. };
  2213. function Fade(Splide2, Components2, options) {
  2214. const { on } = EventInterface(Splide2);
  2215. function mount() {
  2216. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  2217. nextTick(() => {
  2218. Components2.Slides.style("transition", `opacity ${options.speed}ms ${options.easing}`);
  2219. });
  2220. });
  2221. }
  2222. function start(index, done) {
  2223. const { track } = Components2.Elements;
  2224. style(track, "height", unit(rect(track).height));
  2225. nextTick(() => {
  2226. done();
  2227. style(track, "height", "");
  2228. });
  2229. }
  2230. return {
  2231. mount,
  2232. start,
  2233. cancel: noop
  2234. };
  2235. }
  2236. function Slide(Splide2, Components2, options) {
  2237. const { bind } = EventInterface(Splide2);
  2238. const { Move, Controller } = Components2;
  2239. const { list } = Components2.Elements;
  2240. let endCallback;
  2241. function mount() {
  2242. bind(list, "transitionend", (e) => {
  2243. if (e.target === list && endCallback) {
  2244. cancel();
  2245. endCallback();
  2246. }
  2247. });
  2248. }
  2249. function start(index, done) {
  2250. const destination = Move.toPosition(index, true);
  2251. const position = Move.getPosition();
  2252. const speed = getSpeed(index);
  2253. if (abs(destination - position) >= 1 && speed >= 1) {
  2254. apply(`transform ${speed}ms ${options.easing}`);
  2255. Move.translate(destination, true);
  2256. endCallback = done;
  2257. } else {
  2258. Move.jump(index);
  2259. done();
  2260. }
  2261. }
  2262. function cancel() {
  2263. apply("");
  2264. }
  2265. function getSpeed(index) {
  2266. const { rewindSpeed } = options;
  2267. if (Splide2.is(SLIDE) && rewindSpeed) {
  2268. const prev = Controller.getIndex(true);
  2269. const end = Controller.getEnd();
  2270. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2271. return rewindSpeed;
  2272. }
  2273. }
  2274. return options.speed;
  2275. }
  2276. function apply(transition) {
  2277. style(list, "transition", transition);
  2278. }
  2279. return {
  2280. mount,
  2281. start,
  2282. cancel
  2283. };
  2284. }
  2285. const _Splide = class {
  2286. constructor(target, options) {
  2287. this.event = EventBus();
  2288. this.Components = {};
  2289. this.state = State(CREATED);
  2290. this.splides = [];
  2291. this._options = {};
  2292. this._Extensions = {};
  2293. const root = isString(target) ? query(document, target) : target;
  2294. assert(root, `${root} is invalid.`);
  2295. this.root = root;
  2296. merge(DEFAULTS, _Splide.defaults);
  2297. merge(merge(this._options, DEFAULTS), options || {});
  2298. try {
  2299. merge(this._options, JSON.parse(getAttribute(root, DATA_ATTRIBUTE)));
  2300. } catch (e) {
  2301. assert(false, e.message);
  2302. }
  2303. }
  2304. mount(Extensions, Transition) {
  2305. const { state, Components: Components2 } = this;
  2306. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2307. state.set(CREATED);
  2308. this._Components = Components2;
  2309. this._Transition = Transition || this._Transition || (this.is(FADE) ? Fade : Slide);
  2310. this._Extensions = Extensions || this._Extensions;
  2311. const Constructors = assign({}, ComponentConstructors, this._Extensions, { Transition: this._Transition });
  2312. forOwn(Constructors, (Component, key) => {
  2313. const component = Component(this, Components2, this._options);
  2314. Components2[key] = component;
  2315. component.setup && component.setup();
  2316. });
  2317. forOwn(Components2, (component) => {
  2318. component.mount && component.mount();
  2319. });
  2320. this.emit(EVENT_MOUNTED);
  2321. addClass(this.root, CLASS_INITIALIZED);
  2322. state.set(IDLE);
  2323. this.emit(EVENT_READY);
  2324. return this;
  2325. }
  2326. sync(splide) {
  2327. this.splides.push({ splide });
  2328. splide.splides.push({ splide: this, isParent: true });
  2329. if (this.state.is(IDLE)) {
  2330. this._Components.Sync.remount();
  2331. splide.Components.Sync.remount();
  2332. }
  2333. return this;
  2334. }
  2335. go(control) {
  2336. this._Components.Controller.go(control);
  2337. return this;
  2338. }
  2339. on(events, callback) {
  2340. this.event.on(events, callback, null, DEFAULT_USER_EVENT_PRIORITY);
  2341. return this;
  2342. }
  2343. off(events) {
  2344. this.event.off(events);
  2345. return this;
  2346. }
  2347. emit(event) {
  2348. this.event.emit(event, ...slice(arguments, 1));
  2349. return this;
  2350. }
  2351. add(slides, index) {
  2352. this._Components.Slides.add(slides, index);
  2353. return this;
  2354. }
  2355. remove(matcher) {
  2356. this._Components.Slides.remove(matcher);
  2357. return this;
  2358. }
  2359. is(type) {
  2360. return this._options.type === type;
  2361. }
  2362. refresh() {
  2363. this.emit(EVENT_REFRESH);
  2364. return this;
  2365. }
  2366. destroy(completely = true) {
  2367. const { event, state } = this;
  2368. if (state.is(CREATED)) {
  2369. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  2370. } else {
  2371. forOwn(this._Components, (component) => {
  2372. component.destroy && component.destroy(completely);
  2373. }, true);
  2374. event.emit(EVENT_DESTROY);
  2375. event.destroy();
  2376. completely && empty(this.splides);
  2377. state.set(DESTROYED);
  2378. }
  2379. return this;
  2380. }
  2381. get options() {
  2382. return this._options;
  2383. }
  2384. set options(options) {
  2385. const { _options } = this;
  2386. merge(_options, options);
  2387. if (!this.state.is(CREATED)) {
  2388. this.emit(EVENT_UPDATED, _options);
  2389. }
  2390. }
  2391. get length() {
  2392. return this._Components.Slides.getLength(true);
  2393. }
  2394. get index() {
  2395. return this._Components.Controller.getIndex();
  2396. }
  2397. };
  2398. let Splide = _Splide;
  2399. Splide.defaults = {};
  2400. Splide.STATES = STATES;
  2401. const CLASS_RENDERED = "is-rendered";
  2402. const RENDERER_DEFAULT_CONFIG = {
  2403. listTag: "ul",
  2404. slideTag: "li"
  2405. };
  2406. class Style {
  2407. constructor(id, options) {
  2408. this.styles = {};
  2409. this.id = id;
  2410. this.options = options;
  2411. }
  2412. rule(selector, prop, value, breakpoint) {
  2413. breakpoint = breakpoint || "default";
  2414. const selectors = this.styles[breakpoint] = this.styles[breakpoint] || {};
  2415. const styles = selectors[selector] = selectors[selector] || {};
  2416. styles[prop] = value;
  2417. }
  2418. build() {
  2419. let css = "";
  2420. if (this.styles.default) {
  2421. css += this.buildSelectors(this.styles.default);
  2422. }
  2423. Object.keys(this.styles).sort((n, m) => this.options.mediaQuery === "min" ? +n - +m : +m - +n).forEach((breakpoint) => {
  2424. if (breakpoint !== "default") {
  2425. css += `@media screen and (max-width: ${breakpoint}px) {`;
  2426. css += this.buildSelectors(this.styles[breakpoint]);
  2427. css += `}`;
  2428. }
  2429. });
  2430. return css;
  2431. }
  2432. buildSelectors(selectors) {
  2433. let css = "";
  2434. forOwn(selectors, (styles, selector) => {
  2435. selector = `#${this.id} ${selector}`.trim();
  2436. css += `${selector} {`;
  2437. forOwn(styles, (value, prop) => {
  2438. if (value || value === 0) {
  2439. css += `${prop}: ${value};`;
  2440. }
  2441. });
  2442. css += "}";
  2443. });
  2444. return css;
  2445. }
  2446. }
  2447. class SplideRenderer {
  2448. constructor(contents, options, config, defaults) {
  2449. this.slides = [];
  2450. this.options = {};
  2451. this.breakpoints = [];
  2452. merge(DEFAULTS, defaults || {});
  2453. merge(merge(this.options, DEFAULTS), options || {});
  2454. this.contents = contents;
  2455. this.config = assign({}, RENDERER_DEFAULT_CONFIG, config || {});
  2456. this.id = this.config.id || uniqueId("splide");
  2457. this.Style = new Style(this.id, this.options);
  2458. this.Direction = Direction(null, null, this.options);
  2459. assert(this.contents.length, "Provide at least 1 content.");
  2460. this.init();
  2461. }
  2462. static clean(splide) {
  2463. const { on } = EventInterface(splide);
  2464. const { root } = splide;
  2465. const clones = queryAll(root, `.${CLASS_CLONE}`);
  2466. on(EVENT_MOUNTED, () => {
  2467. remove(child(root, "style"));
  2468. });
  2469. remove(clones);
  2470. }
  2471. init() {
  2472. this.parseBreakpoints();
  2473. this.initSlides();
  2474. this.registerRootStyles();
  2475. this.registerTrackStyles();
  2476. this.registerSlideStyles();
  2477. this.registerListStyles();
  2478. }
  2479. initSlides() {
  2480. push(this.slides, this.contents.map((content, index) => {
  2481. content = isString(content) ? { html: content } : content;
  2482. content.styles = content.styles || {};
  2483. content.attrs = content.attrs || {};
  2484. this.cover(content);
  2485. const classes = `${this.options.classes.slide} ${index === 0 ? CLASS_ACTIVE : ""}`;
  2486. assign(content.attrs, {
  2487. class: `${classes} ${content.attrs.class || ""}`.trim(),
  2488. style: this.buildStyles(content.styles)
  2489. });
  2490. return content;
  2491. }));
  2492. if (this.isLoop()) {
  2493. this.generateClones(this.slides);
  2494. }
  2495. }
  2496. registerRootStyles() {
  2497. this.breakpoints.forEach(([width, options]) => {
  2498. this.Style.rule(" ", "max-width", unit(options.width), width);
  2499. });
  2500. }
  2501. registerTrackStyles() {
  2502. const { Style: Style2 } = this;
  2503. const selector = `.${CLASS_TRACK}`;
  2504. this.breakpoints.forEach(([width, options]) => {
  2505. Style2.rule(selector, this.resolve("paddingLeft"), this.cssPadding(options, false), width);
  2506. Style2.rule(selector, this.resolve("paddingRight"), this.cssPadding(options, true), width);
  2507. Style2.rule(selector, "height", this.cssTrackHeight(options), width);
  2508. });
  2509. }
  2510. registerListStyles() {
  2511. const { Style: Style2 } = this;
  2512. const selector = `.${CLASS_LIST}`;
  2513. this.breakpoints.forEach(([width, options]) => {
  2514. Style2.rule(selector, "transform", this.buildTranslate(options), width);
  2515. if (!this.cssSlideHeight(options)) {
  2516. Style2.rule(selector, "aspect-ratio", this.cssAspectRatio(options), width);
  2517. }
  2518. });
  2519. }
  2520. registerSlideStyles() {
  2521. const { Style: Style2 } = this;
  2522. const selector = `.${CLASS_SLIDE}`;
  2523. this.breakpoints.forEach(([width, options]) => {
  2524. Style2.rule(selector, "width", this.cssSlideWidth(options), width);
  2525. Style2.rule(selector, "height", this.cssSlideHeight(options) || "100%", width);
  2526. Style2.rule(selector, this.resolve("marginRight"), unit(options.gap) || "0px", width);
  2527. Style2.rule(`${selector} > img`, "display", options.cover ? "none" : "inline", width);
  2528. });
  2529. }
  2530. buildTranslate(options) {
  2531. const { resolve, orient } = this.Direction;
  2532. const values = [];
  2533. values.push(this.cssOffsetClones(options));
  2534. values.push(this.cssOffsetGaps(options));
  2535. if (this.isCenter(options)) {
  2536. values.push(this.buildCssValue(orient(-50), "%"));
  2537. values.push(...this.cssOffsetCenter(options));
  2538. }
  2539. return values.filter(Boolean).map((value) => `translate${resolve("X")}(${value})`).join(" ");
  2540. }
  2541. cssOffsetClones(options) {
  2542. const { resolve, orient } = this.Direction;
  2543. const cloneCount = this.getCloneCount();
  2544. if (this.isFixedWidth(options)) {
  2545. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2546. return this.buildCssValue(orient(value) * cloneCount, unit2);
  2547. }
  2548. const percent = 100 * cloneCount / options.perPage;
  2549. return `${orient(percent)}%`;
  2550. }
  2551. cssOffsetCenter(options) {
  2552. const { resolve, orient } = this.Direction;
  2553. if (this.isFixedWidth(options)) {
  2554. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2555. return [this.buildCssValue(orient(value / 2), unit2)];
  2556. }
  2557. const values = [];
  2558. const { perPage, gap } = options;
  2559. values.push(`${orient(50 / perPage)}%`);
  2560. if (gap) {
  2561. const { value, unit: unit2 } = this.parseCssValue(gap);
  2562. const gapOffset = (value / perPage - value) / 2;
  2563. values.push(this.buildCssValue(orient(gapOffset), unit2));
  2564. }
  2565. return values;
  2566. }
  2567. cssOffsetGaps(options) {
  2568. const cloneCount = this.getCloneCount();
  2569. if (cloneCount && options.gap) {
  2570. const { orient } = this.Direction;
  2571. const { value, unit: unit2 } = this.parseCssValue(options.gap);
  2572. if (this.isFixedWidth(options)) {
  2573. return this.buildCssValue(orient(value * cloneCount), unit2);
  2574. }
  2575. const { perPage } = options;
  2576. const gaps = cloneCount / perPage;
  2577. return this.buildCssValue(orient(gaps * value), unit2);
  2578. }
  2579. return "";
  2580. }
  2581. resolve(prop) {
  2582. return camelToKebab(this.Direction.resolve(prop));
  2583. }
  2584. cssPadding(options, right) {
  2585. const { padding } = options;
  2586. const prop = this.Direction.resolve(right ? "right" : "left", true);
  2587. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  2588. }
  2589. cssTrackHeight(options) {
  2590. let height = "";
  2591. if (this.isVertical()) {
  2592. height = this.cssHeight(options);
  2593. assert(height, '"height" is missing.');
  2594. height = `calc(${height} - ${this.cssPadding(options, false)} - ${this.cssPadding(options, true)})`;
  2595. }
  2596. return height;
  2597. }
  2598. cssHeight(options) {
  2599. return unit(options.height);
  2600. }
  2601. cssSlideWidth(options) {
  2602. return options.autoWidth ? "" : unit(options.fixedWidth) || (this.isVertical() ? "" : this.cssSlideSize(options));
  2603. }
  2604. cssSlideHeight(options) {
  2605. return unit(options.fixedHeight) || (this.isVertical() ? options.autoHeight ? "" : this.cssSlideSize(options) : this.cssHeight(options));
  2606. }
  2607. cssSlideSize(options) {
  2608. const gap = unit(options.gap);
  2609. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  2610. }
  2611. cssAspectRatio(options) {
  2612. const { heightRatio } = options;
  2613. return heightRatio ? `${1 / heightRatio}` : "";
  2614. }
  2615. buildCssValue(value, unit2) {
  2616. return `${value}${unit2}`;
  2617. }
  2618. parseCssValue(value) {
  2619. if (isString(value)) {
  2620. const number = parseFloat(value) || 0;
  2621. const unit2 = value.replace(/\d*(\.\d*)?/, "") || "px";
  2622. return { value: number, unit: unit2 };
  2623. }
  2624. return { value, unit: "px" };
  2625. }
  2626. parseBreakpoints() {
  2627. const { breakpoints } = this.options;
  2628. this.breakpoints.push(["default", this.options]);
  2629. if (breakpoints) {
  2630. forOwn(breakpoints, (options, width) => {
  2631. this.breakpoints.push([width, merge(merge({}, this.options), options)]);
  2632. });
  2633. }
  2634. }
  2635. isFixedWidth(options) {
  2636. return !!options[this.Direction.resolve("fixedWidth")];
  2637. }
  2638. isLoop() {
  2639. return this.options.type === LOOP;
  2640. }
  2641. isCenter(options) {
  2642. if (options.focus === "center") {
  2643. if (this.isLoop()) {
  2644. return true;
  2645. }
  2646. if (this.options.type === SLIDE) {
  2647. return !this.options.trimSpace;
  2648. }
  2649. }
  2650. return false;
  2651. }
  2652. isVertical() {
  2653. return this.options.direction === TTB;
  2654. }
  2655. buildClasses() {
  2656. const { options } = this;
  2657. return [
  2658. CLASS_ROOT,
  2659. `${CLASS_ROOT}--${options.type}`,
  2660. `${CLASS_ROOT}--${options.direction}`,
  2661. options.drag && `${CLASS_ROOT}--draggable`,
  2662. options.isNavigation && `${CLASS_ROOT}--nav`,
  2663. CLASS_ACTIVE,
  2664. !this.config.hidden && CLASS_RENDERED
  2665. ].filter(Boolean).join(" ");
  2666. }
  2667. buildAttrs(attrs) {
  2668. let attr = "";
  2669. forOwn(attrs, (value, key) => {
  2670. attr += value ? ` ${camelToKebab(key)}="${value}"` : "";
  2671. });
  2672. return attr.trim();
  2673. }
  2674. buildStyles(styles) {
  2675. let style = "";
  2676. forOwn(styles, (value, key) => {
  2677. style += ` ${camelToKebab(key)}:${value};`;
  2678. });
  2679. return style.trim();
  2680. }
  2681. renderSlides() {
  2682. const { slideTag: tag } = this.config;
  2683. return this.slides.map((content) => {
  2684. return `<${tag} ${this.buildAttrs(content.attrs)}>${content.html || ""}</${tag}>`;
  2685. }).join("");
  2686. }
  2687. cover(content) {
  2688. const { styles, html = "" } = content;
  2689. if (this.options.cover && !this.options.lazyLoad) {
  2690. const src = html.match(/<img.*?src\s*=\s*(['"])(.+?)\1.*?>/);
  2691. if (src && src[2]) {
  2692. styles.background = `center/cover no-repeat url('${src[2]}')`;
  2693. }
  2694. }
  2695. }
  2696. generateClones(contents) {
  2697. const { classes } = this.options;
  2698. const count = this.getCloneCount();
  2699. const slides = contents.slice();
  2700. while (slides.length < count) {
  2701. push(slides, slides);
  2702. }
  2703. push(slides.slice(-count).reverse(), slides.slice(0, count)).forEach((content, index) => {
  2704. const attrs = assign({}, content.attrs, { class: `${content.attrs.class} ${classes.clone}` });
  2705. const clone = assign({}, content, { attrs });
  2706. index < count ? contents.unshift(clone) : contents.push(clone);
  2707. });
  2708. }
  2709. getCloneCount() {
  2710. if (this.isLoop()) {
  2711. const { options } = this;
  2712. if (options.clones) {
  2713. return options.clones;
  2714. }
  2715. const perPage = max(...this.breakpoints.map(([, options2]) => options2.perPage));
  2716. return perPage * ((options.flickMaxPages || 1) + 1);
  2717. }
  2718. return 0;
  2719. }
  2720. renderArrows() {
  2721. let html = "";
  2722. html += `<div class="${this.options.classes.arrows}">`;
  2723. html += this.renderArrow(true);
  2724. html += this.renderArrow(false);
  2725. html += `</div>`;
  2726. return html;
  2727. }
  2728. renderArrow(prev) {
  2729. const { classes, i18n } = this.options;
  2730. const attrs = {
  2731. class: `${classes.arrow} ${prev ? classes.prev : classes.next}`,
  2732. type: "button",
  2733. ariaLabel: prev ? i18n.prev : i18n.next
  2734. };
  2735. return `<button ${this.buildAttrs(attrs)}><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${this.options.arrowPath || PATH}" /></svg></button>`;
  2736. }
  2737. html() {
  2738. const { rootClass, listTag, arrows, beforeTrack, afterTrack, slider, beforeSlider, afterSlider } = this.config;
  2739. let html = "";
  2740. html += `<div id="${this.id}" class="${this.buildClasses()} ${rootClass || ""}">`;
  2741. html += `<style>${this.Style.build()}</style>`;
  2742. if (slider) {
  2743. html += beforeSlider || "";
  2744. html += `<div class="splide__slider">`;
  2745. }
  2746. html += beforeTrack || "";
  2747. if (arrows) {
  2748. html += this.renderArrows();
  2749. }
  2750. html += `<div class="splide__track">`;
  2751. html += `<${listTag} class="splide__list">`;
  2752. html += this.renderSlides();
  2753. html += `</${listTag}>`;
  2754. html += `</div>`;
  2755. html += afterTrack || "";
  2756. if (slider) {
  2757. html += `</div>`;
  2758. html += afterSlider || "";
  2759. }
  2760. html += `</div>`;
  2761. return html;
  2762. }
  2763. }
  2764. export { CLASSES, CLASS_ACTIVE, CLASS_ARROW, CLASS_ARROWS, CLASS_ARROW_NEXT, CLASS_ARROW_PREV, CLASS_AUTOPLAY, CLASS_CLONE, CLASS_CONTAINER, CLASS_INITIALIZED, CLASS_LIST, CLASS_LOADING, CLASS_NEXT, CLASS_PAGINATION, CLASS_PAGINATION_PAGE, CLASS_PAUSE, CLASS_PLAY, CLASS_PREV, CLASS_PROGRESS, CLASS_PROGRESS_BAR, CLASS_ROOT, CLASS_SLIDE, CLASS_SLIDER, CLASS_SPINNER, CLASS_SR, CLASS_TRACK, CLASS_VISIBLE, EVENT_ACTIVE, EVENT_ARROWS_MOUNTED, EVENT_ARROWS_UPDATED, EVENT_AUTOPLAY_PAUSE, EVENT_AUTOPLAY_PLAY, EVENT_AUTOPLAY_PLAYING, EVENT_CLICK, EVENT_DESTROY, EVENT_DRAG, EVENT_DRAGGED, EVENT_DRAGGING, EVENT_HIDDEN, EVENT_INACTIVE, EVENT_LAZYLOAD_LOADED, EVENT_MOUNTED, EVENT_MOVE, EVENT_MOVED, EVENT_NAVIGATION_MOUNTED, EVENT_PAGINATION_MOUNTED, EVENT_PAGINATION_UPDATED, EVENT_READY, EVENT_REFRESH, EVENT_REPOSITIONED, EVENT_RESIZE, EVENT_RESIZED, EVENT_SCROLL, EVENT_SCROLLED, EVENT_SHIFTED, EVENT_SLIDE_KEYDOWN, EVENT_UPDATED, EVENT_VISIBLE, EventBus, EventInterface, RequestInterval, STATUS_CLASSES, Splide, SplideRenderer, State, Throttle, Splide as default };