splide.esm.js 79 KB

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