splide.esm.js 79 KB

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