splide.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577
  1. /*!
  2. * Splide.js
  3. * Version : 4.1.3
  4. * License : MIT
  5. * Copyright: 2022 Naotoshi Fujita
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Splide = factory());
  11. })(this, (function () { 'use strict';
  12. const MEDIA_PREFERS_REDUCED_MOTION = "(prefers-reduced-motion: reduce)";
  13. const CREATED = 1;
  14. const MOUNTED = 2;
  15. const IDLE = 3;
  16. const MOVING = 4;
  17. const SCROLLING = 5;
  18. const DRAGGING = 6;
  19. const DESTROYED = 7;
  20. const STATES = {
  21. CREATED,
  22. MOUNTED,
  23. IDLE,
  24. MOVING,
  25. SCROLLING,
  26. DRAGGING,
  27. DESTROYED
  28. };
  29. function empty(array) {
  30. array.length = 0;
  31. }
  32. function apply(func, ...args) {
  33. return func.bind(null, ...args);
  34. }
  35. const nextTick = setTimeout;
  36. const noop = () => {
  37. };
  38. function raf(func) {
  39. return requestAnimationFrame(func);
  40. }
  41. function typeOf(type, subject) {
  42. return typeof subject === type;
  43. }
  44. function isObject(subject) {
  45. return !isNull(subject) && typeOf("object", subject);
  46. }
  47. const isArray = Array.isArray;
  48. const isFunction = apply(typeOf, "function");
  49. const isString = apply(typeOf, "string");
  50. apply(typeOf, "boolean");
  51. const isUndefined = apply(typeOf, "undefined");
  52. function isNull(subject) {
  53. return subject === null;
  54. }
  55. function isHTMLElement(subject) {
  56. try {
  57. return subject instanceof (subject.ownerDocument.defaultView || window).HTMLElement;
  58. } catch (e) {
  59. return false;
  60. }
  61. }
  62. function toArray(value) {
  63. return isArray(value) ? value : [value];
  64. }
  65. function forEach(values, iteratee) {
  66. toArray(values).forEach(iteratee);
  67. }
  68. function push(array, items) {
  69. array.push(...toArray(items));
  70. return array;
  71. }
  72. const arrayProto = Array.prototype;
  73. function slice(arrayLike, start, end) {
  74. return arrayProto.slice.call(arrayLike, start, end);
  75. }
  76. function includes(arrayLike, value) {
  77. return arrayProto.includes.call(arrayLike, value);
  78. }
  79. function toggleClass(elm, classes, force) {
  80. if (elm) {
  81. forEach(isString(classes) ? classes.split(" ") : classes, (className) => {
  82. className && elm.classList.toggle(className, force);
  83. });
  84. }
  85. }
  86. function addClass(elm, classes) {
  87. toggleClass(elm, classes, true);
  88. }
  89. function append(parent, children2) {
  90. 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. } else {
  1175. Transition.cancel();
  1176. }
  1177. set(MOVING);
  1178. emit(EVENT_MOVE, index, prev, dest);
  1179. Transition.start(index, () => {
  1180. set(IDLE);
  1181. emit(EVENT_MOVED, index, prev, dest);
  1182. callback && callback();
  1183. });
  1184. }
  1185. function jump(index) {
  1186. translate(toPosition(index, true));
  1187. }
  1188. function translate(position, preventLoop) {
  1189. if (!Splide.is(FADE)) {
  1190. const destination = preventLoop ? position : loop(position);
  1191. style(list, "transform", `translate${resolve("X")}(${destination}px)`);
  1192. position !== destination && emit(EVENT_SHIFTED);
  1193. }
  1194. }
  1195. function loop(position) {
  1196. if (Splide.is(LOOP)) {
  1197. const exceededMax = exceededLimit(true, position);
  1198. const exceededMin = exceededLimit(false, position);
  1199. if (exceededMin || exceededMax) {
  1200. position = shift(position, exceededMax);
  1201. }
  1202. }
  1203. return position;
  1204. }
  1205. function shift(position, backwards) {
  1206. const excess = position - getLimit(backwards);
  1207. const size = sliderSize();
  1208. position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
  1209. return position;
  1210. }
  1211. function cancel() {
  1212. translate(getPosition(), true);
  1213. Transition.cancel();
  1214. }
  1215. function toIndex(position) {
  1216. const slides = Slides.get();
  1217. let index = 0;
  1218. let minDistance = Infinity;
  1219. for (let i = 0; i < slides.length; i++) {
  1220. const slideIndex = slides[i].index;
  1221. const distance = abs(toPosition(slideIndex, true) - position);
  1222. if (distance <= minDistance) {
  1223. minDistance = distance;
  1224. index = slideIndex;
  1225. } else {
  1226. break;
  1227. }
  1228. }
  1229. return index;
  1230. }
  1231. function toPosition(index, trimming) {
  1232. const position = orient(totalSize(index - 1) - offset(index));
  1233. return trimming ? trim(position) : position;
  1234. }
  1235. function getPosition() {
  1236. const left = resolve("left");
  1237. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1238. }
  1239. function trim(position) {
  1240. if (options.trimSpace && Splide.is(SLIDE)) {
  1241. position = clamp(position, 0, orient(sliderSize(true) - listSize()));
  1242. }
  1243. return position;
  1244. }
  1245. function offset(index) {
  1246. const { focus } = options;
  1247. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1248. }
  1249. function getLimit(max) {
  1250. return toPosition(max ? Components.Controller.getEnd() : 0, !!options.trimSpace);
  1251. }
  1252. function canShift(backwards) {
  1253. const padding = getPadding(false);
  1254. const shifted = orient(shift(getPosition(), backwards));
  1255. return backwards ? shifted >= padding : shifted <= list[resolve("scrollWidth")] - rect(track)[resolve("width")] + padding;
  1256. }
  1257. function exceededLimit(max, position = getPosition()) {
  1258. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1259. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1260. return exceededMin || exceededMax;
  1261. }
  1262. return {
  1263. mount,
  1264. move,
  1265. jump,
  1266. translate,
  1267. shift,
  1268. cancel,
  1269. toIndex,
  1270. toPosition,
  1271. getPosition,
  1272. getLimit,
  1273. exceededLimit,
  1274. reposition,
  1275. canShift
  1276. };
  1277. };
  1278. const Controller = (Splide, Components, options, event) => {
  1279. const { on, emit } = event;
  1280. const { Move } = Components;
  1281. const { getPosition, getLimit, toPosition } = Move;
  1282. const { isEnough, getLength } = Components.Slides;
  1283. const { omitEnd } = options;
  1284. const isLoop = Splide.is(LOOP);
  1285. const isSlide = Splide.is(SLIDE);
  1286. const getNext = apply(getAdjacent, false);
  1287. const getPrev = apply(getAdjacent, true);
  1288. let currIndex = options.start || 0;
  1289. let endIndex;
  1290. let prevIndex = currIndex;
  1291. let slideCount;
  1292. let perMove;
  1293. let perPage;
  1294. function mount() {
  1295. init();
  1296. on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], init);
  1297. on(EVENT_RESIZED, onResized);
  1298. }
  1299. function init() {
  1300. slideCount = getLength(true);
  1301. perMove = options.perMove;
  1302. perPage = options.perPage;
  1303. endIndex = getEnd();
  1304. const end = omitEnd ? endIndex : slideCount - 1;
  1305. const index = clamp(currIndex, 0, end);
  1306. prevIndex = index;
  1307. if (index !== currIndex) {
  1308. currIndex = index;
  1309. Move.reposition();
  1310. }
  1311. }
  1312. function onResized() {
  1313. if (endIndex !== getEnd()) {
  1314. emit(EVENT_END_INDEX_CHANGED);
  1315. }
  1316. }
  1317. function go(control, allowSameIndex, callback) {
  1318. if (!isBusy()) {
  1319. const dest = parse(control);
  1320. const index = loop(dest);
  1321. const validIndex = index > -1 && (allowSameIndex || index !== currIndex);
  1322. const canMove = dest === index || Move.canShift(dest > prevIndex);
  1323. if (validIndex && canMove) {
  1324. setIndex(index);
  1325. Move.move(dest, index, prevIndex, callback);
  1326. }
  1327. }
  1328. }
  1329. function jump(control) {
  1330. const { set } = Components.Breakpoints;
  1331. const { speed } = options;
  1332. set({ speed: 0 });
  1333. go(control);
  1334. set({ speed });
  1335. }
  1336. function scroll(destination, duration, snap, callback) {
  1337. Components.Scroll.scroll(destination, duration, snap, () => {
  1338. const index = loop(Move.toIndex(getPosition()));
  1339. setIndex(omitEnd ? min(index, endIndex) : index);
  1340. callback && callback();
  1341. });
  1342. }
  1343. function parse(control) {
  1344. let index = currIndex;
  1345. if (isString(control)) {
  1346. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1347. if (indicator === "+" || indicator === "-") {
  1348. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
  1349. } else if (indicator === ">") {
  1350. index = number ? toIndex(+number) : getNext(true);
  1351. } else if (indicator === "<") {
  1352. index = getPrev(true);
  1353. }
  1354. } else {
  1355. index = isLoop ? control : clamp(control, 0, endIndex);
  1356. }
  1357. return index;
  1358. }
  1359. function getAdjacent(prev, destination) {
  1360. const number = perMove || (hasFocus() ? 1 : perPage);
  1361. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex, !(perMove || hasFocus()));
  1362. if (dest === -1 && isSlide) {
  1363. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1364. return prev ? 0 : endIndex;
  1365. }
  1366. }
  1367. return destination ? dest : loop(dest);
  1368. }
  1369. function computeDestIndex(dest, from, snapPage) {
  1370. if (isEnough() || hasFocus()) {
  1371. const index = computeMovableDestIndex(dest);
  1372. if (index !== dest) {
  1373. from = dest;
  1374. dest = index;
  1375. snapPage = false;
  1376. }
  1377. if (dest < 0 || dest > endIndex) {
  1378. if (!perMove && (between(0, dest, from, true) || between(endIndex, from, dest, true))) {
  1379. dest = toIndex(toPage(dest));
  1380. } else {
  1381. if (isLoop) {
  1382. dest = snapPage ? dest < 0 ? -(slideCount % perPage || perPage) : slideCount : dest;
  1383. } else if (options.rewind) {
  1384. dest = dest < 0 ? endIndex : 0;
  1385. } else {
  1386. dest = -1;
  1387. }
  1388. }
  1389. } else {
  1390. if (snapPage && dest !== from) {
  1391. dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
  1392. }
  1393. }
  1394. } else {
  1395. dest = -1;
  1396. }
  1397. return dest;
  1398. }
  1399. function computeMovableDestIndex(dest) {
  1400. if (isSlide && options.trimSpace === "move" && dest !== currIndex) {
  1401. const position = getPosition();
  1402. while (position === toPosition(dest, true) && between(dest, 0, Splide.length - 1, !options.rewind)) {
  1403. dest < currIndex ? --dest : ++dest;
  1404. }
  1405. }
  1406. return dest;
  1407. }
  1408. function loop(index) {
  1409. return isLoop ? (index + slideCount) % slideCount || 0 : index;
  1410. }
  1411. function getEnd() {
  1412. let end = slideCount - (hasFocus() || isLoop && perMove ? 1 : perPage);
  1413. while (omitEnd && end-- > 0) {
  1414. if (toPosition(slideCount - 1, true) !== toPosition(end, true)) {
  1415. end++;
  1416. break;
  1417. }
  1418. }
  1419. return clamp(end, 0, slideCount - 1);
  1420. }
  1421. function toIndex(page) {
  1422. return clamp(hasFocus() ? page : perPage * page, 0, endIndex);
  1423. }
  1424. function toPage(index) {
  1425. return hasFocus() ? min(index, endIndex) : floor((index >= endIndex ? slideCount - 1 : index) / perPage);
  1426. }
  1427. function toDest(destination) {
  1428. const closest = Move.toIndex(destination);
  1429. return isSlide ? clamp(closest, 0, endIndex) : closest;
  1430. }
  1431. function setIndex(index) {
  1432. if (index !== currIndex) {
  1433. prevIndex = currIndex;
  1434. currIndex = index;
  1435. }
  1436. }
  1437. function getIndex(prev) {
  1438. return prev ? prevIndex : currIndex;
  1439. }
  1440. function hasFocus() {
  1441. return !isUndefined(options.focus) || options.isNavigation;
  1442. }
  1443. function isBusy() {
  1444. return Splide.state.is([MOVING, SCROLLING]) && !!options.waitForTransition;
  1445. }
  1446. return {
  1447. mount,
  1448. go,
  1449. jump,
  1450. scroll,
  1451. getNext,
  1452. getPrev,
  1453. getAdjacent,
  1454. getEnd,
  1455. setIndex,
  1456. getIndex,
  1457. toIndex,
  1458. toPage,
  1459. toDest,
  1460. hasFocus,
  1461. isBusy
  1462. };
  1463. };
  1464. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1465. 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";
  1466. const SIZE = 40;
  1467. const Arrows = (Splide, Components, options, event) => {
  1468. const { on, bind, emit } = event;
  1469. const { classes, i18n } = options;
  1470. const { Elements, Controller } = Components;
  1471. const { arrows: placeholder, track } = Elements;
  1472. let wrapper = placeholder;
  1473. let prev = Elements.prev;
  1474. let next = Elements.next;
  1475. let created;
  1476. let wrapperClasses;
  1477. const arrows = {};
  1478. function mount() {
  1479. init();
  1480. on(EVENT_UPDATED, remount);
  1481. }
  1482. function remount() {
  1483. destroy();
  1484. mount();
  1485. }
  1486. function init() {
  1487. const enabled = options.arrows;
  1488. if (enabled && !(prev && next)) {
  1489. createArrows();
  1490. }
  1491. if (prev && next) {
  1492. assign(arrows, { prev, next });
  1493. display(wrapper, enabled ? "" : "none");
  1494. addClass(wrapper, wrapperClasses = `${CLASS_ARROWS}--${options.direction}`);
  1495. if (enabled) {
  1496. listen();
  1497. update();
  1498. setAttribute([prev, next], ARIA_CONTROLS, track.id);
  1499. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1500. }
  1501. }
  1502. }
  1503. function destroy() {
  1504. event.destroy();
  1505. removeClass(wrapper, wrapperClasses);
  1506. if (created) {
  1507. removeNode(placeholder ? [prev, next] : wrapper);
  1508. prev = next = null;
  1509. } else {
  1510. removeAttribute([prev, next], ALL_ATTRIBUTES);
  1511. }
  1512. }
  1513. function listen() {
  1514. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLLED, EVENT_END_INDEX_CHANGED], update);
  1515. bind(next, "click", apply(go, ">"));
  1516. bind(prev, "click", apply(go, "<"));
  1517. }
  1518. function go(control) {
  1519. Controller.go(control, true);
  1520. }
  1521. function createArrows() {
  1522. wrapper = placeholder || create("div", classes.arrows);
  1523. prev = createArrow(true);
  1524. next = createArrow(false);
  1525. created = true;
  1526. append(wrapper, [prev, next]);
  1527. !placeholder && before(wrapper, track);
  1528. }
  1529. function createArrow(prev2) {
  1530. 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}" />`;
  1531. return parseHtml(arrow);
  1532. }
  1533. function update() {
  1534. if (prev && next) {
  1535. const index = Splide.index;
  1536. const prevIndex = Controller.getPrev();
  1537. const nextIndex = Controller.getNext();
  1538. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1539. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1540. prev.disabled = prevIndex < 0;
  1541. next.disabled = nextIndex < 0;
  1542. setAttribute(prev, ARIA_LABEL, prevLabel);
  1543. setAttribute(next, ARIA_LABEL, nextLabel);
  1544. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1545. }
  1546. }
  1547. return {
  1548. arrows,
  1549. mount,
  1550. destroy,
  1551. update
  1552. };
  1553. };
  1554. const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
  1555. const Autoplay = (Splide, Components, options, event) => {
  1556. const { on, bind, emit } = event;
  1557. const interval = RequestInterval(options.interval, Splide.go.bind(Splide, ">"), onAnimationFrame);
  1558. const { isPaused } = interval;
  1559. const { Elements, Elements: { root, toggle } } = Components;
  1560. const { autoplay } = options;
  1561. let hovered;
  1562. let focused;
  1563. let stopped = autoplay === "pause";
  1564. function mount() {
  1565. if (autoplay) {
  1566. listen();
  1567. toggle && setAttribute(toggle, ARIA_CONTROLS, Elements.track.id);
  1568. stopped || play();
  1569. update();
  1570. }
  1571. }
  1572. function listen() {
  1573. if (options.pauseOnHover) {
  1574. bind(root, "mouseenter mouseleave", (e) => {
  1575. hovered = e.type === "mouseenter";
  1576. autoToggle();
  1577. });
  1578. }
  1579. if (options.pauseOnFocus) {
  1580. bind(root, "focusin focusout", (e) => {
  1581. focused = e.type === "focusin";
  1582. autoToggle();
  1583. });
  1584. }
  1585. if (toggle) {
  1586. bind(toggle, "click", () => {
  1587. stopped ? play() : pause(true);
  1588. });
  1589. }
  1590. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1591. on(EVENT_MOVE, onMove);
  1592. }
  1593. function play() {
  1594. if (isPaused() && Components.Slides.isEnough()) {
  1595. interval.start(!options.resetProgress);
  1596. focused = hovered = stopped = false;
  1597. update();
  1598. emit(EVENT_AUTOPLAY_PLAY);
  1599. }
  1600. }
  1601. function pause(stop = true) {
  1602. stopped = !!stop;
  1603. update();
  1604. if (!isPaused()) {
  1605. interval.pause();
  1606. emit(EVENT_AUTOPLAY_PAUSE);
  1607. }
  1608. }
  1609. function autoToggle() {
  1610. if (!stopped) {
  1611. hovered || focused ? pause(false) : play();
  1612. }
  1613. }
  1614. function update() {
  1615. if (toggle) {
  1616. toggleClass(toggle, CLASS_ACTIVE, !stopped);
  1617. setAttribute(toggle, ARIA_LABEL, options.i18n[stopped ? "play" : "pause"]);
  1618. }
  1619. }
  1620. function onAnimationFrame(rate) {
  1621. const { bar } = Elements;
  1622. bar && style(bar, "width", `${rate * 100}%`);
  1623. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1624. }
  1625. function onMove(index) {
  1626. const Slide = Components.Slides.getAt(index);
  1627. interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1628. }
  1629. return {
  1630. mount,
  1631. destroy: interval.cancel,
  1632. play,
  1633. pause,
  1634. isPaused
  1635. };
  1636. };
  1637. const BOUNCE_DIFF_THRESHOLD = 10;
  1638. const BOUNCE_DURATION = 600;
  1639. const FRICTION_FACTOR = 0.6;
  1640. const BASE_VELOCITY = 1.5;
  1641. const MIN_DURATION = 800;
  1642. const Scroll = (Splide, Components, options, event) => {
  1643. const { on, emit } = event;
  1644. const { state: { set } } = Splide;
  1645. const { Move } = Components;
  1646. const { getPosition, getLimit, exceededLimit, translate } = Move;
  1647. const isSlide = Splide.is(SLIDE);
  1648. let interval;
  1649. let callback;
  1650. let friction = 1;
  1651. function mount() {
  1652. on(EVENT_MOVE, clear);
  1653. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1654. }
  1655. function scroll(destination, duration, snap, onScrolled, noConstrain) {
  1656. const from = getPosition();
  1657. clear();
  1658. if (snap && (!isSlide || !exceededLimit())) {
  1659. const size = Components.Layout.sliderSize();
  1660. const offset = sign(destination) * size * floor(abs(destination) / size) || 0;
  1661. destination = Move.toPosition(Components.Controller.toDest(destination % size)) + offset;
  1662. }
  1663. const immediately = approximatelyEqual(from, destination, 1) || duration === 0;
  1664. friction = 1;
  1665. duration = immediately ? 0 : duration || max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION);
  1666. callback = onScrolled;
  1667. interval = RequestInterval(duration, onEnd, apply(update, from, destination, noConstrain), 1);
  1668. set(SCROLLING);
  1669. emit(EVENT_SCROLL);
  1670. interval.start();
  1671. }
  1672. function onEnd() {
  1673. set(IDLE);
  1674. callback && callback();
  1675. emit(EVENT_SCROLLED);
  1676. }
  1677. function update(from, to, noConstrain, rate) {
  1678. const position = getPosition();
  1679. const target = from + (to - from) * easing(rate);
  1680. const diff = (target - position) * friction;
  1681. translate(position + diff);
  1682. if (isSlide && !noConstrain && exceededLimit()) {
  1683. friction *= FRICTION_FACTOR;
  1684. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1685. scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
  1686. }
  1687. }
  1688. }
  1689. function clear() {
  1690. if (interval) {
  1691. interval.cancel();
  1692. }
  1693. }
  1694. function cancel() {
  1695. if (interval && !interval.isPaused()) {
  1696. clear();
  1697. onEnd();
  1698. }
  1699. }
  1700. function easing(t) {
  1701. const { easingFunc } = options;
  1702. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1703. }
  1704. return {
  1705. mount,
  1706. destroy: clear,
  1707. scroll,
  1708. cancel
  1709. };
  1710. };
  1711. const SCROLL_LISTENER_OPTIONS = { passive: false, capture: true };
  1712. const Drag = (Splide, Components, options, event) => {
  1713. const { on, emit, bind } = event;
  1714. const binder = event.create();
  1715. const { state } = Splide;
  1716. const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
  1717. const { resolve, orient } = Components.Direction;
  1718. const { getPosition, exceededLimit } = Move;
  1719. let basePosition;
  1720. let baseEvent;
  1721. let prevBaseEvent;
  1722. let isFree;
  1723. let dragging;
  1724. let exceeded = false;
  1725. let clickPrevented;
  1726. let disabled;
  1727. let target;
  1728. function mount() {
  1729. bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1730. bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1731. bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
  1732. bind(track, "click", onClick, { capture: true });
  1733. bind(track, "dragstart", prevent);
  1734. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1735. }
  1736. function init() {
  1737. const { drag } = options;
  1738. disable(!drag);
  1739. isFree = drag === "free";
  1740. }
  1741. function onPointerDown(e) {
  1742. clickPrevented = false;
  1743. if (!disabled) {
  1744. const isTouch = isTouchEvent(e);
  1745. if (isDraggable(e.target) && (isTouch || !e.button)) {
  1746. if (!Controller.isBusy()) {
  1747. target = isTouch ? track : window;
  1748. dragging = state.is([MOVING, SCROLLING]);
  1749. prevBaseEvent = null;
  1750. binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
  1751. binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
  1752. Move.cancel();
  1753. Scroll.cancel();
  1754. save(e);
  1755. } else {
  1756. prevent(e, true);
  1757. }
  1758. }
  1759. }
  1760. }
  1761. function onPointerMove(e) {
  1762. if (!state.is(DRAGGING)) {
  1763. state.set(DRAGGING);
  1764. emit(EVENT_DRAG);
  1765. }
  1766. if (shouldRelease(e)) {
  1767. return onPointerUp(e);
  1768. }
  1769. if (e.cancelable) {
  1770. if (dragging) {
  1771. Move.translate(basePosition + constrain(diffCoord(e)));
  1772. const expired = diffTime(e) > LOG_INTERVAL;
  1773. const hasExceeded = exceeded !== (exceeded = exceededLimit());
  1774. if (expired || hasExceeded) {
  1775. save(e);
  1776. }
  1777. clickPrevented = true;
  1778. emit(EVENT_DRAGGING);
  1779. prevent(e);
  1780. } else if (isSliderDirection(e)) {
  1781. dragging = shouldStart(e);
  1782. prevent(e);
  1783. }
  1784. }
  1785. }
  1786. function onPointerUp(e) {
  1787. if (state.is(DRAGGING)) {
  1788. state.set(IDLE);
  1789. emit(EVENT_DRAGGED);
  1790. }
  1791. if (dragging) {
  1792. move(e);
  1793. prevent(e);
  1794. }
  1795. binder.destroy();
  1796. dragging = false;
  1797. }
  1798. function onClick(e) {
  1799. if (!disabled && clickPrevented) {
  1800. prevent(e, true);
  1801. }
  1802. }
  1803. function save(e) {
  1804. prevBaseEvent = baseEvent;
  1805. baseEvent = e;
  1806. basePosition = getPosition();
  1807. }
  1808. function move(e) {
  1809. const { updateOnDragged = true } = options;
  1810. const velocity = computeVelocity(e);
  1811. const destination = computeDestination(velocity);
  1812. const rewind = options.rewind && options.rewindByDrag;
  1813. const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
  1814. reduce(false);
  1815. if (isFree) {
  1816. scroll(destination, void 0, options.snap);
  1817. } else if (Splide.is(FADE)) {
  1818. Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
  1819. } else if (Splide.is(SLIDE) && exceeded && rewind) {
  1820. Controller.go(exceededLimit(true) ? ">" : "<");
  1821. } else {
  1822. Controller.go(Controller.toDest(destination), true);
  1823. }
  1824. reduce(true);
  1825. }
  1826. function shouldRelease(e) {
  1827. if (options.releaseTouch && Splide.is(SLIDE) && isTouchEvent(e)) {
  1828. const { index } = Splide;
  1829. const diff = diffCoord(e);
  1830. if (exceededLimit() || index === 0 && diff > 0 || index === Splide.length - 1 && diff < 0) {
  1831. return true;
  1832. }
  1833. }
  1834. return false;
  1835. }
  1836. function shouldStart(e) {
  1837. const { dragMinThreshold: thresholds } = options;
  1838. const isObj = isObject(thresholds);
  1839. const mouse = isObj && thresholds.mouse || 0;
  1840. const touch = (isObj ? thresholds.touch : +thresholds) || 10;
  1841. return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
  1842. }
  1843. function isSliderDirection(e) {
  1844. return abs(diffCoord(e)) > abs(diffCoord(e, true));
  1845. }
  1846. function computeVelocity(e) {
  1847. if (Splide.is(LOOP) || !exceeded) {
  1848. const time = diffTime(e);
  1849. if (time && time < LOG_INTERVAL) {
  1850. return diffCoord(e) / time;
  1851. }
  1852. }
  1853. return 0;
  1854. }
  1855. function computeDestination(velocity) {
  1856. return getPosition() + sign(velocity) * min(
  1857. abs(velocity) * (options.flickPower || 600),
  1858. isFree ? Infinity : Components.Layout.listSize() * (options.flickMaxPages || 1)
  1859. );
  1860. }
  1861. function diffCoord(e, orthogonal) {
  1862. return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
  1863. }
  1864. function diffTime(e) {
  1865. return timeOf(e) - timeOf(getBaseEvent(e));
  1866. }
  1867. function getBaseEvent(e) {
  1868. return baseEvent === e && prevBaseEvent || baseEvent;
  1869. }
  1870. function coordOf(e, orthogonal) {
  1871. return (isTouchEvent(e) ? e.changedTouches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
  1872. }
  1873. function constrain(diff) {
  1874. return diff / (exceeded && Splide.is(SLIDE) ? FRICTION : 1);
  1875. }
  1876. function isDraggable(target2) {
  1877. const { noDrag } = options;
  1878. return !matches(target2, `.${CLASS_PAGINATION_PAGE}, .${CLASS_ARROW}`) && (!noDrag || !matches(target2, noDrag));
  1879. }
  1880. function isTouchEvent(e) {
  1881. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1882. }
  1883. function isDragging() {
  1884. return dragging;
  1885. }
  1886. function disable(value) {
  1887. disabled = value;
  1888. }
  1889. return {
  1890. mount,
  1891. disable,
  1892. isDragging
  1893. };
  1894. };
  1895. const KEYBOARD_EVENT = "keydown";
  1896. const Keyboard = (Splide, Components, options, event) => {
  1897. const { on, bind, destroy } = event;
  1898. const { root } = Splide;
  1899. const { resolve } = Components.Direction;
  1900. let target;
  1901. let disabled;
  1902. function mount() {
  1903. init();
  1904. on(EVENT_UPDATED, destroy);
  1905. on(EVENT_UPDATED, init);
  1906. on(EVENT_MOVE, onMove);
  1907. }
  1908. function init() {
  1909. const { keyboard } = options;
  1910. if (keyboard) {
  1911. target = keyboard === "global" ? window : root;
  1912. bind(target, KEYBOARD_EVENT, onKeydown);
  1913. }
  1914. }
  1915. function disable(value) {
  1916. disabled = value;
  1917. }
  1918. function onMove() {
  1919. const _disabled = disabled;
  1920. disabled = true;
  1921. nextTick(() => {
  1922. disabled = _disabled;
  1923. });
  1924. }
  1925. function onKeydown(e) {
  1926. if (!disabled) {
  1927. if (e.key === resolve(ARROW_LEFT)) {
  1928. Splide.go("<");
  1929. } else if (e.key === resolve(ARROW_RIGHT)) {
  1930. Splide.go(">");
  1931. }
  1932. }
  1933. }
  1934. return {
  1935. mount,
  1936. destroy,
  1937. disable
  1938. };
  1939. };
  1940. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1941. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1942. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1943. const LazyLoad = (Splide, Components, options, event) => {
  1944. const { on, off, bind, emit } = event;
  1945. const isSequential = options.lazyLoad === "sequential";
  1946. const events = [EVENT_MOVED, EVENT_SCROLLED];
  1947. let entries = [];
  1948. function mount() {
  1949. if (options.lazyLoad) {
  1950. init();
  1951. on(EVENT_REFRESH, init);
  1952. }
  1953. }
  1954. function init() {
  1955. empty(entries);
  1956. register();
  1957. if (isSequential) {
  1958. loadNext();
  1959. } else {
  1960. off(events);
  1961. on(events, check);
  1962. check();
  1963. }
  1964. }
  1965. function register() {
  1966. Components.Slides.forEach((Slide) => {
  1967. queryAll(Slide.slide, IMAGE_SELECTOR).forEach((img) => {
  1968. const src = getAttribute(img, SRC_DATA_ATTRIBUTE);
  1969. const srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
  1970. if (src !== img.src || srcset !== img.srcset) {
  1971. const className = options.classes.spinner;
  1972. const parent = img.parentElement;
  1973. const spinner = child(parent, `.${className}`) || create("span", className, parent);
  1974. entries.push([img, Slide, spinner]);
  1975. img.src || display(img, "none");
  1976. }
  1977. });
  1978. });
  1979. }
  1980. function check() {
  1981. entries = entries.filter((data) => {
  1982. const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  1983. return data[1].isWithin(Splide.index, distance) ? load(data) : true;
  1984. });
  1985. entries.length || off(events);
  1986. }
  1987. function load(data) {
  1988. const [img] = data;
  1989. addClass(data[1].slide, CLASS_LOADING);
  1990. bind(img, "load error", apply(onLoad, data));
  1991. setAttribute(img, "src", getAttribute(img, SRC_DATA_ATTRIBUTE));
  1992. setAttribute(img, "srcset", getAttribute(img, SRCSET_DATA_ATTRIBUTE));
  1993. removeAttribute(img, SRC_DATA_ATTRIBUTE);
  1994. removeAttribute(img, SRCSET_DATA_ATTRIBUTE);
  1995. }
  1996. function onLoad(data, e) {
  1997. const [img, Slide] = data;
  1998. removeClass(Slide.slide, CLASS_LOADING);
  1999. if (e.type !== "error") {
  2000. removeNode(data[2]);
  2001. display(img, "");
  2002. emit(EVENT_LAZYLOAD_LOADED, img, Slide);
  2003. emit(EVENT_RESIZE);
  2004. } else {
  2005. emit(EVENT_LAZYLOAD_ERROR, img, Slide);
  2006. }
  2007. isSequential && loadNext();
  2008. }
  2009. function loadNext() {
  2010. entries.length && load(entries.shift());
  2011. }
  2012. return {
  2013. mount,
  2014. destroy: apply(empty, entries),
  2015. check
  2016. };
  2017. };
  2018. const Pagination = (Splide, Components, options, event) => {
  2019. const { on, emit, bind } = event;
  2020. const { Slides, Elements, Controller } = Components;
  2021. const { hasFocus, getIndex, go } = Controller;
  2022. const { resolve } = Components.Direction;
  2023. const { pagination: placeholder } = Elements;
  2024. const items = [];
  2025. let list;
  2026. let paginationClasses;
  2027. function mount() {
  2028. destroy();
  2029. on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], mount);
  2030. const enabled = options.pagination;
  2031. placeholder && display(placeholder, enabled ? "" : "none");
  2032. if (enabled) {
  2033. on([EVENT_MOVE, EVENT_SCROLL, EVENT_SCROLLED], update);
  2034. createPagination();
  2035. update();
  2036. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide.index));
  2037. }
  2038. }
  2039. function destroy() {
  2040. if (list) {
  2041. removeNode(placeholder ? slice(list.children) : list);
  2042. removeClass(list, paginationClasses);
  2043. empty(items);
  2044. list = null;
  2045. }
  2046. event.destroy();
  2047. }
  2048. function createPagination() {
  2049. const { length } = Splide;
  2050. const { classes, i18n, perPage } = options;
  2051. const max = hasFocus() ? Controller.getEnd() + 1 : ceil(length / perPage);
  2052. list = placeholder || create("ul", classes.pagination, Elements.track.parentElement);
  2053. addClass(list, paginationClasses = `${CLASS_PAGINATION}--${getDirection()}`);
  2054. setAttribute(list, ROLE, "tablist");
  2055. setAttribute(list, ARIA_LABEL, i18n.select);
  2056. setAttribute(list, ARIA_ORIENTATION, getDirection() === TTB ? "vertical" : "");
  2057. for (let i = 0; i < max; i++) {
  2058. const li = create("li", null, list);
  2059. const button = create("button", { class: classes.page, type: "button" }, li);
  2060. const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
  2061. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  2062. bind(button, "click", apply(onClick, i));
  2063. if (options.paginationKeyboard) {
  2064. bind(button, "keydown", apply(onKeydown, i));
  2065. }
  2066. setAttribute(li, ROLE, "presentation");
  2067. setAttribute(button, ROLE, "tab");
  2068. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  2069. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  2070. setAttribute(button, TAB_INDEX, -1);
  2071. items.push({ li, button, page: i });
  2072. }
  2073. }
  2074. function onClick(page) {
  2075. go(`>${page}`, true);
  2076. }
  2077. function onKeydown(page, e) {
  2078. const { length } = items;
  2079. const { key } = e;
  2080. const dir = getDirection();
  2081. let nextPage = -1;
  2082. if (key === resolve(ARROW_RIGHT, false, dir)) {
  2083. nextPage = ++page % length;
  2084. } else if (key === resolve(ARROW_LEFT, false, dir)) {
  2085. nextPage = (--page + length) % length;
  2086. } else if (key === "Home") {
  2087. nextPage = 0;
  2088. } else if (key === "End") {
  2089. nextPage = length - 1;
  2090. }
  2091. const item = items[nextPage];
  2092. if (item) {
  2093. focus(item.button);
  2094. go(`>${nextPage}`);
  2095. prevent(e, true);
  2096. }
  2097. }
  2098. function getDirection() {
  2099. return options.paginationDirection || options.direction;
  2100. }
  2101. function getAt(index) {
  2102. return items[Controller.toPage(index)];
  2103. }
  2104. function update() {
  2105. const prev = getAt(getIndex(true));
  2106. const curr = getAt(getIndex());
  2107. if (prev) {
  2108. const { button } = prev;
  2109. removeClass(button, CLASS_ACTIVE);
  2110. removeAttribute(button, ARIA_SELECTED);
  2111. setAttribute(button, TAB_INDEX, -1);
  2112. }
  2113. if (curr) {
  2114. const { button } = curr;
  2115. addClass(button, CLASS_ACTIVE);
  2116. setAttribute(button, ARIA_SELECTED, true);
  2117. setAttribute(button, TAB_INDEX, "");
  2118. }
  2119. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  2120. }
  2121. return {
  2122. items,
  2123. mount,
  2124. destroy,
  2125. getAt,
  2126. update
  2127. };
  2128. };
  2129. const TRIGGER_KEYS = [" ", "Enter"];
  2130. const Sync = (Splide2, Components, options, event) => {
  2131. const { isNavigation, slideFocus } = options;
  2132. const events = [];
  2133. function mount() {
  2134. Splide2.splides.forEach((target) => {
  2135. if (!target.isParent) {
  2136. sync(Splide2, target.splide);
  2137. sync(target.splide, Splide2);
  2138. }
  2139. });
  2140. if (isNavigation) {
  2141. navigate();
  2142. }
  2143. }
  2144. function destroy() {
  2145. events.forEach((event2) => {
  2146. event2.destroy();
  2147. });
  2148. empty(events);
  2149. }
  2150. function remount() {
  2151. destroy();
  2152. mount();
  2153. }
  2154. function sync(splide, target) {
  2155. const event2 = splide.event.create();
  2156. event2.on(EVENT_MOVE, (index, prev, dest) => {
  2157. target.go(target.is(LOOP) ? dest : index);
  2158. });
  2159. events.push(event2);
  2160. }
  2161. function navigate() {
  2162. const ev = event.create();
  2163. const { on } = ev;
  2164. on(EVENT_CLICK, onClick);
  2165. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2166. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2167. events.push(ev);
  2168. ev.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2169. }
  2170. function update() {
  2171. setAttribute(
  2172. Components.Elements.list,
  2173. ARIA_ORIENTATION,
  2174. options.direction === TTB ? "vertical" : ""
  2175. );
  2176. }
  2177. function onClick(Slide) {
  2178. Splide2.go(Slide.index);
  2179. }
  2180. function onKeydown(Slide, e) {
  2181. if (includes(TRIGGER_KEYS, e.key)) {
  2182. onClick(Slide);
  2183. prevent(e);
  2184. }
  2185. }
  2186. return {
  2187. setup: apply(
  2188. Components.Breakpoints.set,
  2189. { slideFocus: isUndefined(slideFocus) ? isNavigation : slideFocus },
  2190. true
  2191. ),
  2192. mount,
  2193. destroy,
  2194. remount
  2195. };
  2196. };
  2197. const Wheel = (Splide, Components, options, event) => {
  2198. let lastTime = 0;
  2199. function mount() {
  2200. event.destroy();
  2201. if (options.wheel) {
  2202. event.bind(Components.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
  2203. }
  2204. event.on(EVENT_UPDATED, mount);
  2205. }
  2206. function onWheel(e) {
  2207. if (e.cancelable) {
  2208. const delta = parse(e);
  2209. const backwards = delta < 0;
  2210. const timeStamp = timeOf(e);
  2211. const min = options.wheelMinThreshold || 0;
  2212. const sleep = options.wheelSleep || 0;
  2213. if (abs(delta) > min && timeStamp - lastTime > sleep) {
  2214. Splide.go(delta < 0 ? "<" : ">");
  2215. lastTime = timeStamp;
  2216. }
  2217. shouldPrevent(backwards) && prevent(e);
  2218. }
  2219. }
  2220. function parse(e) {
  2221. const { wheelAxis = "y" } = options;
  2222. const { deltaX, deltaY } = e;
  2223. const x = includes(wheelAxis, "x") ? Components.Direction.orient(-deltaX) : 0;
  2224. const y = includes(wheelAxis, "y") ? deltaY : 0;
  2225. return x || y;
  2226. }
  2227. function shouldPrevent(backwards) {
  2228. return !options.releaseWheel || Splide.state.is(MOVING) || Components.Controller.getAdjacent(backwards) !== -1;
  2229. }
  2230. return {
  2231. mount
  2232. };
  2233. };
  2234. const VISUALLY_HIDDEN = `border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px`;
  2235. const SR_REMOVAL_DELAY = 90;
  2236. const Live = (Splide, Components, options, event) => {
  2237. const { on } = event;
  2238. const { track } = Components.Elements;
  2239. const enabled = options.live && !options.isNavigation;
  2240. const sr = create("span", CLASS_SR);
  2241. const interval = RequestInterval(SR_REMOVAL_DELAY, apply(toggle, false));
  2242. function mount() {
  2243. if (enabled) {
  2244. disable(!Components.Autoplay.isPaused());
  2245. setAttribute(track, ARIA_ATOMIC, true);
  2246. sr.textContent = "\u2026";
  2247. sr.style.cssText = VISUALLY_HIDDEN;
  2248. on(EVENT_AUTOPLAY_PLAY, apply(disable, true));
  2249. on(EVENT_AUTOPLAY_PAUSE, apply(disable, false));
  2250. on([EVENT_MOVED, EVENT_SCROLLED], apply(toggle, true));
  2251. }
  2252. }
  2253. function toggle(active) {
  2254. setAttribute(track, ARIA_BUSY, active);
  2255. if (active) {
  2256. append(track, sr);
  2257. interval.start();
  2258. } else {
  2259. removeNode(sr);
  2260. interval.cancel();
  2261. }
  2262. }
  2263. function destroy() {
  2264. removeAttribute(track, [ARIA_LIVE, ARIA_ATOMIC, ARIA_BUSY]);
  2265. removeNode(sr);
  2266. }
  2267. function disable(disabled) {
  2268. if (enabled) {
  2269. setAttribute(track, ARIA_LIVE, disabled ? "off" : "polite");
  2270. }
  2271. }
  2272. return {
  2273. mount,
  2274. disable,
  2275. destroy
  2276. };
  2277. };
  2278. const COMPONENTS = {
  2279. Breakpoints,
  2280. Direction,
  2281. Elements,
  2282. Slides,
  2283. Layout,
  2284. Clones,
  2285. Move,
  2286. Controller,
  2287. Arrows,
  2288. Autoplay,
  2289. Scroll,
  2290. Drag,
  2291. Keyboard,
  2292. LazyLoad,
  2293. Pagination,
  2294. Sync,
  2295. Wheel,
  2296. Live
  2297. };
  2298. const I18N = {
  2299. prev: "Previous slide",
  2300. next: "Next slide",
  2301. first: "Go to first slide",
  2302. last: "Go to last slide",
  2303. slideX: "Go to slide %s",
  2304. pageX: "Go to page %s",
  2305. play: "Start autoplay",
  2306. pause: "Pause autoplay",
  2307. carousel: "carousel",
  2308. slide: "slide",
  2309. select: "Select a slide to show",
  2310. slideLabel: "%s of %s"
  2311. };
  2312. const DEFAULTS = {
  2313. type: "slide",
  2314. role: "region",
  2315. speed: 400,
  2316. perPage: 1,
  2317. cloneStatus: true,
  2318. arrows: true,
  2319. pagination: true,
  2320. paginationKeyboard: true,
  2321. interval: 5e3,
  2322. pauseOnHover: true,
  2323. pauseOnFocus: true,
  2324. resetProgress: true,
  2325. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  2326. drag: true,
  2327. direction: "ltr",
  2328. trimSpace: true,
  2329. focusableNodes: "a, button, textarea, input, select, iframe",
  2330. live: true,
  2331. classes: CLASSES,
  2332. i18n: I18N,
  2333. reducedMotion: {
  2334. speed: 0,
  2335. rewindSpeed: 0,
  2336. autoplay: "pause"
  2337. }
  2338. };
  2339. const Fade = (Splide, Components, options, event) => {
  2340. const { Slides } = Components;
  2341. function mount() {
  2342. event.on([EVENT_MOUNTED, EVENT_REFRESH], init);
  2343. }
  2344. function init() {
  2345. Slides.forEach((Slide) => {
  2346. Slide.style("transform", `translateX(-${100 * Slide.index}%)`);
  2347. });
  2348. }
  2349. function start(index, done) {
  2350. Slides.style("transition", `opacity ${options.speed}ms ${options.easing}`);
  2351. nextTick(done);
  2352. }
  2353. return {
  2354. mount,
  2355. start,
  2356. cancel: noop
  2357. };
  2358. };
  2359. const Slide = (Splide, Components, options, event) => {
  2360. const { Move, Controller, Scroll } = Components;
  2361. const { list } = Components.Elements;
  2362. const transition = apply(style, list, "transition");
  2363. let endCallback;
  2364. function mount() {
  2365. event.bind(list, "transitionend", (e) => {
  2366. if (e.target === list && endCallback) {
  2367. cancel();
  2368. endCallback();
  2369. }
  2370. });
  2371. }
  2372. function start(index, done) {
  2373. const destination = Move.toPosition(index, true);
  2374. const position = Move.getPosition();
  2375. const speed = getSpeed(index);
  2376. if (abs(destination - position) >= 1 && speed >= 1) {
  2377. if (options.useScroll) {
  2378. Scroll.scroll(destination, speed, false, done);
  2379. } else {
  2380. transition(`transform ${speed}ms ${options.easing}`);
  2381. Move.translate(destination, true);
  2382. endCallback = done;
  2383. }
  2384. } else {
  2385. Move.jump(index);
  2386. done();
  2387. }
  2388. }
  2389. function cancel() {
  2390. transition("");
  2391. Scroll.cancel();
  2392. }
  2393. function getSpeed(index) {
  2394. const { rewindSpeed } = options;
  2395. if (Splide.is(SLIDE) && rewindSpeed) {
  2396. const prev = Controller.getIndex(true);
  2397. const end = Controller.getEnd();
  2398. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2399. return rewindSpeed;
  2400. }
  2401. }
  2402. return options.speed;
  2403. }
  2404. return {
  2405. mount,
  2406. start,
  2407. cancel
  2408. };
  2409. };
  2410. class Splide {
  2411. static defaults = {};
  2412. static STATES = STATES;
  2413. root;
  2414. event = EventInterface();
  2415. Components = {};
  2416. state = State(CREATED);
  2417. splides = [];
  2418. _o = {};
  2419. _C;
  2420. _E = {};
  2421. _T;
  2422. constructor(target, options = {}) {
  2423. const root = isString(target) ? query(document, target) : target;
  2424. assert(root, `${root} is invalid.`);
  2425. this.root = root;
  2426. options = merge({
  2427. label: getAttribute(root, ARIA_LABEL) || "",
  2428. labelledby: getAttribute(root, ARIA_LABELLEDBY) || ""
  2429. }, DEFAULTS, Splide.defaults, options);
  2430. try {
  2431. merge(options, JSON.parse(getAttribute(root, DATA_ATTRIBUTE)));
  2432. } catch (e) {
  2433. assert(false, "Invalid JSON");
  2434. }
  2435. this._o = Object.create(merge({}, options));
  2436. }
  2437. mount(Extensions = this._E, Transition = this._T) {
  2438. const { state, Components: Components2 } = this;
  2439. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2440. state.set(CREATED);
  2441. this._C = Components2;
  2442. this._T = Transition || (this.is(FADE) ? Fade : Slide);
  2443. this._E = Extensions;
  2444. const Constructors = assign({}, COMPONENTS, this._E, { Transition: this._T });
  2445. forOwn(Constructors, (Component, key) => {
  2446. const component = Component(this, Components2, this._o, this.event.create());
  2447. Components2[key] = component;
  2448. component.setup && component.setup();
  2449. });
  2450. forOwn(Components2, (component) => {
  2451. component.mount && component.mount();
  2452. });
  2453. this.emit(EVENT_MOUNTED);
  2454. addClass(this.root, CLASS_INITIALIZED);
  2455. state.set(IDLE);
  2456. this.emit(EVENT_READY);
  2457. return this;
  2458. }
  2459. sync(splide) {
  2460. this.splides.push({ splide });
  2461. splide.splides.push({ splide: this, isParent: true });
  2462. if (this.state.is(IDLE)) {
  2463. this._C.Sync.remount();
  2464. splide.Components.Sync.remount();
  2465. }
  2466. return this;
  2467. }
  2468. go(control) {
  2469. this._C.Controller.go(control);
  2470. return this;
  2471. }
  2472. jump(control) {
  2473. this._C.Controller.jump(control);
  2474. return this;
  2475. }
  2476. on(events, callback) {
  2477. this.event.on(events, callback);
  2478. return this;
  2479. }
  2480. off(events, callback) {
  2481. this.event.off(events, callback);
  2482. return this;
  2483. }
  2484. emit(event, ...args) {
  2485. this.event.emit(event, ...args);
  2486. return this;
  2487. }
  2488. add(slides, index) {
  2489. this._C.Slides.add(slides, index);
  2490. return this;
  2491. }
  2492. remove(matcher) {
  2493. this._C.Slides.remove(matcher);
  2494. return this;
  2495. }
  2496. is(type) {
  2497. return this._o.type === type;
  2498. }
  2499. refresh() {
  2500. this.emit(EVENT_REFRESH);
  2501. return this;
  2502. }
  2503. destroy(completely = true) {
  2504. const { event, state } = this;
  2505. if (state.is(CREATED)) {
  2506. this.on(EVENT_READY, this.destroy.bind(this, completely));
  2507. } else {
  2508. forOwn(this._C, (component) => {
  2509. component.destroy && component.destroy(completely);
  2510. }, true);
  2511. event.emit(EVENT_DESTROY);
  2512. event.destroy();
  2513. completely && empty(this.splides);
  2514. state.set(DESTROYED);
  2515. }
  2516. return this;
  2517. }
  2518. get options() {
  2519. return this._o;
  2520. }
  2521. set options(options) {
  2522. this._C.Breakpoints.set(options, true, true);
  2523. }
  2524. get length() {
  2525. return this._C.Slides.getLength(true);
  2526. }
  2527. get index() {
  2528. return this._C.Controller.getIndex();
  2529. }
  2530. }
  2531. return Splide;
  2532. }));