splide.cjs.js 81 KB

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