splide.cjs.js 81 KB

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