splide.js 76 KB

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