splide.js 76 KB

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