splide.js 77 KB

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