splide.js 77 KB

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