splide.esm.js 84 KB

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