splide.js 76 KB

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