splide.js 70 KB

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