splide.esm.js 78 KB

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