splide.cjs.js 80 KB

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