splide.js 77 KB

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