splide.esm.js 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
  1. /*!
  2. * Splide.js
  3. * Version : 4.1.3
  4. * License : MIT
  5. * Copyright: 2022 Naotoshi Fujita
  6. */
  7. const MEDIA_PREFERS_REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
  8. const CREATED = 1;
  9. const MOUNTED = 2;
  10. const IDLE = 3;
  11. const MOVING = 4;
  12. const SCROLLING = 5;
  13. const DRAGGING = 6;
  14. const DESTROYED = 7;
  15. const STATES = {
  16. CREATED,
  17. MOUNTED,
  18. IDLE,
  19. MOVING,
  20. SCROLLING,
  21. DRAGGING,
  22. DESTROYED
  23. };
  24. function N(n) {
  25. n.length = 0;
  26. }
  27. function a(n, ...t) {
  28. return n.bind(null, ...t);
  29. }
  30. const dn = setTimeout, an = () => {
  31. };
  32. function P(n) {
  33. return requestAnimationFrame(n);
  34. }
  35. function m(n, t) {
  36. return typeof t === n;
  37. }
  38. function y(n) {
  39. return !S(n) && m("object", n);
  40. }
  41. const g = Array.isArray, ln = a(m, "function"), p = a(m, "string"); a(m, "boolean"); const Z = a(m, "undefined");
  42. function S(n) {
  43. return n === null;
  44. }
  45. function x(n) {
  46. try {
  47. return n instanceof (n.ownerDocument.defaultView || window).HTMLElement;
  48. } catch {
  49. return false;
  50. }
  51. }
  52. function q(n) {
  53. return g(n) ? n : [n];
  54. }
  55. function d(n, t) {
  56. q(n).forEach(t);
  57. }
  58. function G(n, t) {
  59. return n.includes(t);
  60. }
  61. function pn(n, t) {
  62. return n.push(...q(t)), n;
  63. }
  64. const D = Array.prototype;
  65. function F(n, t, e) {
  66. return D.slice.call(n, t, e);
  67. }
  68. function I(n, t, e) {
  69. n && d(p(t) ? t.split(" ") : t, (i) => {
  70. i && n.classList.toggle(i, e);
  71. });
  72. }
  73. function J(n, t) {
  74. I(n, t, true);
  75. }
  76. function Q(n, t) {
  77. d(t, n.appendChild.bind(n));
  78. }
  79. function yn(n, t) {
  80. d(n, (e) => {
  81. const i = (t || e).parentNode;
  82. i && i.insertBefore(e, t);
  83. });
  84. }
  85. function W(n, t) {
  86. return x(n) && n.matches(t);
  87. }
  88. function X(n, t) {
  89. const e = n ? F(n.children) : [];
  90. return t ? e.filter((i) => W(i, t)) : e;
  91. }
  92. function Y(n, t) {
  93. return t ? X(n, t)[0] : n.firstElementChild;
  94. }
  95. function En(n, t) {
  96. return n.closest(t);
  97. }
  98. const v = Object.assign, A = Object.keys;
  99. function L(n, t, e) {
  100. return n && (e ? A(n).reverse() : A(n)).forEach((i) => {
  101. i !== "__proto__" && t(n[i], i);
  102. }), n;
  103. }
  104. function k(n, ...t) {
  105. return t.forEach((e) => {
  106. L(e, (i, r) => {
  107. g(i) ? i = i.slice() : y(i) && (i = k({}, y(n[r]) ? n[r] : {}, i)), n[r] = i;
  108. });
  109. }), n;
  110. }
  111. function gn(n, t) {
  112. return d(t || A(n), (e) => {
  113. delete n[e];
  114. }), n;
  115. }
  116. function U(n, t) {
  117. d(n, (e) => {
  118. d(t, (i) => {
  119. e && e.removeAttribute(i);
  120. });
  121. });
  122. }
  123. function M(n, t, e) {
  124. y(t) ? L(t, (i, r) => {
  125. M(n, r, i);
  126. }) : d(n, (i) => {
  127. S(e) || e === "" ? U(i, t) : i.setAttribute(t, String(e));
  128. });
  129. }
  130. function j(n, t, e) {
  131. const i = document.createElement(n);
  132. return t && (p(t) ? J(i, t) : M(i, t)), e && Q(e, i), i;
  133. }
  134. function nn(n, t, e) {
  135. if (Z(e))
  136. return getComputedStyle(n)[t];
  137. S(e) || (n.style[t] = `${e}`);
  138. }
  139. function An(n, t) {
  140. nn(n, "display", t);
  141. }
  142. function $n(n) {
  143. x(n) && n.focus({ preventScroll: true });
  144. }
  145. function wn(n, t) {
  146. return n.getAttribute(t);
  147. }
  148. function Cn(n, t) {
  149. return !!n && n.classList.contains(t);
  150. }
  151. function tn(n) {
  152. return n.getBoundingClientRect();
  153. }
  154. function en(n) {
  155. d(n, (t) => {
  156. t && t.parentNode && t.parentNode.removeChild(t);
  157. });
  158. }
  159. function qn(n) {
  160. return Y(new DOMParser().parseFromString(n, "text/html").body);
  161. }
  162. function Ln(n, t) {
  163. n.preventDefault(), t && (n.stopPropagation(), n.stopImmediatePropagation());
  164. }
  165. function On(n, t) {
  166. return n && n.querySelector(t);
  167. }
  168. function Tn(n, t) {
  169. return t && n ? F(n.querySelectorAll(t)) : [];
  170. }
  171. function Pn(n, t) {
  172. I(n, t, false);
  173. }
  174. function Bn(n) {
  175. return n.timeStamp;
  176. }
  177. function Nn(n) {
  178. return p(n) ? n : n ? `${n}px` : "";
  179. }
  180. function rn(n) {
  181. let t = "";
  182. return L(n, (e, i) => {
  183. t += e || e === 0 ? ` ${i}${e !== true ? `="${e}"` : ""}` : "";
  184. }), t.trim();
  185. }
  186. function _(...n) {
  187. return n.reduce((t, e) => `${t} ${g(e) ? _(...e) : e || ""}`.trim(), "");
  188. }
  189. function on(n, t) {
  190. return t = g(t) || !y(t) ? { class: _(t) } : t, `<${`${n} ${t ? rn(t) : ""}`.trim()}>`;
  191. }
  192. a(on, "div"); const { min: E, max: $, floor: Dn, ceil: Fn, abs: un, sign: In } = Math;
  193. function Mn(n, t, e) {
  194. return un(n - t) < e;
  195. }
  196. function _n(n, t, e, i) {
  197. const r = E(t, e), o = $(t, e);
  198. return i ? r < n && n < o : r <= n && n <= o;
  199. }
  200. function bn(n, t, e) {
  201. const i = E(t, e), r = $(t, e);
  202. return E($(i, n), r);
  203. }
  204. function Hn(n) {
  205. return n.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
  206. }
  207. function Kn(n, t) {
  208. return d(t, (e) => {
  209. n = n.replace("%s", `${e}`);
  210. }), n;
  211. }
  212. function cn(n, t = 2) {
  213. return `${n}`.padStart(t, "0");
  214. }
  215. const B = {};
  216. function zn(n) {
  217. return `${n}${cn(B[n] = (B[n] || 0) + 1)}`;
  218. }
  219. function w(n, t) {
  220. d(n, (e) => {
  221. p(e) && e.split(" ").forEach(t);
  222. });
  223. }
  224. function C(n, t) {
  225. const e = [];
  226. for (let i = n.length - 1; i >= 0; i--)
  227. t(n[i]) && e.push(...n.splice(i, 1));
  228. return e;
  229. }
  230. function b(n) {
  231. const t = n || [], e = n ? {} : void 0;
  232. function i(o, f, u, c) {
  233. w(f, (s) => {
  234. o.addEventListener(s, u, c), t.push([o.removeEventListener.bind(o, s, u, c), e]);
  235. });
  236. }
  237. function r() {
  238. e ? C(t, (o) => o[1] === e).forEach((o) => {
  239. o[0]();
  240. }) : (t.forEach((o) => {
  241. o[0]();
  242. }), N(t));
  243. }
  244. return {
  245. bind: i,
  246. create: a(b, t),
  247. destroy: r
  248. };
  249. }
  250. function H(n) {
  251. const t = n || [], e = n ? {} : void 0;
  252. function i(u, c) {
  253. w(u, (s) => {
  254. t.push([s, c, e]);
  255. });
  256. }
  257. function r(u, c) {
  258. w(u, (s) => {
  259. C(t, (l) => l[0] === s && (!c || l[1] === c) && l[2] === e);
  260. });
  261. }
  262. function o(u, ...c) {
  263. t.slice().forEach((s) => {
  264. s[0] === u && s[1](...c);
  265. });
  266. }
  267. function f() {
  268. e ? C(t, (u) => u[2] === e) : N(t);
  269. }
  270. return {
  271. on: i,
  272. off: r,
  273. emit: o,
  274. create: a(H, t),
  275. destroy: f
  276. };
  277. }
  278. function fn(n = b(), t = H()) {
  279. function e() {
  280. return fn(n.create(), t.create());
  281. }
  282. function i() {
  283. n.destroy(), t.destroy();
  284. }
  285. return v({}, n, t, { create: e, destroy: i });
  286. }
  287. function sn(n, t, e, i) {
  288. const { now: r } = Date;
  289. let o, f = 0, u, c = true, s = 0;
  290. function l() {
  291. if (!c) {
  292. if (f = n ? E((r() - o) / n, 1) : 1, e && e(f), f >= 1 && (t(), o = r(), i && ++s >= i))
  293. return O();
  294. u = P(l);
  295. }
  296. }
  297. function K(h) {
  298. h || T(), o = r() - (h ? f * n : 0), c = false, u = P(l);
  299. }
  300. function O() {
  301. c = true;
  302. }
  303. function z() {
  304. o = r(), f = 0, e && e(f);
  305. }
  306. function T() {
  307. u && cancelAnimationFrame(u), f = 0, u = 0, c = true;
  308. }
  309. function R(h) {
  310. n = h;
  311. }
  312. function V() {
  313. return c;
  314. }
  315. return {
  316. start: K,
  317. rewind: z,
  318. pause: O,
  319. cancel: T,
  320. set: R,
  321. isPaused: V
  322. };
  323. }
  324. function Rn(n) {
  325. let t = n;
  326. function e(r) {
  327. t = r;
  328. }
  329. function i(r) {
  330. return G(q(r), t);
  331. }
  332. return { set: e, is: i };
  333. }
  334. function Vn(n, t) {
  335. const e = sn(t || 0, n, void 0, 1);
  336. return () => {
  337. e.isPaused() && e.start();
  338. };
  339. }
  340. const EVENT_MOUNTED = "mounted";
  341. const EVENT_READY = "ready";
  342. const EVENT_MOVE = "move";
  343. const EVENT_MOVED = "moved";
  344. const EVENT_CLICK = "click";
  345. const EVENT_ACTIVE = "active";
  346. const EVENT_INACTIVE = "inactive";
  347. const EVENT_VISIBLE = "visible";
  348. const EVENT_HIDDEN = "hidden";
  349. const EVENT_REFRESH = "refresh";
  350. const EVENT_UPDATED = "updated";
  351. const EVENT_RESIZE = "resize";
  352. const EVENT_RESIZED = "resized";
  353. const EVENT_DRAG = "drag";
  354. const EVENT_DRAGGING = "dragging";
  355. const EVENT_DRAGGED = "dragged";
  356. const EVENT_SCROLL = "scroll";
  357. const EVENT_SCROLLED = "scrolled";
  358. const EVENT_OVERFLOW = "overflow";
  359. const EVENT_DESTROY = "destroy";
  360. const EVENT_ARROWS_MOUNTED = "arrows:mounted";
  361. const EVENT_ARROWS_UPDATED = "arrows:updated";
  362. const EVENT_PAGINATION_MOUNTED = "pagination:mounted";
  363. const EVENT_PAGINATION_UPDATED = "pagination:updated";
  364. const EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
  365. const EVENT_AUTOPLAY_PLAY = "autoplay:play";
  366. const EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
  367. const EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
  368. const EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
  369. const EVENT_SLIDE_KEYDOWN = "sk";
  370. const EVENT_SHIFTED = "sh";
  371. const EVENT_END_INDEX_CHANGED = "ei";
  372. function Media(Splide2, Components2, options) {
  373. const { state } = Splide2;
  374. const breakpoints = options.breakpoints || {};
  375. const reducedMotion = options.reducedMotion || {};
  376. const binder = b();
  377. const queries = [];
  378. function setup() {
  379. const isMin = options.mediaQuery === "min";
  380. A(breakpoints).sort((n, m) => isMin ? +n - +m : +m - +n).forEach((key) => {
  381. register(breakpoints[key], `(${isMin ? "min" : "max"}-width:${key}px)`);
  382. });
  383. register(reducedMotion, MEDIA_PREFERS_REDUCED_MOTION);
  384. update();
  385. }
  386. function destroy(completely) {
  387. if (completely) {
  388. binder.destroy();
  389. }
  390. }
  391. function register(options2, query) {
  392. const queryList = matchMedia(query);
  393. binder.bind(queryList, "change", update);
  394. queries.push([options2, queryList]);
  395. }
  396. function update() {
  397. const destroyed = state.is(DESTROYED);
  398. const direction = options.direction;
  399. const merged = queries.reduce((merged2, entry) => {
  400. return k(merged2, entry[1].matches ? entry[0] : {});
  401. }, {});
  402. gn(options);
  403. set(merged);
  404. if (options.destroy) {
  405. Splide2.destroy(options.destroy === "completely");
  406. } else if (destroyed) {
  407. destroy(true);
  408. Splide2.mount();
  409. } else {
  410. direction !== options.direction && Splide2.refresh();
  411. }
  412. }
  413. function reduce(enable) {
  414. if (matchMedia(MEDIA_PREFERS_REDUCED_MOTION).matches) {
  415. enable ? k(options, reducedMotion) : gn(options, A(reducedMotion));
  416. }
  417. }
  418. function set(opts, base, notify) {
  419. k(options, opts);
  420. base && k(Object.getPrototypeOf(options), opts);
  421. if (notify || !state.is(CREATED)) {
  422. Splide2.emit(EVENT_UPDATED, options);
  423. }
  424. }
  425. return {
  426. setup,
  427. destroy,
  428. reduce,
  429. set
  430. };
  431. }
  432. const ARROW = "Arrow";
  433. const ARROW_LEFT = `${ARROW}Left`;
  434. const ARROW_RIGHT = `${ARROW}Right`;
  435. const ARROW_UP = `${ARROW}Up`;
  436. const ARROW_DOWN = `${ARROW}Down`;
  437. const LTR = "ltr";
  438. const RTL = "rtl";
  439. const TTB = "ttb";
  440. const ORIENTATION_MAP = {
  441. width: ["height"],
  442. left: ["top", "right"],
  443. right: ["bottom", "left"],
  444. x: ["y"],
  445. X: ["Y"],
  446. Y: ["X"],
  447. ArrowLeft: [ARROW_UP, ARROW_RIGHT],
  448. ArrowRight: [ARROW_DOWN, ARROW_LEFT]
  449. };
  450. function Direction(Splide2, Components2, options) {
  451. function resolve(prop, axisOnly, direction) {
  452. direction = direction || options.direction;
  453. const index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
  454. return ORIENTATION_MAP[prop] && ORIENTATION_MAP[prop][index] || prop.replace(/width|left|right/i, (match, offset) => {
  455. const replacement = ORIENTATION_MAP[match.toLowerCase()][index] || match;
  456. return offset > 0 ? replacement.charAt(0).toUpperCase() + replacement.slice(1) : replacement;
  457. });
  458. }
  459. function orient(value) {
  460. return value * (options.direction === RTL ? 1 : -1);
  461. }
  462. return {
  463. resolve,
  464. orient
  465. };
  466. }
  467. const ROLE = "role";
  468. const TAB_INDEX = "tabindex";
  469. const DISABLED = "disabled";
  470. const ARIA_PREFIX = "aria-";
  471. const ARIA_CONTROLS = `${ARIA_PREFIX}controls`;
  472. const ARIA_CURRENT = `${ARIA_PREFIX}current`;
  473. const ARIA_SELECTED = `${ARIA_PREFIX}selected`;
  474. const ARIA_LABEL = `${ARIA_PREFIX}label`;
  475. const ARIA_LABELLEDBY = `${ARIA_PREFIX}labelledby`;
  476. const ARIA_HIDDEN = `${ARIA_PREFIX}hidden`;
  477. const ARIA_ORIENTATION = `${ARIA_PREFIX}orientation`;
  478. const ARIA_ROLEDESCRIPTION = `${ARIA_PREFIX}roledescription`;
  479. const ARIA_LIVE = `${ARIA_PREFIX}live`;
  480. const ARIA_BUSY = `${ARIA_PREFIX}busy`;
  481. const ARIA_ATOMIC = `${ARIA_PREFIX}atomic`;
  482. const ALL_ATTRIBUTES = [
  483. ROLE,
  484. TAB_INDEX,
  485. DISABLED,
  486. ARIA_CONTROLS,
  487. ARIA_CURRENT,
  488. ARIA_LABEL,
  489. ARIA_LABELLEDBY,
  490. ARIA_HIDDEN,
  491. ARIA_ORIENTATION,
  492. ARIA_ROLEDESCRIPTION
  493. ];
  494. const PROJECT_CODE = "splide";
  495. const DATA_ATTRIBUTE = `data-${PROJECT_CODE}`;
  496. const CLASS_PREFIX = `${PROJECT_CODE}__`;
  497. const STATUS_CLASS_PREFIX = "is-";
  498. const CLASS_ROOT = PROJECT_CODE;
  499. const CLASS_TRACK = `${CLASS_PREFIX}track`;
  500. const CLASS_LIST = `${CLASS_PREFIX}list`;
  501. const CLASS_SLIDE = `${CLASS_PREFIX}slide`;
  502. const CLASS_CLONE = `${CLASS_SLIDE}--clone`;
  503. const CLASS_CONTAINER = `${CLASS_SLIDE}__container`;
  504. const CLASS_ARROWS = `${CLASS_PREFIX}arrows`;
  505. const CLASS_ARROW = `${CLASS_PREFIX}arrow`;
  506. const CLASS_ARROW_PREV = `${CLASS_ARROW}--prev`;
  507. const CLASS_ARROW_NEXT = `${CLASS_ARROW}--next`;
  508. const CLASS_PAGINATION = `${CLASS_PREFIX}pagination`;
  509. const CLASS_PAGINATION_PAGE = `${CLASS_PAGINATION}__page`;
  510. const CLASS_PROGRESS = `${CLASS_PREFIX}progress`;
  511. const CLASS_PROGRESS_BAR = `${CLASS_PROGRESS}__bar`;
  512. const CLASS_TOGGLE = `${CLASS_PREFIX}toggle`;
  513. const CLASS_TOGGLE_PLAY = `${CLASS_TOGGLE}__play`;
  514. const CLASS_TOGGLE_PAUSE = `${CLASS_TOGGLE}__pause`;
  515. const CLASS_SPINNER = `${CLASS_PREFIX}spinner`;
  516. const CLASS_SR = `${CLASS_PREFIX}sr`;
  517. const CLASS_INITIALIZED = `${STATUS_CLASS_PREFIX}initialized`;
  518. const CLASS_ACTIVE = `${STATUS_CLASS_PREFIX}active`;
  519. const CLASS_PREV = `${STATUS_CLASS_PREFIX}prev`;
  520. const CLASS_NEXT = `${STATUS_CLASS_PREFIX}next`;
  521. const CLASS_VISIBLE = `${STATUS_CLASS_PREFIX}visible`;
  522. const CLASS_LOADING = `${STATUS_CLASS_PREFIX}loading`;
  523. const CLASS_FOCUS_IN = `${STATUS_CLASS_PREFIX}focus-in`;
  524. const CLASS_OVERFLOW = `${STATUS_CLASS_PREFIX}overflow`;
  525. const STATUS_CLASSES = [
  526. CLASS_ACTIVE,
  527. CLASS_VISIBLE,
  528. CLASS_PREV,
  529. CLASS_NEXT,
  530. CLASS_LOADING,
  531. CLASS_FOCUS_IN,
  532. CLASS_OVERFLOW
  533. ];
  534. const CLASSES = {
  535. slide: CLASS_SLIDE,
  536. clone: CLASS_CLONE,
  537. arrows: CLASS_ARROWS,
  538. arrow: CLASS_ARROW,
  539. prev: CLASS_ARROW_PREV,
  540. next: CLASS_ARROW_NEXT,
  541. pagination: CLASS_PAGINATION,
  542. page: CLASS_PAGINATION_PAGE,
  543. spinner: CLASS_SPINNER
  544. };
  545. function assert(condition, message) {
  546. if (!condition) {
  547. throw new Error(`[${PROJECT_CODE}] ${message || ""}`);
  548. }
  549. }
  550. const FRICTION = 5;
  551. const LOG_INTERVAL = 200;
  552. const POINTER_DOWN_EVENTS = "touchstart mousedown";
  553. const POINTER_MOVE_EVENTS = "touchmove mousemove";
  554. const POINTER_UP_EVENTS = "touchend touchcancel mouseup click";
  555. function Elements(Splide2, Components2, options, event) {
  556. const { on, bind } = event;
  557. const { root } = Splide2;
  558. const { i18n } = options;
  559. const elements = {};
  560. const slides = [];
  561. let rootClasses = [];
  562. let trackClasses = [];
  563. let track;
  564. let list;
  565. let isUsingKey;
  566. function setup() {
  567. collect();
  568. init();
  569. update();
  570. }
  571. function mount() {
  572. on(EVENT_REFRESH, destroy);
  573. on(EVENT_REFRESH, setup);
  574. on(EVENT_UPDATED, update);
  575. bind(document, `${POINTER_DOWN_EVENTS} keydown`, (e) => {
  576. isUsingKey = e.type === "keydown";
  577. }, { capture: true });
  578. bind(root, "focusin", () => {
  579. I(root, CLASS_FOCUS_IN, !!isUsingKey);
  580. });
  581. }
  582. function destroy(completely) {
  583. const attrs = ALL_ATTRIBUTES.concat("style");
  584. N(slides);
  585. Pn(root, rootClasses);
  586. Pn(track, trackClasses);
  587. U([track, list], attrs);
  588. U(root, completely ? attrs : ["style", ARIA_ROLEDESCRIPTION]);
  589. }
  590. function update() {
  591. Pn(root, rootClasses);
  592. Pn(track, trackClasses);
  593. rootClasses = getClasses(CLASS_ROOT);
  594. trackClasses = getClasses(CLASS_TRACK);
  595. J(root, rootClasses);
  596. J(track, trackClasses);
  597. M(root, ARIA_LABEL, options.label);
  598. M(root, ARIA_LABELLEDBY, options.labelledby);
  599. }
  600. function collect() {
  601. track = find(CLASS_TRACK);
  602. list = Y(track, `.${CLASS_LIST}`);
  603. assert(track && list, "A track/list element is missing.");
  604. pn(slides, X(list, `.${CLASS_SLIDE}:not(.${CLASS_CLONE})`));
  605. v(elements, {
  606. root,
  607. track,
  608. list,
  609. slides,
  610. arrows: find(CLASS_ARROWS),
  611. pagination: find(CLASS_PAGINATION),
  612. prev: find(CLASS_ARROW_PREV),
  613. next: find(CLASS_ARROW_NEXT),
  614. bar: find(CLASS_PROGRESS_BAR),
  615. toggle: find(CLASS_TOGGLE)
  616. });
  617. }
  618. function init() {
  619. const id = root.id || zn(PROJECT_CODE);
  620. const role = options.role;
  621. root.id = id;
  622. track.id = track.id || `${id}-track`;
  623. list.id = list.id || `${id}-list`;
  624. if (!wn(root, ROLE) && root.tagName !== "SECTION" && role) {
  625. M(root, ROLE, role);
  626. }
  627. M(root, ARIA_ROLEDESCRIPTION, i18n.carousel);
  628. M(list, ROLE, "presentation");
  629. }
  630. function find(className) {
  631. const elm = On(root, `.${className}`);
  632. return elm && En(elm, `.${CLASS_ROOT}`) === root ? elm : void 0;
  633. }
  634. function getClasses(base) {
  635. return [
  636. `${base}--${options.type}`,
  637. `${base}--${options.direction}`,
  638. options.drag && `${base}--draggable`,
  639. options.isNavigation && `${base}--nav`,
  640. base === CLASS_ROOT && CLASS_ACTIVE
  641. ];
  642. }
  643. return v(elements, {
  644. setup,
  645. mount,
  646. destroy
  647. });
  648. }
  649. const SLIDE = "slide";
  650. const LOOP = "loop";
  651. const FADE = "fade";
  652. function Slide$1(Splide2, index, slideIndex, slide) {
  653. const event = Splide2.event.create();
  654. const { on, emit, bind } = event;
  655. const { Components, root, options } = Splide2;
  656. const { isNavigation, updateOnMove, i18n, pagination, slideFocus } = options;
  657. const { resolve } = Components.Direction;
  658. const styles = wn(slide, "style");
  659. const label = wn(slide, ARIA_LABEL);
  660. const isClone = slideIndex > -1;
  661. const container = Y(slide, `.${CLASS_CONTAINER}`);
  662. let destroyed;
  663. function mount() {
  664. if (!isClone) {
  665. slide.id = `${root.id}-slide${cn(index + 1)}`;
  666. M(slide, ROLE, pagination ? "tabpanel" : "group");
  667. M(slide, ARIA_ROLEDESCRIPTION, i18n.slide);
  668. M(slide, ARIA_LABEL, label || Kn(i18n.slideLabel, [index + 1, Splide2.length]));
  669. }
  670. listen();
  671. }
  672. function listen() {
  673. bind(slide, "click", a(emit, EVENT_CLICK, self));
  674. bind(slide, "keydown", a(emit, EVENT_SLIDE_KEYDOWN, self));
  675. on([EVENT_MOVED, EVENT_SHIFTED, EVENT_SCROLLED], update);
  676. on(EVENT_NAVIGATION_MOUNTED, initNavigation);
  677. if (updateOnMove) {
  678. on(EVENT_MOVE, onMove);
  679. }
  680. }
  681. function destroy() {
  682. destroyed = true;
  683. event.destroy();
  684. Pn(slide, STATUS_CLASSES);
  685. U(slide, ALL_ATTRIBUTES);
  686. M(slide, "style", styles);
  687. M(slide, ARIA_LABEL, label || "");
  688. }
  689. function initNavigation() {
  690. const controls = Splide2.splides.map((target) => {
  691. const Slide2 = target.splide.Components.Slides.getAt(index);
  692. return Slide2 ? Slide2.slide.id : "";
  693. }).join(" ");
  694. M(slide, ARIA_LABEL, Kn(i18n.slideX, (isClone ? slideIndex : index) + 1));
  695. M(slide, ARIA_CONTROLS, controls);
  696. M(slide, ROLE, slideFocus ? "button" : "");
  697. slideFocus && U(slide, ARIA_ROLEDESCRIPTION);
  698. }
  699. function onMove() {
  700. if (!destroyed) {
  701. update();
  702. }
  703. }
  704. function update() {
  705. if (!destroyed) {
  706. const { index: curr } = Splide2;
  707. updateActivity();
  708. updateVisibility();
  709. I(slide, CLASS_PREV, index === curr - 1);
  710. I(slide, CLASS_NEXT, index === curr + 1);
  711. }
  712. }
  713. function updateActivity() {
  714. const active = isActive();
  715. if (active !== Cn(slide, CLASS_ACTIVE)) {
  716. I(slide, CLASS_ACTIVE, active);
  717. M(slide, ARIA_CURRENT, isNavigation && active || "");
  718. emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, self);
  719. }
  720. }
  721. function updateVisibility() {
  722. const visible = isVisible();
  723. const hidden = !visible && (!isActive() || isClone);
  724. if (!Splide2.state.is([MOVING, SCROLLING])) {
  725. M(slide, ARIA_HIDDEN, hidden || "");
  726. }
  727. M(Tn(slide, options.focusableNodes || ""), TAB_INDEX, hidden ? -1 : "");
  728. if (slideFocus) {
  729. M(slide, TAB_INDEX, hidden ? -1 : 0);
  730. }
  731. if (visible !== Cn(slide, CLASS_VISIBLE)) {
  732. I(slide, CLASS_VISIBLE, visible);
  733. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
  734. }
  735. if (!visible && document.activeElement === slide) {
  736. const Slide2 = Components.Slides.getAt(Splide2.index);
  737. Slide2 && $n(Slide2.slide);
  738. }
  739. }
  740. function style(prop, value, useContainer) {
  741. nn(useContainer && container || slide, prop, value);
  742. }
  743. function isActive() {
  744. const { index: curr } = Splide2;
  745. return curr === index || options.cloneStatus && curr === slideIndex;
  746. }
  747. function isVisible() {
  748. if (Splide2.is(FADE)) {
  749. return isActive();
  750. }
  751. const trackRect = tn(Components.Elements.track);
  752. const slideRect = tn(slide);
  753. const left = resolve("left", true);
  754. const right = resolve("right", true);
  755. return Dn(trackRect[left]) <= Fn(slideRect[left]) && Dn(slideRect[right]) <= Fn(trackRect[right]);
  756. }
  757. function isWithin(from, distance) {
  758. let diff = un(from - index);
  759. if (!isClone && (options.rewind || Splide2.is(LOOP))) {
  760. diff = E(diff, Splide2.length - diff);
  761. }
  762. return diff <= distance;
  763. }
  764. function position() {
  765. return slide[resolve("offsetLeft")];
  766. }
  767. function size() {
  768. return tn(slide)[resolve("width")];
  769. }
  770. const self = {
  771. index,
  772. slideIndex,
  773. slide,
  774. container,
  775. isClone,
  776. mount,
  777. destroy,
  778. update,
  779. position,
  780. size,
  781. style,
  782. isWithin
  783. };
  784. return self;
  785. }
  786. function Slides(Splide2, Components2, options, event) {
  787. const { on, emit, bind } = event;
  788. const { slides, list } = Components2.Elements;
  789. const Slides2 = [];
  790. function mount() {
  791. init();
  792. on(EVENT_REFRESH, destroy);
  793. on(EVENT_REFRESH, init);
  794. }
  795. function init() {
  796. slides.forEach((slide, index) => {
  797. register(slide, index, -1);
  798. });
  799. }
  800. function destroy() {
  801. forEach((Slide2) => {
  802. Slide2.destroy();
  803. });
  804. N(Slides2);
  805. }
  806. function update() {
  807. forEach((Slide2) => {
  808. Slide2.update();
  809. });
  810. }
  811. function register(slide, index, slideIndex) {
  812. const object = Slide$1(Splide2, index, slideIndex, slide);
  813. object.mount();
  814. Slides2.push(object);
  815. Slides2.sort((Slide1, Slide2) => Slide1.index - Slide2.index);
  816. }
  817. function get(excludeClones) {
  818. return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
  819. }
  820. function getIn(page) {
  821. const { Controller } = Components2;
  822. const index = Controller.toIndex(page);
  823. const max = Controller.hasFocus() ? 1 : options.perPage;
  824. return filter((Slide2) => _n(Slide2.index, index, index + max - 1));
  825. }
  826. function getAt(index) {
  827. return filter(index)[0];
  828. }
  829. function add(items, index) {
  830. d(items, (slide) => {
  831. if (p(slide)) {
  832. slide = qn(slide);
  833. }
  834. if (x(slide)) {
  835. const ref = slides[index];
  836. ref ? yn(slide, ref) : Q(list, slide);
  837. J(slide, options.classes.slide);
  838. observeImages(slide, a(emit, EVENT_RESIZE));
  839. }
  840. });
  841. emit(EVENT_REFRESH);
  842. }
  843. function remove(matcher) {
  844. en(filter(matcher).map((Slide2) => Slide2.slide));
  845. emit(EVENT_REFRESH);
  846. }
  847. function forEach(iteratee, excludeClones) {
  848. get(excludeClones).forEach(iteratee);
  849. }
  850. function filter(matcher) {
  851. return Slides2.filter(
  852. ln(matcher) ? matcher : (Slide2) => p(matcher) ? W(Slide2.slide, matcher) : G(q(matcher), Slide2.index)
  853. );
  854. }
  855. function style(prop, value, useContainer) {
  856. forEach((Slide2) => {
  857. Slide2.style(prop, value, useContainer);
  858. });
  859. }
  860. function observeImages(elm, callback) {
  861. const images = Tn(elm, "img");
  862. let { length } = images;
  863. if (length) {
  864. images.forEach((img) => {
  865. bind(img, "load error", () => {
  866. if (!--length) {
  867. callback();
  868. }
  869. });
  870. });
  871. } else {
  872. callback();
  873. }
  874. }
  875. function getLength(excludeClones) {
  876. return excludeClones ? slides.length : Slides2.length;
  877. }
  878. function isEnough() {
  879. return Slides2.length > options.perPage;
  880. }
  881. return {
  882. mount,
  883. destroy,
  884. update,
  885. register,
  886. get,
  887. getIn,
  888. getAt,
  889. add,
  890. remove,
  891. forEach,
  892. filter,
  893. style,
  894. getLength,
  895. isEnough
  896. };
  897. }
  898. function Layout(Splide2, Components2, options, event) {
  899. const { on, bind, emit } = event;
  900. const { Slides } = Components2;
  901. const { resolve } = Components2.Direction;
  902. const { root, track, list } = Components2.Elements;
  903. const { getAt, style: styleSlides } = Slides;
  904. let vertical;
  905. let rootRect;
  906. let overflow;
  907. function mount() {
  908. init();
  909. bind(window, "resize load", Vn(a(emit, EVENT_RESIZE)));
  910. on([EVENT_UPDATED, EVENT_REFRESH], init);
  911. on(EVENT_RESIZE, resize);
  912. }
  913. function init() {
  914. vertical = options.direction === TTB;
  915. nn(root, "maxWidth", Nn(options.width));
  916. nn(track, resolve("paddingLeft"), cssPadding(false));
  917. nn(track, resolve("paddingRight"), cssPadding(true));
  918. resize(true);
  919. }
  920. function resize(force) {
  921. const newRect = tn(root);
  922. if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  923. nn(track, "height", cssTrackHeight());
  924. styleSlides(resolve("marginRight"), Nn(options.gap));
  925. styleSlides("width", cssSlideWidth());
  926. styleSlides("height", cssSlideHeight(), true);
  927. rootRect = newRect;
  928. emit(EVENT_RESIZED);
  929. if (overflow !== (overflow = isOverflow())) {
  930. I(root, CLASS_OVERFLOW, overflow);
  931. emit(EVENT_OVERFLOW, overflow);
  932. }
  933. }
  934. }
  935. function cssPadding(right) {
  936. const { padding } = options;
  937. const prop = resolve(right ? "right" : "left");
  938. return padding && Nn(padding[prop] || (y(padding) ? 0 : padding)) || "0px";
  939. }
  940. function cssTrackHeight() {
  941. let height = "";
  942. if (vertical) {
  943. height = cssHeight();
  944. assert(height, "height or heightRatio is missing.");
  945. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  946. }
  947. return height;
  948. }
  949. function cssHeight() {
  950. return Nn(options.height || tn(list).width * options.heightRatio);
  951. }
  952. function cssSlideWidth() {
  953. return options.autoWidth ? null : Nn(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  954. }
  955. function cssSlideHeight() {
  956. return Nn(options.fixedHeight) || (vertical ? options.autoHeight ? null : cssSlideSize() : cssHeight());
  957. }
  958. function cssSlideSize() {
  959. const gap = Nn(options.gap);
  960. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  961. }
  962. function listSize() {
  963. return tn(list)[resolve("width")];
  964. }
  965. function slideSize(index = 0, withoutGap) {
  966. const Slide = getAt(index);
  967. return (Slide ? Slide.size() : 0) + (withoutGap ? 0 : getGap());
  968. }
  969. function totalSize(index, withoutGap) {
  970. const Slide = getAt(index);
  971. return Slide ? Slide.position() + Slide.size() + (withoutGap ? 0 : getGap()) : 0;
  972. }
  973. function sliderSize(withoutGap) {
  974. return totalSize(Splide2.length - 1) - totalSize(0) + slideSize(0, withoutGap);
  975. }
  976. function getGap() {
  977. const Slide = getAt(0);
  978. return Slide && parseFloat(nn(Slide.slide, resolve("marginRight"))) || 0;
  979. }
  980. function getPadding(right) {
  981. return list[`offset${right ? "Right" : "Left"}`];
  982. }
  983. function isOverflow() {
  984. return Splide2.is(FADE) || sliderSize(true) > listSize();
  985. }
  986. return {
  987. mount,
  988. resize,
  989. listSize,
  990. slideSize,
  991. sliderSize,
  992. totalSize,
  993. getPadding,
  994. isOverflow
  995. };
  996. }
  997. const MULTIPLIER = 2;
  998. function Clones(Splide2, Components2, options, event) {
  999. const { on } = event;
  1000. const { Elements, Slides } = Components2;
  1001. const { resolve } = Components2.Direction;
  1002. const clones = [];
  1003. let cloneCount;
  1004. function mount() {
  1005. on(EVENT_REFRESH, remount);
  1006. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1007. if (cloneCount = computeCloneCount()) {
  1008. generate(cloneCount);
  1009. Components2.Layout.resize(true);
  1010. }
  1011. }
  1012. function remount() {
  1013. destroy();
  1014. mount();
  1015. }
  1016. function destroy() {
  1017. en(clones);
  1018. N(clones);
  1019. event.destroy();
  1020. }
  1021. function observe() {
  1022. const count = computeCloneCount();
  1023. if (cloneCount !== count) {
  1024. if (cloneCount < count || !count) {
  1025. event.emit(EVENT_REFRESH);
  1026. }
  1027. }
  1028. }
  1029. function generate(count) {
  1030. const slides = Slides.get().slice();
  1031. const { length } = slides;
  1032. if (length) {
  1033. while (slides.length < count) {
  1034. pn(slides, slides);
  1035. }
  1036. pn(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  1037. const isHead = index < count;
  1038. const clone = cloneDeep(Slide.slide, index);
  1039. isHead ? yn(clone, slides[0].slide) : Q(Elements.list, clone);
  1040. pn(clones, clone);
  1041. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1042. });
  1043. }
  1044. }
  1045. function cloneDeep(elm, index) {
  1046. const clone = elm.cloneNode(true);
  1047. J(clone, options.classes.clone);
  1048. clone.id = `${Splide2.root.id}-clone${cn(index + 1)}`;
  1049. return clone;
  1050. }
  1051. function computeCloneCount() {
  1052. let { clones: clones2 } = options;
  1053. if (!Splide2.is(LOOP)) {
  1054. clones2 = 0;
  1055. } else if (Z(clones2)) {
  1056. const fixedSize = options[resolve("fixedWidth")] && Components2.Layout.slideSize(0);
  1057. const fixedCount = fixedSize && Fn(tn(Elements.track)[resolve("width")] / fixedSize);
  1058. clones2 = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage * MULTIPLIER;
  1059. }
  1060. return clones2;
  1061. }
  1062. return {
  1063. mount,
  1064. destroy
  1065. };
  1066. }
  1067. function Move(Splide2, Components2, options, event) {
  1068. const { on, emit } = event;
  1069. const { set } = Splide2.state;
  1070. const { slideSize, getPadding, listSize, sliderSize } = Components2.Layout;
  1071. const { resolve, orient } = Components2.Direction;
  1072. const { list, track } = Components2.Elements;
  1073. let Transition;
  1074. function mount() {
  1075. Transition = Components2.Transition;
  1076. on([EVENT_RESIZED], reposition);
  1077. }
  1078. function reposition() {
  1079. if (!Components2.Controller.isBusy()) {
  1080. Components2.Scroll.cancel();
  1081. jump(Splide2.index);
  1082. Components2.Slides.update();
  1083. }
  1084. }
  1085. function move(dest, index, prev, callback) {
  1086. if (dest !== index && canShift(dest > prev)) {
  1087. cancel();
  1088. translate(shift(getPosition(), dest > prev), true);
  1089. }
  1090. set(MOVING);
  1091. emit(EVENT_MOVE, index, prev, dest);
  1092. Transition.start(index, () => {
  1093. set(IDLE);
  1094. emit(EVENT_MOVED, index, prev, dest);
  1095. callback && callback();
  1096. });
  1097. }
  1098. function jump(index) {
  1099. translate(toPosition(index, true));
  1100. }
  1101. function translate(position, preventLoop) {
  1102. if (!Splide2.is(FADE)) {
  1103. const destination = preventLoop ? position : loop(position);
  1104. nn(list, "transform", `translate${resolve("X")}(${destination}px)`);
  1105. position !== destination && emit(EVENT_SHIFTED);
  1106. }
  1107. }
  1108. function loop(position) {
  1109. if (Splide2.is(LOOP)) {
  1110. const index = toIndex(position);
  1111. const exceededMax = index > Components2.Controller.getEnd();
  1112. const exceededMin = index < 0;
  1113. if (exceededMin || exceededMax) {
  1114. position = shift(position, exceededMax);
  1115. }
  1116. }
  1117. return position;
  1118. }
  1119. function shift(position, backwards) {
  1120. const excess = position - getLimit(backwards);
  1121. const size = sliderSize();
  1122. position -= orient(size * (Fn(un(excess) / size) || 1)) * (backwards ? 1 : -1);
  1123. return position;
  1124. }
  1125. function cancel() {
  1126. translate(getPosition(), true);
  1127. Transition.cancel();
  1128. }
  1129. function toIndex(position) {
  1130. const Slides = Components2.Slides.get();
  1131. let index = 0;
  1132. let minDistance = Infinity;
  1133. for (let i = 0; i < Slides.length; i++) {
  1134. const slideIndex = Slides[i].index;
  1135. const distance = un(toPosition(slideIndex, true) - position);
  1136. if (distance <= minDistance) {
  1137. minDistance = distance;
  1138. index = slideIndex;
  1139. } else {
  1140. break;
  1141. }
  1142. }
  1143. return index;
  1144. }
  1145. function toPosition(index, trimming) {
  1146. const Slide = Components2.Slides.getAt(index);
  1147. const position = Slide ? orient(Slide.position() - offset(index)) : 0;
  1148. return trimming ? trim(position) : position;
  1149. }
  1150. function getPosition() {
  1151. const left = resolve("left");
  1152. return tn(list)[left] - tn(track)[left] + orient(getPadding(false));
  1153. }
  1154. function trim(position) {
  1155. if (options.trimSpace && Splide2.is(SLIDE)) {
  1156. position = bn(position, 0, orient(sliderSize(true) - listSize()));
  1157. }
  1158. return position;
  1159. }
  1160. function offset(index) {
  1161. const { focus } = options;
  1162. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1163. }
  1164. function getLimit(max) {
  1165. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1166. }
  1167. function canShift(backwards) {
  1168. const shifted = orient(shift(getPosition(), backwards));
  1169. return backwards ? shifted >= 0 : shifted <= list[resolve("scrollWidth")] - tn(track)[resolve("width")];
  1170. }
  1171. function exceededLimit(max, position) {
  1172. position = Z(position) ? getPosition() : position;
  1173. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1174. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1175. return exceededMin || exceededMax;
  1176. }
  1177. return {
  1178. mount,
  1179. move,
  1180. jump,
  1181. translate,
  1182. shift,
  1183. cancel,
  1184. toIndex,
  1185. toPosition,
  1186. getPosition,
  1187. getLimit,
  1188. exceededLimit,
  1189. reposition
  1190. };
  1191. }
  1192. function Controller(Splide2, Components2, options, event) {
  1193. const { on, emit } = event;
  1194. const { Move } = Components2;
  1195. const { getPosition, getLimit, toPosition } = Move;
  1196. const { isEnough, getLength } = Components2.Slides;
  1197. const { omitEnd } = options;
  1198. const isLoop = Splide2.is(LOOP);
  1199. const isSlide = Splide2.is(SLIDE);
  1200. const getNext = a(getAdjacent, false);
  1201. const getPrev = a(getAdjacent, true);
  1202. let currIndex = options.start || 0;
  1203. let endIndex;
  1204. let prevIndex = currIndex;
  1205. let slideCount;
  1206. let perMove;
  1207. let perPage;
  1208. function mount() {
  1209. init();
  1210. on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], init);
  1211. on(EVENT_RESIZED, onResized);
  1212. }
  1213. function init() {
  1214. slideCount = getLength(true);
  1215. perMove = options.perMove;
  1216. perPage = options.perPage;
  1217. endIndex = getEnd();
  1218. const index = bn(currIndex, 0, omitEnd ? endIndex : slideCount - 1);
  1219. if (index !== currIndex) {
  1220. currIndex = index;
  1221. Move.reposition();
  1222. }
  1223. }
  1224. function onResized() {
  1225. if (endIndex !== getEnd()) {
  1226. emit(EVENT_END_INDEX_CHANGED);
  1227. }
  1228. }
  1229. function go(control, allowSameIndex, callback) {
  1230. if (!isBusy()) {
  1231. const dest = parse(control);
  1232. const index = loop(dest);
  1233. if (index > -1 && (allowSameIndex || index !== currIndex)) {
  1234. setIndex(index);
  1235. Move.move(dest, index, prevIndex, callback);
  1236. }
  1237. }
  1238. }
  1239. function scroll(destination, duration, snap, callback) {
  1240. Components2.Scroll.scroll(destination, duration, snap, () => {
  1241. const index = loop(Move.toIndex(getPosition()));
  1242. setIndex(omitEnd ? E(index, endIndex) : index);
  1243. callback && callback();
  1244. });
  1245. }
  1246. function parse(control) {
  1247. let index = currIndex;
  1248. if (p(control)) {
  1249. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1250. if (indicator === "+" || indicator === "-") {
  1251. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
  1252. } else if (indicator === ">") {
  1253. index = number ? toIndex(+number) : getNext(true);
  1254. } else if (indicator === "<") {
  1255. index = getPrev(true);
  1256. }
  1257. } else {
  1258. index = isLoop ? control : bn(control, 0, endIndex);
  1259. }
  1260. return index;
  1261. }
  1262. function getAdjacent(prev, destination) {
  1263. const number = perMove || (hasFocus() ? 1 : perPage);
  1264. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex, !(perMove || hasFocus()));
  1265. if (dest === -1 && isSlide) {
  1266. if (!Mn(getPosition(), getLimit(!prev), 1)) {
  1267. return prev ? 0 : endIndex;
  1268. }
  1269. }
  1270. return destination ? dest : loop(dest);
  1271. }
  1272. function computeDestIndex(dest, from, snapPage) {
  1273. if (isEnough() || hasFocus()) {
  1274. const index = computeMovableDestIndex(dest);
  1275. if (index !== dest) {
  1276. from = dest;
  1277. dest = index;
  1278. snapPage = false;
  1279. }
  1280. if (dest < 0 || dest > endIndex) {
  1281. if (!perMove && (_n(0, dest, from, true) || _n(endIndex, from, dest, true))) {
  1282. dest = toIndex(toPage(dest));
  1283. } else {
  1284. if (isLoop) {
  1285. dest = snapPage ? dest < 0 ? -(slideCount % perPage || perPage) : slideCount : dest;
  1286. } else if (options.rewind) {
  1287. dest = dest < 0 ? endIndex : 0;
  1288. } else {
  1289. dest = -1;
  1290. }
  1291. }
  1292. } else {
  1293. if (snapPage && dest !== from) {
  1294. dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
  1295. }
  1296. }
  1297. } else {
  1298. dest = -1;
  1299. }
  1300. return dest;
  1301. }
  1302. function computeMovableDestIndex(dest) {
  1303. if (isSlide && options.trimSpace === "move" && dest !== currIndex) {
  1304. const position = getPosition();
  1305. while (position === toPosition(dest, true) && _n(dest, 0, Splide2.length - 1, !options.rewind)) {
  1306. dest < currIndex ? --dest : ++dest;
  1307. }
  1308. }
  1309. return dest;
  1310. }
  1311. function loop(index) {
  1312. return isLoop ? (index + slideCount) % slideCount || 0 : index;
  1313. }
  1314. function getEnd() {
  1315. let end = slideCount - (hasFocus() || isLoop && perMove ? 1 : perPage);
  1316. while (omitEnd && end-- > 0) {
  1317. if (toPosition(slideCount - 1, true) !== toPosition(end, true)) {
  1318. end++;
  1319. break;
  1320. }
  1321. }
  1322. return bn(end, 0, slideCount - 1);
  1323. }
  1324. function toIndex(page) {
  1325. return bn(hasFocus() ? page : perPage * page, 0, endIndex);
  1326. }
  1327. function toPage(index) {
  1328. return hasFocus() ? E(index, endIndex) : Dn((index >= endIndex ? slideCount - 1 : index) / perPage);
  1329. }
  1330. function toDest(destination) {
  1331. const closest = Move.toIndex(destination);
  1332. return isSlide ? bn(closest, 0, endIndex) : closest;
  1333. }
  1334. function setIndex(index) {
  1335. if (index !== currIndex) {
  1336. prevIndex = currIndex;
  1337. currIndex = index;
  1338. }
  1339. }
  1340. function getIndex(prev) {
  1341. return prev ? prevIndex : currIndex;
  1342. }
  1343. function hasFocus() {
  1344. return !Z(options.focus) || options.isNavigation;
  1345. }
  1346. function isBusy() {
  1347. return Splide2.state.is([MOVING, SCROLLING]) && !!options.waitForTransition;
  1348. }
  1349. return {
  1350. mount,
  1351. go,
  1352. scroll,
  1353. getNext,
  1354. getPrev,
  1355. getAdjacent,
  1356. getEnd,
  1357. setIndex,
  1358. getIndex,
  1359. toIndex,
  1360. toPage,
  1361. toDest,
  1362. hasFocus,
  1363. isBusy
  1364. };
  1365. }
  1366. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1367. 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";
  1368. const SIZE = 40;
  1369. function Arrows(Splide2, Components2, options, event) {
  1370. const { on, bind, emit } = event;
  1371. const { classes, i18n } = options;
  1372. const { Elements, Controller } = Components2;
  1373. const { arrows: placeholder, track } = Elements;
  1374. let wrapper = placeholder;
  1375. let prev = Elements.prev;
  1376. let next = Elements.next;
  1377. let created;
  1378. let wrapperClasses;
  1379. const arrows = {};
  1380. function mount() {
  1381. init();
  1382. on(EVENT_UPDATED, remount);
  1383. }
  1384. function remount() {
  1385. destroy();
  1386. mount();
  1387. }
  1388. function init() {
  1389. const enabled = options.arrows;
  1390. if (enabled && !(prev && next)) {
  1391. createArrows();
  1392. }
  1393. if (prev && next) {
  1394. v(arrows, { prev, next });
  1395. An(wrapper, enabled ? "" : "none");
  1396. J(wrapper, wrapperClasses = `${CLASS_ARROWS}--${options.direction}`);
  1397. if (enabled) {
  1398. listen();
  1399. update();
  1400. M([prev, next], ARIA_CONTROLS, track.id);
  1401. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1402. }
  1403. }
  1404. }
  1405. function destroy() {
  1406. event.destroy();
  1407. Pn(wrapper, wrapperClasses);
  1408. if (created) {
  1409. en(placeholder ? [prev, next] : wrapper);
  1410. prev = next = null;
  1411. } else {
  1412. U([prev, next], ALL_ATTRIBUTES);
  1413. }
  1414. }
  1415. function listen() {
  1416. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLLED, EVENT_END_INDEX_CHANGED], update);
  1417. bind(next, "click", a(go, ">"));
  1418. bind(prev, "click", a(go, "<"));
  1419. }
  1420. function go(control) {
  1421. Controller.go(control, true);
  1422. }
  1423. function createArrows() {
  1424. wrapper = placeholder || j("div", classes.arrows);
  1425. prev = createArrow(true);
  1426. next = createArrow(false);
  1427. created = true;
  1428. Q(wrapper, [prev, next]);
  1429. !placeholder && yn(wrapper, track);
  1430. }
  1431. function createArrow(prev2) {
  1432. 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}" />`;
  1433. return qn(arrow);
  1434. }
  1435. function update() {
  1436. if (prev && next) {
  1437. const index = Splide2.index;
  1438. const prevIndex = Controller.getPrev();
  1439. const nextIndex = Controller.getNext();
  1440. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1441. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1442. prev.disabled = prevIndex < 0;
  1443. next.disabled = nextIndex < 0;
  1444. M(prev, ARIA_LABEL, prevLabel);
  1445. M(next, ARIA_LABEL, nextLabel);
  1446. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1447. }
  1448. }
  1449. return {
  1450. arrows,
  1451. mount,
  1452. destroy,
  1453. update
  1454. };
  1455. }
  1456. const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
  1457. function Autoplay(Splide2, Components2, options, event) {
  1458. const { on, bind, emit } = event;
  1459. const interval = sn(options.interval, Splide2.go.bind(Splide2, ">"), onAnimationFrame);
  1460. const { isPaused } = interval;
  1461. const { Elements, Elements: { root, toggle } } = Components2;
  1462. const { autoplay } = options;
  1463. let hovered;
  1464. let focused;
  1465. let stopped = autoplay === "pause";
  1466. function mount() {
  1467. if (autoplay) {
  1468. listen();
  1469. toggle && M(toggle, ARIA_CONTROLS, Elements.track.id);
  1470. stopped || play();
  1471. update();
  1472. }
  1473. }
  1474. function listen() {
  1475. if (options.pauseOnHover) {
  1476. bind(root, "mouseenter mouseleave", (e) => {
  1477. hovered = e.type === "mouseenter";
  1478. autoToggle();
  1479. });
  1480. }
  1481. if (options.pauseOnFocus) {
  1482. bind(root, "focusin focusout", (e) => {
  1483. focused = e.type === "focusin";
  1484. autoToggle();
  1485. });
  1486. }
  1487. if (toggle) {
  1488. bind(toggle, "click", () => {
  1489. stopped ? play() : pause(true);
  1490. });
  1491. }
  1492. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1493. on(EVENT_MOVE, onMove);
  1494. }
  1495. function play() {
  1496. if (isPaused() && Components2.Slides.isEnough()) {
  1497. interval.start(!options.resetProgress);
  1498. focused = hovered = stopped = false;
  1499. update();
  1500. emit(EVENT_AUTOPLAY_PLAY);
  1501. }
  1502. }
  1503. function pause(stop = true) {
  1504. stopped = !!stop;
  1505. update();
  1506. if (!isPaused()) {
  1507. interval.pause();
  1508. emit(EVENT_AUTOPLAY_PAUSE);
  1509. }
  1510. }
  1511. function autoToggle() {
  1512. if (!stopped) {
  1513. hovered || focused ? pause(false) : play();
  1514. }
  1515. }
  1516. function update() {
  1517. if (toggle) {
  1518. I(toggle, CLASS_ACTIVE, !stopped);
  1519. M(toggle, ARIA_LABEL, options.i18n[stopped ? "play" : "pause"]);
  1520. }
  1521. }
  1522. function onAnimationFrame(rate) {
  1523. const { bar } = Elements;
  1524. bar && nn(bar, "width", `${rate * 100}%`);
  1525. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1526. }
  1527. function onMove(index) {
  1528. const Slide = Components2.Slides.getAt(index);
  1529. interval.set(Slide && +wn(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1530. }
  1531. return {
  1532. mount,
  1533. destroy: interval.cancel,
  1534. play,
  1535. pause,
  1536. isPaused
  1537. };
  1538. }
  1539. function Cover(Splide2, Components2, options, event) {
  1540. const { on } = event;
  1541. function mount() {
  1542. if (options.cover) {
  1543. on(EVENT_LAZYLOAD_LOADED, a(toggle, true));
  1544. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], a(cover, true));
  1545. }
  1546. }
  1547. function cover(cover2) {
  1548. Components2.Slides.forEach((Slide) => {
  1549. const img = Y(Slide.container || Slide.slide, "img");
  1550. if (img && img.src) {
  1551. toggle(cover2, img, Slide);
  1552. }
  1553. });
  1554. }
  1555. function toggle(cover2, img, Slide) {
  1556. Slide.style("background", cover2 ? `center/cover no-repeat url("${img.src}")` : "", true);
  1557. An(img, cover2 ? "none" : "");
  1558. }
  1559. return {
  1560. mount,
  1561. destroy: a(cover, false)
  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 noDistance = Mn(from, destination, 1);
  1591. friction = 1;
  1592. duration = noDistance ? 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 }, Media: { 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.Media.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 SR_REMOVAL_DELAY = 90;
  2136. function Live(Splide2, Components2, options, event) {
  2137. const { on } = event;
  2138. const { track } = Components2.Elements;
  2139. const enabled = options.live && !options.isNavigation;
  2140. const sr = j("span", CLASS_SR);
  2141. const interval = sn(SR_REMOVAL_DELAY, a(toggle, false));
  2142. function mount() {
  2143. if (enabled) {
  2144. disable(!Components2.Autoplay.isPaused());
  2145. M(track, ARIA_ATOMIC, true);
  2146. sr.textContent = "\u2026";
  2147. on(EVENT_AUTOPLAY_PLAY, a(disable, true));
  2148. on(EVENT_AUTOPLAY_PAUSE, a(disable, false));
  2149. on([EVENT_MOVED, EVENT_SCROLLED], a(toggle, true));
  2150. }
  2151. }
  2152. function toggle(active) {
  2153. M(track, ARIA_BUSY, active);
  2154. if (active) {
  2155. Q(track, sr);
  2156. interval.start();
  2157. } else {
  2158. en(sr);
  2159. interval.cancel();
  2160. }
  2161. }
  2162. function destroy() {
  2163. U(track, [ARIA_LIVE, ARIA_ATOMIC, ARIA_BUSY]);
  2164. en(sr);
  2165. }
  2166. function disable(disabled) {
  2167. if (enabled) {
  2168. M(track, ARIA_LIVE, disabled ? "off" : "polite");
  2169. }
  2170. }
  2171. return {
  2172. mount,
  2173. disable,
  2174. destroy
  2175. };
  2176. }
  2177. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2178. __proto__: null,
  2179. Media: Media,
  2180. Direction: Direction,
  2181. Elements: Elements,
  2182. Slides: Slides,
  2183. Layout: Layout,
  2184. Clones: Clones,
  2185. Move: Move,
  2186. Controller: Controller,
  2187. Arrows: Arrows,
  2188. Autoplay: Autoplay,
  2189. Cover: Cover,
  2190. Scroll: Scroll,
  2191. Drag: Drag,
  2192. Keyboard: Keyboard,
  2193. LazyLoad: LazyLoad,
  2194. Pagination: Pagination,
  2195. Sync: Sync,
  2196. Wheel: Wheel,
  2197. Live: 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, Transition) {
  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._T || (this.is(FADE) ? Fade : Slide);
  2344. this._E = Extensions || this._E;
  2345. const Constructors = v({}, ComponentConstructors, 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) {
  2382. this.event.emit(event, ...F(arguments, 1));
  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.Media.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. export { CLASSES, CLASS_ACTIVE, CLASS_ARROW, CLASS_ARROWS, CLASS_ARROW_NEXT, CLASS_ARROW_PREV, CLASS_CLONE, CLASS_CONTAINER, CLASS_FOCUS_IN, CLASS_INITIALIZED, CLASS_LIST, CLASS_LOADING, CLASS_NEXT, CLASS_OVERFLOW, CLASS_PAGINATION, CLASS_PAGINATION_PAGE, CLASS_PREV, CLASS_PROGRESS, CLASS_PROGRESS_BAR, CLASS_ROOT, CLASS_SLIDE, CLASS_SPINNER, CLASS_SR, CLASS_TOGGLE, CLASS_TOGGLE_PAUSE, CLASS_TOGGLE_PLAY, CLASS_TRACK, CLASS_VISIBLE, DEFAULTS, EVENT_ACTIVE, EVENT_ARROWS_MOUNTED, EVENT_ARROWS_UPDATED, EVENT_AUTOPLAY_PAUSE, EVENT_AUTOPLAY_PLAY, EVENT_AUTOPLAY_PLAYING, EVENT_CLICK, EVENT_DESTROY, EVENT_DRAG, EVENT_DRAGGED, EVENT_DRAGGING, EVENT_END_INDEX_CHANGED, EVENT_HIDDEN, EVENT_INACTIVE, EVENT_LAZYLOAD_LOADED, EVENT_MOUNTED, EVENT_MOVE, EVENT_MOVED, EVENT_NAVIGATION_MOUNTED, EVENT_OVERFLOW, EVENT_PAGINATION_MOUNTED, EVENT_PAGINATION_UPDATED, EVENT_READY, EVENT_REFRESH, EVENT_RESIZE, EVENT_RESIZED, EVENT_SCROLL, EVENT_SCROLLED, EVENT_SHIFTED, EVENT_SLIDE_KEYDOWN, EVENT_UPDATED, EVENT_VISIBLE, FADE, LOOP, LTR, RTL, SLIDE, STATUS_CLASSES, Splide, SplideRenderer, TTB, Splide as default };