splide.js 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571
  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 { role = "region" } = options;
  695. const id = root.id || uniqueId(PROJECT_CODE);
  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. const { cloneStatus = true } = options;
  822. return curr === index || cloneStatus && curr === slideIndex;
  823. }
  824. function isVisible() {
  825. if (Splide2.is(FADE)) {
  826. return isActive();
  827. }
  828. const trackRect = rect(Elements.track);
  829. const slideRect = rect(slide);
  830. const left = resolve("left", true);
  831. const right = resolve("right", true);
  832. return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
  833. }
  834. function isWithin(from, distance) {
  835. let diff = abs(from - index);
  836. if (!isClone && (options.rewind || Splide2.is(LOOP))) {
  837. diff = min(diff, Splide2.length - diff);
  838. }
  839. return diff <= distance;
  840. }
  841. function pos() {
  842. const first = Components.Slides.get()[0];
  843. const left = resolve("left");
  844. return first ? abs(rect(slide)[left] - rect(first.slide)[left]) : 0;
  845. }
  846. function size() {
  847. return rect(slide)[resolve("width")];
  848. }
  849. const self = {
  850. index,
  851. slideIndex,
  852. slide,
  853. container,
  854. isClone,
  855. mount,
  856. destroy,
  857. update,
  858. pos,
  859. size,
  860. style: style$1,
  861. isWithin
  862. };
  863. return self;
  864. };
  865. const Slides = (Splide, Components, options, event) => {
  866. const { on, emit, bind } = event;
  867. const { slides, list } = Components.Elements;
  868. const Slides2 = [];
  869. function mount() {
  870. init();
  871. on(EVENT_REFRESH, destroy);
  872. on(EVENT_REFRESH, init);
  873. }
  874. function init() {
  875. slides.forEach((slide, index) => {
  876. register(slide, index, -1);
  877. });
  878. }
  879. function destroy() {
  880. forEach$1((Slide2) => {
  881. Slide2.destroy();
  882. });
  883. empty(Slides2);
  884. }
  885. function update() {
  886. forEach$1((Slide2) => {
  887. Slide2.update();
  888. });
  889. }
  890. function register(slide, index, slideIndex) {
  891. const object = Slide$1(Splide, index, slideIndex, slide);
  892. object.mount();
  893. Slides2.push(object);
  894. Slides2.sort((Slide1, Slide2) => Slide1.index - Slide2.index);
  895. }
  896. function get(excludeClones) {
  897. return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
  898. }
  899. function getIn(page) {
  900. const { Controller } = Components;
  901. const index = Controller.toIndex(page);
  902. const max = Controller.hasFocus() ? 1 : options.perPage;
  903. return filter((Slide2) => between(Slide2.index, index, index + max - 1));
  904. }
  905. function getAt(index) {
  906. return filter(index)[0];
  907. }
  908. function add(items, index) {
  909. forEach(items, (slide) => {
  910. if (isString(slide)) {
  911. slide = parseHtml(slide);
  912. }
  913. if (isHTMLElement(slide)) {
  914. const ref = slides[index];
  915. ref ? before(slide, ref) : append(list, slide);
  916. addClass(slide, options.classes.slide);
  917. observeImages(slide, apply(emit, EVENT_RESIZE));
  918. }
  919. });
  920. emit(EVENT_REFRESH);
  921. }
  922. function remove(matcher) {
  923. removeNode(filter(matcher).map((Slide2) => Slide2.slide));
  924. emit(EVENT_REFRESH);
  925. }
  926. function forEach$1(iteratee, excludeClones) {
  927. get(excludeClones).forEach(iteratee);
  928. }
  929. function filter(matcher) {
  930. return Slides2.filter(
  931. isFunction(matcher) ? matcher : (Slide2) => isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index)
  932. );
  933. }
  934. function style(prop, value, useContainer) {
  935. forEach$1((Slide2) => {
  936. Slide2.style(prop, value, useContainer);
  937. });
  938. }
  939. function observeImages(elm, callback) {
  940. const images = queryAll(elm, "img");
  941. let { length } = images;
  942. if (length) {
  943. images.forEach((img) => {
  944. bind(img, "load error", () => {
  945. if (!--length) {
  946. callback();
  947. }
  948. });
  949. });
  950. } else {
  951. callback();
  952. }
  953. }
  954. function getLength(excludeClones) {
  955. return excludeClones ? slides.length : Slides2.length;
  956. }
  957. function isEnough() {
  958. return Slides2.length > options.perPage;
  959. }
  960. return {
  961. mount,
  962. destroy,
  963. update,
  964. register,
  965. get,
  966. getIn,
  967. getAt,
  968. add,
  969. remove,
  970. forEach: forEach$1,
  971. filter,
  972. style,
  973. getLength,
  974. isEnough
  975. };
  976. };
  977. const Layout = (Splide, Components, options, event) => {
  978. const { on, bind, emit } = event;
  979. const { Slides } = Components;
  980. const { resolve } = Components.Direction;
  981. const { root, track, list } = Components.Elements;
  982. const { getAt, style: styleSlides } = Slides;
  983. let vertical;
  984. let rootRect;
  985. let overflow;
  986. function mount() {
  987. init();
  988. bind(window, "resize load", Throttle(apply(emit, EVENT_RESIZE)));
  989. on([EVENT_UPDATED, EVENT_REFRESH], init);
  990. on(EVENT_RESIZE, resize);
  991. }
  992. function init() {
  993. vertical = options.direction === TTB;
  994. style(root, "maxWidth", unit(options.width));
  995. style(track, resolve("paddingLeft"), cssPadding(false));
  996. style(track, resolve("paddingRight"), cssPadding(true));
  997. resize(true);
  998. }
  999. function resize(force) {
  1000. const newRect = rect(root);
  1001. if (force || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  1002. style(track, "height", cssTrackHeight());
  1003. styleSlides(resolve("marginRight"), unit(options.gap));
  1004. styleSlides("width", cssSlideWidth());
  1005. styleSlides("height", cssSlideHeight(), true);
  1006. rootRect = newRect;
  1007. emit(EVENT_RESIZED);
  1008. if (overflow !== (overflow = isOverflow())) {
  1009. toggleClass(root, CLASS_OVERFLOW, overflow);
  1010. emit(EVENT_OVERFLOW, overflow);
  1011. }
  1012. }
  1013. }
  1014. function cssPadding(right) {
  1015. const { padding } = options;
  1016. const prop = resolve(right ? "right" : "left");
  1017. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  1018. }
  1019. function cssTrackHeight() {
  1020. let height = "";
  1021. if (vertical) {
  1022. height = cssHeight();
  1023. assert(height, "height or heightRatio is missing.");
  1024. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  1025. }
  1026. return height;
  1027. }
  1028. function cssHeight() {
  1029. return unit(options.height || rect(list).width * options.heightRatio);
  1030. }
  1031. function cssSlideWidth() {
  1032. return options.autoWidth ? null : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  1033. }
  1034. function cssSlideHeight() {
  1035. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? null : cssSlideSize() : cssHeight());
  1036. }
  1037. function cssSlideSize() {
  1038. const gap = unit(options.gap);
  1039. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  1040. }
  1041. function listSize() {
  1042. return rect(list)[resolve("width")];
  1043. }
  1044. function slideSize(index = 0, withoutGap) {
  1045. const Slide = getAt(index);
  1046. return (Slide ? Slide.size() : 0) + (withoutGap ? 0 : getGap());
  1047. }
  1048. function totalSize(index, withoutGap) {
  1049. const Slide = getAt(index);
  1050. return Slide ? Slide.pos() + Slide.size() + (withoutGap ? 0 : getGap()) : 0;
  1051. }
  1052. function sliderSize(withoutGap) {
  1053. return totalSize(Splide.length - 1) - totalSize(0) + slideSize(0, withoutGap);
  1054. }
  1055. function getGap() {
  1056. const first = getAt(0);
  1057. const second = getAt(1);
  1058. return first && second ? second.pos() - first.pos() - first.size() : 0;
  1059. }
  1060. function getPadding(right) {
  1061. return parseFloat(style(
  1062. track,
  1063. resolve(`padding${right ? "Right" : "Left"}`)
  1064. )) || 0;
  1065. }
  1066. function isOverflow() {
  1067. return Splide.is(FADE) || sliderSize(true) > listSize();
  1068. }
  1069. return {
  1070. mount,
  1071. resize,
  1072. listSize,
  1073. slideSize,
  1074. sliderSize,
  1075. totalSize,
  1076. getPadding,
  1077. isOverflow
  1078. };
  1079. };
  1080. const MULTIPLIER = 2;
  1081. const Clones = (Splide, Components, options, event) => {
  1082. const { on } = event;
  1083. const { Elements, Slides, Layout: { resize } } = Components;
  1084. const { resolve } = Components.Direction;
  1085. const clones = [];
  1086. let cloneCount;
  1087. function mount() {
  1088. on(EVENT_REFRESH, remount);
  1089. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1090. if (cloneCount = computeCloneCount()) {
  1091. generate(cloneCount);
  1092. resize(true);
  1093. }
  1094. }
  1095. function remount() {
  1096. destroy();
  1097. mount();
  1098. resize(true);
  1099. }
  1100. function destroy() {
  1101. removeNode(clones);
  1102. empty(clones);
  1103. event.destroy();
  1104. }
  1105. function observe() {
  1106. const count = computeCloneCount();
  1107. if (cloneCount !== count) {
  1108. if (cloneCount < count || !count) {
  1109. !count && Splide.go(0);
  1110. event.emit(EVENT_REFRESH);
  1111. }
  1112. }
  1113. }
  1114. function generate(count) {
  1115. const slides = Slides.get().slice();
  1116. const { length } = slides;
  1117. if (length) {
  1118. while (slides.length < count) {
  1119. push(slides, slides);
  1120. }
  1121. push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  1122. const isHead = index < count;
  1123. const clone = cloneDeep(Slide.slide, index);
  1124. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1125. push(clones, clone);
  1126. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1127. });
  1128. }
  1129. }
  1130. function cloneDeep(elm, index) {
  1131. const clone = elm.cloneNode(true);
  1132. addClass(clone, options.classes.clone);
  1133. clone.id = `${Splide.root.id}-clone${pad(index + 1)}`;
  1134. return clone;
  1135. }
  1136. function computeCloneCount() {
  1137. let { clones: clones2 } = options;
  1138. if (!Splide.is(LOOP)) {
  1139. clones2 = 0;
  1140. } else if (isUndefined(clones2)) {
  1141. const fixedSize = options[resolve("fixedWidth")] && Components.Layout.slideSize(0);
  1142. const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1143. clones2 = fixedCount || options[resolve("autoWidth")] && Splide.length || options.perPage * MULTIPLIER;
  1144. }
  1145. return clones2;
  1146. }
  1147. return {
  1148. mount,
  1149. destroy
  1150. };
  1151. };
  1152. const Move = (Splide, Components, options, event) => {
  1153. const { on, emit } = event;
  1154. const { set } = Splide.state;
  1155. const { Slides } = Components;
  1156. const { slideSize, getPadding, listSize, sliderSize, totalSize } = Components.Layout;
  1157. const { resolve, orient } = Components.Direction;
  1158. const { list, track } = Components.Elements;
  1159. let Transition;
  1160. function mount() {
  1161. Transition = Components.Transition;
  1162. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1163. }
  1164. function reposition() {
  1165. if (!Components.Controller.isBusy()) {
  1166. Components.Scroll.cancel();
  1167. jump(Splide.index);
  1168. Components.Slides.update();
  1169. }
  1170. }
  1171. function move(dest, index, prev, callback) {
  1172. if (dest !== index && canShift(dest > prev)) {
  1173. cancel();
  1174. translate(shift(getPosition(), dest > prev), true);
  1175. } else {
  1176. Transition.cancel();
  1177. }
  1178. set(MOVING);
  1179. emit(EVENT_MOVE, index, prev, dest);
  1180. Transition.start(index, () => {
  1181. set(IDLE);
  1182. emit(EVENT_MOVED, index, prev, dest);
  1183. callback && callback();
  1184. });
  1185. }
  1186. function jump(index) {
  1187. translate(toPosition(index, true));
  1188. }
  1189. function translate(position, preventLoop) {
  1190. if (!Splide.is(FADE)) {
  1191. const destination = preventLoop ? position : loop(position);
  1192. style(list, "transform", `translate${resolve("X")}(${destination}px)`);
  1193. position !== destination && emit(EVENT_SHIFTED);
  1194. }
  1195. }
  1196. function loop(position) {
  1197. if (Splide.is(LOOP)) {
  1198. const exceededMax = exceededLimit(true, position);
  1199. const exceededMin = exceededLimit(false, position);
  1200. if (exceededMin || exceededMax) {
  1201. position = shift(position, exceededMax);
  1202. }
  1203. }
  1204. return position;
  1205. }
  1206. function shift(position, backwards) {
  1207. const excess = position - getLimit(backwards);
  1208. const size = sliderSize();
  1209. position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
  1210. return position;
  1211. }
  1212. function cancel() {
  1213. translate(getPosition(), true);
  1214. Transition.cancel();
  1215. }
  1216. function toIndex(position) {
  1217. const slides = Slides.get();
  1218. let index = 0;
  1219. let minDistance = Infinity;
  1220. for (let i = 0; i < slides.length; i++) {
  1221. const slideIndex = slides[i].index;
  1222. const distance = abs(toPosition(slideIndex, true) - position);
  1223. if (distance <= minDistance) {
  1224. minDistance = distance;
  1225. index = slideIndex;
  1226. } else {
  1227. break;
  1228. }
  1229. }
  1230. return index;
  1231. }
  1232. function toPosition(index, trimming) {
  1233. const position = orient(totalSize(index - 1) - offset(index));
  1234. return trimming ? trim(position) : position;
  1235. }
  1236. function getPosition() {
  1237. const left = resolve("left");
  1238. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1239. }
  1240. function trim(position) {
  1241. if (options.trimSpace && Splide.is(SLIDE)) {
  1242. position = clamp(position, 0, orient(sliderSize(true) - listSize()));
  1243. }
  1244. return position;
  1245. }
  1246. function offset(index) {
  1247. const { focus } = options;
  1248. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1249. }
  1250. function getLimit(max) {
  1251. return toPosition(max ? Components.Controller.getEnd() : 0, !!options.trimSpace);
  1252. }
  1253. function canShift(backwards) {
  1254. const padding = getPadding(false);
  1255. const shifted = orient(shift(getPosition(), backwards));
  1256. return backwards ? shifted >= padding : shifted <= list[resolve("scrollWidth")] - rect(track)[resolve("width")] + padding;
  1257. }
  1258. function exceededLimit(max, position = getPosition()) {
  1259. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1260. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1261. return exceededMin || exceededMax;
  1262. }
  1263. return {
  1264. mount,
  1265. move,
  1266. jump,
  1267. translate,
  1268. shift,
  1269. cancel,
  1270. toIndex,
  1271. toPosition,
  1272. getPosition,
  1273. getLimit,
  1274. exceededLimit,
  1275. reposition,
  1276. canShift
  1277. };
  1278. };
  1279. const Controller = (Splide, Components, options, event) => {
  1280. const { on, emit } = event;
  1281. const { Move } = Components;
  1282. const { getPosition, getLimit, toPosition } = Move;
  1283. const { isEnough, getLength } = Components.Slides;
  1284. const { omitEnd } = options;
  1285. const isLoop = Splide.is(LOOP);
  1286. const isSlide = Splide.is(SLIDE);
  1287. const getNext = apply(getAdjacent, false);
  1288. const getPrev = apply(getAdjacent, true);
  1289. let currIndex = options.start || 0;
  1290. let endIndex;
  1291. let prevIndex = currIndex;
  1292. let slideCount;
  1293. let perMove;
  1294. let perPage;
  1295. function mount() {
  1296. init();
  1297. on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], init);
  1298. on(EVENT_RESIZED, onResized);
  1299. }
  1300. function init() {
  1301. slideCount = getLength(true);
  1302. perMove = options.perMove;
  1303. perPage = options.perPage;
  1304. endIndex = getEnd();
  1305. const end = omitEnd ? endIndex : slideCount - 1;
  1306. const index = clamp(currIndex, 0, end);
  1307. prevIndex = index;
  1308. if (index !== currIndex) {
  1309. currIndex = index;
  1310. Move.reposition();
  1311. }
  1312. }
  1313. function onResized() {
  1314. if (endIndex !== getEnd()) {
  1315. emit(EVENT_END_INDEX_CHANGED);
  1316. }
  1317. }
  1318. function go(control, allowSameIndex, callback) {
  1319. if (!isBusy()) {
  1320. const dest = parse(control);
  1321. const index = loop(dest);
  1322. const validIndex = index > -1 && (allowSameIndex || index !== currIndex);
  1323. const canMove = dest === index || Move.canShift(dest > prevIndex);
  1324. if (validIndex && canMove) {
  1325. setIndex(index);
  1326. Move.move(dest, index, prevIndex, callback);
  1327. }
  1328. }
  1329. }
  1330. function jump(control) {
  1331. const { set } = Components.Breakpoints;
  1332. const { speed } = options;
  1333. set({ speed: 0 });
  1334. go(control);
  1335. set({ speed });
  1336. }
  1337. function scroll(destination, duration, snap, callback) {
  1338. Components.Scroll.scroll(destination, duration, snap, () => {
  1339. const index = loop(Move.toIndex(getPosition()));
  1340. setIndex(omitEnd ? min(index, endIndex) : index);
  1341. callback && callback();
  1342. });
  1343. }
  1344. function parse(control) {
  1345. let index = currIndex;
  1346. if (isString(control)) {
  1347. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1348. if (indicator === "+" || indicator === "-") {
  1349. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
  1350. } else if (indicator === ">") {
  1351. index = number ? toIndex(+number) : getNext(true);
  1352. } else if (indicator === "<") {
  1353. index = getPrev(true);
  1354. }
  1355. } else {
  1356. index = isLoop ? control : clamp(control, 0, endIndex);
  1357. }
  1358. return index;
  1359. }
  1360. function getAdjacent(prev, destination) {
  1361. const number = perMove || (hasFocus() ? 1 : perPage);
  1362. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex, !(perMove || hasFocus()));
  1363. if (dest === -1 && isSlide) {
  1364. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1365. return prev ? 0 : endIndex;
  1366. }
  1367. }
  1368. return destination ? dest : loop(dest);
  1369. }
  1370. function computeDestIndex(dest, from, snapPage) {
  1371. if (isEnough() || hasFocus()) {
  1372. const index = computeMovableDestIndex(dest);
  1373. if (index !== dest) {
  1374. from = dest;
  1375. dest = index;
  1376. snapPage = false;
  1377. }
  1378. if (dest < 0 || dest > endIndex) {
  1379. if (!perMove && (between(0, dest, from, true) || between(endIndex, from, dest, true))) {
  1380. dest = toIndex(toPage(dest));
  1381. } else {
  1382. if (isLoop) {
  1383. dest = snapPage ? dest < 0 ? -(slideCount % perPage || perPage) : slideCount : dest;
  1384. } else if (options.rewind) {
  1385. dest = dest < 0 ? endIndex : 0;
  1386. } else {
  1387. dest = -1;
  1388. }
  1389. }
  1390. } else {
  1391. if (snapPage && dest !== from) {
  1392. dest = toIndex(toPage(from) + (dest < from ? -1 : 1));
  1393. }
  1394. }
  1395. } else {
  1396. dest = -1;
  1397. }
  1398. return dest;
  1399. }
  1400. function computeMovableDestIndex(dest) {
  1401. if (isSlide && options.trimSpace === "move" && dest !== currIndex) {
  1402. const position = getPosition();
  1403. while (position === toPosition(dest, true) && between(dest, 0, Splide.length - 1, !options.rewind)) {
  1404. dest < currIndex ? --dest : ++dest;
  1405. }
  1406. }
  1407. return dest;
  1408. }
  1409. function loop(index) {
  1410. return isLoop ? (index + slideCount) % slideCount || 0 : index;
  1411. }
  1412. function getEnd() {
  1413. let end = slideCount - (hasFocus() || isLoop && perMove ? 1 : perPage);
  1414. while (omitEnd && end-- > 0) {
  1415. if (toPosition(slideCount - 1, true) !== toPosition(end, true)) {
  1416. end++;
  1417. break;
  1418. }
  1419. }
  1420. return clamp(end, 0, slideCount - 1);
  1421. }
  1422. function toIndex(page) {
  1423. return clamp(hasFocus() ? page : perPage * page, 0, endIndex);
  1424. }
  1425. function toPage(index) {
  1426. return hasFocus() ? min(index, endIndex) : floor((index >= endIndex ? slideCount - 1 : index) / perPage);
  1427. }
  1428. function toDest(destination) {
  1429. const closest = Move.toIndex(destination);
  1430. return isSlide ? clamp(closest, 0, endIndex) : closest;
  1431. }
  1432. function setIndex(index) {
  1433. if (index !== currIndex) {
  1434. prevIndex = currIndex;
  1435. currIndex = index;
  1436. }
  1437. }
  1438. function getIndex(prev) {
  1439. return prev ? prevIndex : currIndex;
  1440. }
  1441. function hasFocus() {
  1442. return !isUndefined(options.focus) || options.isNavigation;
  1443. }
  1444. function isBusy() {
  1445. return Splide.state.is([MOVING, SCROLLING]) && !!options.waitForTransition;
  1446. }
  1447. return {
  1448. mount,
  1449. go,
  1450. jump,
  1451. scroll,
  1452. getNext,
  1453. getPrev,
  1454. getAdjacent,
  1455. getEnd,
  1456. setIndex,
  1457. getIndex,
  1458. toIndex,
  1459. toPage,
  1460. toDest,
  1461. hasFocus,
  1462. isBusy
  1463. };
  1464. };
  1465. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1466. 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";
  1467. const SIZE = 40;
  1468. const Arrows = (Splide, Components, options, event) => {
  1469. const { on, bind, emit } = event;
  1470. const { classes, i18n } = options;
  1471. const { Elements, Controller } = Components;
  1472. const { arrows: placeholder, track } = Elements;
  1473. let wrapper = placeholder;
  1474. let prev = Elements.prev;
  1475. let next = Elements.next;
  1476. let created;
  1477. let wrapperClasses;
  1478. const arrows = {};
  1479. function mount() {
  1480. init();
  1481. on(EVENT_UPDATED, remount);
  1482. }
  1483. function remount() {
  1484. destroy();
  1485. mount();
  1486. }
  1487. function init() {
  1488. const { arrows: enabled = true } = options;
  1489. if (enabled && !(prev && next)) {
  1490. createArrows();
  1491. }
  1492. if (prev && next) {
  1493. assign(arrows, { prev, next });
  1494. display(wrapper, enabled ? "" : "none");
  1495. addClass(wrapper, wrapperClasses = `${CLASS_ARROWS}--${options.direction}`);
  1496. if (enabled) {
  1497. listen();
  1498. update();
  1499. setAttribute([prev, next], ARIA_CONTROLS, track.id);
  1500. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1501. }
  1502. }
  1503. }
  1504. function destroy() {
  1505. event.destroy();
  1506. removeClass(wrapper, wrapperClasses);
  1507. if (created) {
  1508. removeNode(placeholder ? [prev, next] : wrapper);
  1509. prev = next = null;
  1510. } else {
  1511. removeAttribute([prev, next], ALL_ATTRIBUTES);
  1512. }
  1513. }
  1514. function listen() {
  1515. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_REFRESH, EVENT_SCROLLED, EVENT_END_INDEX_CHANGED], update);
  1516. bind(next, "click", apply(go, ">"));
  1517. bind(prev, "click", apply(go, "<"));
  1518. }
  1519. function go(control) {
  1520. Controller.go(control, true);
  1521. }
  1522. function createArrows() {
  1523. wrapper = placeholder || create("div", classes.arrows);
  1524. prev = createArrow(true);
  1525. next = createArrow(false);
  1526. created = true;
  1527. append(wrapper, [prev, next]);
  1528. !placeholder && before(wrapper, track);
  1529. }
  1530. function createArrow(prev2) {
  1531. 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}" />`;
  1532. return parseHtml(arrow);
  1533. }
  1534. function update() {
  1535. if (prev && next) {
  1536. const index = Splide.index;
  1537. const prevIndex = Controller.getPrev();
  1538. const nextIndex = Controller.getNext();
  1539. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1540. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1541. prev.disabled = prevIndex < 0;
  1542. next.disabled = nextIndex < 0;
  1543. setAttribute(prev, ARIA_LABEL, prevLabel);
  1544. setAttribute(next, ARIA_LABEL, nextLabel);
  1545. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1546. }
  1547. }
  1548. return {
  1549. arrows,
  1550. mount,
  1551. destroy,
  1552. update
  1553. };
  1554. };
  1555. const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
  1556. const Autoplay = (Splide, Components, options, event) => {
  1557. const { on, bind, emit } = event;
  1558. const { interval: duration = 5e3, pauseOnHover = true, pauseOnFocus = true, resetProgress = true } = options;
  1559. const interval = RequestInterval(duration, Splide.go.bind(Splide, ">"), onAnimationFrame);
  1560. const { isPaused } = interval;
  1561. const { Elements, Elements: { root, toggle } } = Components;
  1562. const { autoplay } = options;
  1563. let hovered;
  1564. let focused;
  1565. let stopped = autoplay === "pause";
  1566. function mount() {
  1567. if (autoplay) {
  1568. listen();
  1569. toggle && setAttribute(toggle, ARIA_CONTROLS, Elements.track.id);
  1570. stopped || play();
  1571. update();
  1572. }
  1573. }
  1574. function listen() {
  1575. if (pauseOnHover) {
  1576. bind(root, "mouseenter mouseleave", (e) => {
  1577. hovered = e.type === "mouseenter";
  1578. autoToggle();
  1579. });
  1580. }
  1581. if (pauseOnFocus) {
  1582. bind(root, "focusin focusout", (e) => {
  1583. focused = e.type === "focusin";
  1584. autoToggle();
  1585. });
  1586. }
  1587. if (toggle) {
  1588. bind(toggle, "click", () => {
  1589. stopped ? play() : pause(true);
  1590. });
  1591. }
  1592. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1593. on(EVENT_MOVE, onMove);
  1594. }
  1595. function play() {
  1596. if (isPaused() && Components.Slides.isEnough()) {
  1597. interval.start(!resetProgress);
  1598. focused = hovered = stopped = false;
  1599. update();
  1600. emit(EVENT_AUTOPLAY_PLAY);
  1601. }
  1602. }
  1603. function pause(stop = true) {
  1604. stopped = !!stop;
  1605. update();
  1606. if (!isPaused()) {
  1607. interval.pause();
  1608. emit(EVENT_AUTOPLAY_PAUSE);
  1609. }
  1610. }
  1611. function autoToggle() {
  1612. if (!stopped) {
  1613. hovered || focused ? pause(false) : play();
  1614. }
  1615. }
  1616. function update() {
  1617. if (toggle) {
  1618. toggleClass(toggle, CLASS_ACTIVE, !stopped);
  1619. setAttribute(toggle, ARIA_LABEL, options.i18n[stopped ? "play" : "pause"]);
  1620. }
  1621. }
  1622. function onAnimationFrame(rate) {
  1623. const { bar } = Elements;
  1624. bar && style(bar, "width", `${rate * 100}%`);
  1625. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1626. }
  1627. function onMove(index) {
  1628. const Slide = Components.Slides.getAt(index);
  1629. interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1630. }
  1631. return {
  1632. mount,
  1633. destroy: interval.cancel,
  1634. play,
  1635. pause,
  1636. isPaused
  1637. };
  1638. };
  1639. const BOUNCE_DIFF_THRESHOLD = 10;
  1640. const BOUNCE_DURATION = 600;
  1641. const FRICTION_FACTOR = 0.6;
  1642. const BASE_VELOCITY = 1.5;
  1643. const MIN_DURATION = 800;
  1644. const Scroll = (Splide, Components, options, event) => {
  1645. const { on, emit } = event;
  1646. const { state: { set } } = Splide;
  1647. const { Move } = Components;
  1648. const { getPosition, getLimit, exceededLimit, translate } = Move;
  1649. const isSlide = Splide.is(SLIDE);
  1650. let interval;
  1651. let callback;
  1652. let friction = 1;
  1653. function mount() {
  1654. on(EVENT_MOVE, clear);
  1655. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1656. }
  1657. function scroll(destination, duration, snap, onScrolled, noConstrain) {
  1658. const from = getPosition();
  1659. clear();
  1660. if (snap && (!isSlide || !exceededLimit())) {
  1661. const size = Components.Layout.sliderSize();
  1662. const offset = sign(destination) * size * floor(abs(destination) / size) || 0;
  1663. destination = Move.toPosition(Components.Controller.toDest(destination % size)) + offset;
  1664. }
  1665. const immediately = approximatelyEqual(from, destination, 1) || duration === 0;
  1666. friction = 1;
  1667. duration = immediately ? 0 : duration || max(abs(destination - from) / BASE_VELOCITY, MIN_DURATION);
  1668. callback = onScrolled;
  1669. interval = RequestInterval(duration, onEnd, apply(update, from, destination, noConstrain), 1);
  1670. set(SCROLLING);
  1671. emit(EVENT_SCROLL);
  1672. interval.start();
  1673. }
  1674. function onEnd() {
  1675. set(IDLE);
  1676. callback && callback();
  1677. emit(EVENT_SCROLLED);
  1678. }
  1679. function update(from, to, noConstrain, rate) {
  1680. const position = getPosition();
  1681. const target = from + (to - from) * easing(rate);
  1682. const diff = (target - position) * friction;
  1683. translate(position + diff);
  1684. if (isSlide && !noConstrain && exceededLimit()) {
  1685. friction *= FRICTION_FACTOR;
  1686. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1687. scroll(getLimit(exceededLimit(true)), BOUNCE_DURATION, false, callback, true);
  1688. }
  1689. }
  1690. }
  1691. function clear() {
  1692. if (interval) {
  1693. interval.cancel();
  1694. }
  1695. }
  1696. function cancel() {
  1697. if (interval && !interval.isPaused()) {
  1698. clear();
  1699. onEnd();
  1700. }
  1701. }
  1702. function easing(t) {
  1703. const { easingFunc } = options;
  1704. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1705. }
  1706. return {
  1707. mount,
  1708. destroy: clear,
  1709. scroll,
  1710. cancel
  1711. };
  1712. };
  1713. const SCROLL_LISTENER_OPTIONS = { passive: false, capture: true };
  1714. const Drag = (Splide, Components, options, event) => {
  1715. const { on, emit, bind } = event;
  1716. const binder = event.create();
  1717. const { state } = Splide;
  1718. const { Move, Scroll, Controller, Elements: { track }, Breakpoints: { reduce } } = Components;
  1719. const { resolve, orient } = Components.Direction;
  1720. const { getPosition, exceededLimit } = Move;
  1721. let basePosition;
  1722. let baseEvent;
  1723. let prevBaseEvent;
  1724. let isFree;
  1725. let dragging;
  1726. let exceeded = false;
  1727. let clickPrevented;
  1728. let disabled;
  1729. let target;
  1730. function mount() {
  1731. bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1732. bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1733. bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
  1734. bind(track, "click", onClick, { capture: true });
  1735. bind(track, "dragstart", prevent);
  1736. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1737. }
  1738. function init() {
  1739. const { drag } = options;
  1740. disable(!drag);
  1741. isFree = drag === "free";
  1742. }
  1743. function onPointerDown(e) {
  1744. clickPrevented = false;
  1745. if (!disabled) {
  1746. const isTouch = isTouchEvent(e);
  1747. if (isDraggable(e.target) && (isTouch || !e.button)) {
  1748. if (!Controller.isBusy()) {
  1749. target = isTouch ? track : window;
  1750. dragging = state.is([MOVING, SCROLLING]);
  1751. prevBaseEvent = null;
  1752. binder.bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
  1753. binder.bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
  1754. Move.cancel();
  1755. Scroll.cancel();
  1756. save(e);
  1757. } else {
  1758. prevent(e, true);
  1759. }
  1760. }
  1761. }
  1762. }
  1763. function onPointerMove(e) {
  1764. if (!state.is(DRAGGING)) {
  1765. state.set(DRAGGING);
  1766. emit(EVENT_DRAG);
  1767. }
  1768. if (shouldRelease(e)) {
  1769. return onPointerUp(e);
  1770. }
  1771. if (e.cancelable) {
  1772. if (dragging) {
  1773. Move.translate(basePosition + constrain(diffCoord(e)));
  1774. const expired = diffTime(e) > LOG_INTERVAL;
  1775. const hasExceeded = exceeded !== (exceeded = exceededLimit());
  1776. if (expired || hasExceeded) {
  1777. save(e);
  1778. }
  1779. clickPrevented = true;
  1780. emit(EVENT_DRAGGING);
  1781. prevent(e);
  1782. } else if (isSliderDirection(e)) {
  1783. dragging = shouldStart(e);
  1784. prevent(e);
  1785. }
  1786. }
  1787. }
  1788. function onPointerUp(e) {
  1789. if (state.is(DRAGGING)) {
  1790. state.set(IDLE);
  1791. emit(EVENT_DRAGGED);
  1792. }
  1793. if (dragging) {
  1794. move(e);
  1795. prevent(e);
  1796. }
  1797. binder.destroy();
  1798. dragging = false;
  1799. exceeded = false;
  1800. }
  1801. function onClick(e) {
  1802. if (!disabled && clickPrevented) {
  1803. prevent(e, true);
  1804. }
  1805. }
  1806. function save(e) {
  1807. prevBaseEvent = baseEvent;
  1808. baseEvent = e;
  1809. basePosition = getPosition();
  1810. }
  1811. function move(e) {
  1812. const { updateOnDragged = true } = options;
  1813. const velocity = computeVelocity(e);
  1814. const destination = computeDestination(velocity);
  1815. const rewind = options.rewind && options.rewindByDrag;
  1816. const scroll = updateOnDragged ? Controller.scroll : Scroll.scroll;
  1817. reduce(false);
  1818. if (isFree) {
  1819. scroll(destination, void 0, options.snap);
  1820. } else if (Splide.is(FADE)) {
  1821. Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
  1822. } else if (Splide.is(SLIDE) && exceeded && rewind) {
  1823. Controller.go(exceededLimit(true) ? ">" : "<");
  1824. } else {
  1825. Controller.go(Controller.toDest(destination), true);
  1826. }
  1827. reduce(true);
  1828. }
  1829. function shouldRelease(e) {
  1830. if (options.releaseTouch && Splide.is(SLIDE) && isTouchEvent(e)) {
  1831. const { index } = Splide;
  1832. const diff = diffCoord(e);
  1833. if (exceededLimit() || index === 0 && diff > 0 || index === Splide.length - 1 && diff < 0) {
  1834. return true;
  1835. }
  1836. }
  1837. return false;
  1838. }
  1839. function shouldStart(e) {
  1840. const { dragMinThreshold: thresholds } = options;
  1841. const isObj = isObject(thresholds);
  1842. const mouse = isObj && thresholds.mouse || 0;
  1843. const touch = (isObj ? thresholds.touch : +thresholds) || 10;
  1844. return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
  1845. }
  1846. function isSliderDirection(e) {
  1847. return abs(diffCoord(e)) > abs(diffCoord(e, true));
  1848. }
  1849. function computeVelocity(e) {
  1850. if (Splide.is(LOOP) || !exceeded) {
  1851. const time = diffTime(e);
  1852. if (time && time < LOG_INTERVAL) {
  1853. return diffCoord(e) / time;
  1854. }
  1855. }
  1856. return 0;
  1857. }
  1858. function computeDestination(velocity) {
  1859. return getPosition() + sign(velocity) * min(
  1860. abs(velocity) * (options.flickPower || 600),
  1861. isFree ? Infinity : Components.Layout.listSize() * (options.flickMaxPages || 1)
  1862. );
  1863. }
  1864. function diffCoord(e, orthogonal) {
  1865. return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
  1866. }
  1867. function diffTime(e) {
  1868. return timeOf(e) - timeOf(getBaseEvent(e));
  1869. }
  1870. function getBaseEvent(e) {
  1871. return baseEvent === e && prevBaseEvent || baseEvent;
  1872. }
  1873. function coordOf(e, orthogonal) {
  1874. return (isTouchEvent(e) ? e.changedTouches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
  1875. }
  1876. function constrain(diff) {
  1877. return diff / (exceeded && Splide.is(SLIDE) ? FRICTION : 1);
  1878. }
  1879. function isDraggable(target2) {
  1880. const { noDrag } = options;
  1881. return !matches(target2, `.${CLASS_PAGINATION_PAGE}, .${CLASS_ARROW}`) && (!noDrag || !matches(target2, noDrag));
  1882. }
  1883. function isTouchEvent(e) {
  1884. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1885. }
  1886. function isDragging() {
  1887. return dragging;
  1888. }
  1889. function disable(value) {
  1890. disabled = value;
  1891. }
  1892. return {
  1893. mount,
  1894. disable,
  1895. isDragging
  1896. };
  1897. };
  1898. const KEYBOARD_EVENT = "keydown";
  1899. const Keyboard = (Splide, Components, options, event) => {
  1900. const { on, bind, destroy } = event;
  1901. const { root } = Splide;
  1902. const { resolve } = Components.Direction;
  1903. let target;
  1904. let disabled;
  1905. function mount() {
  1906. init();
  1907. on(EVENT_UPDATED, destroy);
  1908. on(EVENT_UPDATED, init);
  1909. on(EVENT_MOVE, onMove);
  1910. }
  1911. function init() {
  1912. const { keyboard } = options;
  1913. if (keyboard) {
  1914. target = keyboard === "global" ? window : root;
  1915. bind(target, KEYBOARD_EVENT, onKeydown);
  1916. }
  1917. }
  1918. function disable(value) {
  1919. disabled = value;
  1920. }
  1921. function onMove() {
  1922. const _disabled = disabled;
  1923. disabled = true;
  1924. nextTick(() => {
  1925. disabled = _disabled;
  1926. });
  1927. }
  1928. function onKeydown(e) {
  1929. if (!disabled) {
  1930. if (e.key === resolve(ARROW_LEFT)) {
  1931. Splide.go("<");
  1932. } else if (e.key === resolve(ARROW_RIGHT)) {
  1933. Splide.go(">");
  1934. }
  1935. }
  1936. }
  1937. return {
  1938. mount,
  1939. destroy,
  1940. disable
  1941. };
  1942. };
  1943. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1944. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1945. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1946. const LazyLoad = (Splide, Components, options, event) => {
  1947. const { on, off, bind, emit } = event;
  1948. const isSequential = options.lazyLoad === "sequential";
  1949. const events = [EVENT_MOVED, EVENT_SCROLLED];
  1950. let entries = [];
  1951. function mount() {
  1952. if (options.lazyLoad) {
  1953. init();
  1954. on(EVENT_REFRESH, init);
  1955. }
  1956. }
  1957. function init() {
  1958. empty(entries);
  1959. register();
  1960. if (isSequential) {
  1961. loadNext();
  1962. } else {
  1963. off(events);
  1964. on(events, check);
  1965. check();
  1966. }
  1967. }
  1968. function register() {
  1969. Components.Slides.forEach((Slide) => {
  1970. queryAll(Slide.slide, IMAGE_SELECTOR).forEach((img) => {
  1971. const src = getAttribute(img, SRC_DATA_ATTRIBUTE);
  1972. const srcset = getAttribute(img, SRCSET_DATA_ATTRIBUTE);
  1973. if (src !== img.src || srcset !== img.srcset) {
  1974. const className = options.classes.spinner;
  1975. const parent = img.parentElement;
  1976. const spinner = child(parent, `.${className}`) || create("span", className, parent);
  1977. entries.push([img, Slide, spinner]);
  1978. img.src || display(img, "none");
  1979. }
  1980. });
  1981. });
  1982. }
  1983. function check() {
  1984. entries = entries.filter((data) => {
  1985. const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  1986. return data[1].isWithin(Splide.index, distance) ? load(data) : true;
  1987. });
  1988. entries.length || off(events);
  1989. }
  1990. function load(data) {
  1991. const [img] = data;
  1992. addClass(data[1].slide, CLASS_LOADING);
  1993. bind(img, "load error", apply(onLoad, data));
  1994. setAttribute(img, "src", getAttribute(img, SRC_DATA_ATTRIBUTE));
  1995. setAttribute(img, "srcset", getAttribute(img, SRCSET_DATA_ATTRIBUTE));
  1996. removeAttribute(img, SRC_DATA_ATTRIBUTE);
  1997. removeAttribute(img, SRCSET_DATA_ATTRIBUTE);
  1998. }
  1999. function onLoad(data, e) {
  2000. const [img, Slide] = data;
  2001. removeClass(Slide.slide, CLASS_LOADING);
  2002. if (e.type !== "error") {
  2003. removeNode(data[2]);
  2004. display(img, "");
  2005. emit(EVENT_LAZYLOAD_LOADED, img, Slide);
  2006. emit(EVENT_RESIZE);
  2007. } else {
  2008. emit(EVENT_LAZYLOAD_ERROR, img, Slide);
  2009. }
  2010. isSequential && loadNext();
  2011. }
  2012. function loadNext() {
  2013. entries.length && load(entries.shift());
  2014. }
  2015. return {
  2016. mount,
  2017. destroy: apply(empty, entries),
  2018. check
  2019. };
  2020. };
  2021. const Pagination = (Splide, Components, options, event) => {
  2022. const { on, emit, bind } = event;
  2023. const { Slides, Elements, Controller } = Components;
  2024. const { hasFocus, getIndex, go } = Controller;
  2025. const { resolve } = Components.Direction;
  2026. const { pagination: placeholder } = Elements;
  2027. const items = [];
  2028. let list;
  2029. let paginationClasses;
  2030. function mount() {
  2031. destroy();
  2032. on([EVENT_UPDATED, EVENT_REFRESH, EVENT_END_INDEX_CHANGED], mount);
  2033. const { pagination: enabled = true } = options;
  2034. placeholder && display(placeholder, enabled ? "" : "none");
  2035. if (enabled) {
  2036. on([EVENT_MOVE, EVENT_SCROLL, EVENT_SCROLLED], update);
  2037. createPagination();
  2038. update();
  2039. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide.index));
  2040. }
  2041. }
  2042. function destroy() {
  2043. if (list) {
  2044. removeNode(placeholder ? slice(list.children) : list);
  2045. removeClass(list, paginationClasses);
  2046. empty(items);
  2047. list = null;
  2048. }
  2049. event.destroy();
  2050. }
  2051. function createPagination() {
  2052. const { length } = Splide;
  2053. const { classes, i18n, perPage, paginationKeyboard = true } = options;
  2054. const max = hasFocus() ? Controller.getEnd() + 1 : ceil(length / perPage);
  2055. list = placeholder || create("ul", classes.pagination, Elements.track.parentElement);
  2056. addClass(list, paginationClasses = `${CLASS_PAGINATION}--${getDirection()}`);
  2057. setAttribute(list, ROLE, "tablist");
  2058. setAttribute(list, ARIA_LABEL, i18n.select);
  2059. setAttribute(list, ARIA_ORIENTATION, getDirection() === TTB ? "vertical" : "");
  2060. for (let i = 0; i < max; i++) {
  2061. const li = create("li", null, list);
  2062. const button = create("button", { class: classes.page, type: "button" }, li);
  2063. const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
  2064. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  2065. bind(button, "click", apply(onClick, i));
  2066. if (paginationKeyboard) {
  2067. bind(button, "keydown", apply(onKeydown, i));
  2068. }
  2069. setAttribute(li, ROLE, "presentation");
  2070. setAttribute(button, ROLE, "tab");
  2071. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  2072. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  2073. setAttribute(button, TAB_INDEX, -1);
  2074. items.push({ li, button, page: i });
  2075. }
  2076. }
  2077. function onClick(page) {
  2078. go(`>${page}`, true);
  2079. }
  2080. function onKeydown(page, e) {
  2081. const { length } = items;
  2082. const { key } = e;
  2083. const dir = getDirection();
  2084. let nextPage = -1;
  2085. if (key === resolve(ARROW_RIGHT, false, dir)) {
  2086. nextPage = ++page % length;
  2087. } else if (key === resolve(ARROW_LEFT, false, dir)) {
  2088. nextPage = (--page + length) % length;
  2089. } else if (key === "Home") {
  2090. nextPage = 0;
  2091. } else if (key === "End") {
  2092. nextPage = length - 1;
  2093. }
  2094. const item = items[nextPage];
  2095. if (item) {
  2096. focus(item.button);
  2097. go(`>${nextPage}`);
  2098. prevent(e, true);
  2099. }
  2100. }
  2101. function getDirection() {
  2102. return options.paginationDirection || options.direction;
  2103. }
  2104. function getAt(index) {
  2105. return items[Controller.toPage(index)];
  2106. }
  2107. function update() {
  2108. const prev = getAt(getIndex(true));
  2109. const curr = getAt(getIndex());
  2110. if (prev) {
  2111. const { button } = prev;
  2112. removeClass(button, CLASS_ACTIVE);
  2113. removeAttribute(button, ARIA_SELECTED);
  2114. setAttribute(button, TAB_INDEX, -1);
  2115. }
  2116. if (curr) {
  2117. const { button } = curr;
  2118. addClass(button, CLASS_ACTIVE);
  2119. setAttribute(button, ARIA_SELECTED, true);
  2120. setAttribute(button, TAB_INDEX, "");
  2121. }
  2122. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  2123. }
  2124. return {
  2125. items,
  2126. mount,
  2127. destroy,
  2128. getAt,
  2129. update
  2130. };
  2131. };
  2132. const TRIGGER_KEYS = [" ", "Enter"];
  2133. const Sync = (Splide2, Components, options, event) => {
  2134. const { isNavigation, slideFocus } = options;
  2135. const events = [];
  2136. function mount() {
  2137. Splide2.splides.forEach((target) => {
  2138. if (!target.isParent) {
  2139. sync(Splide2, target.splide);
  2140. sync(target.splide, Splide2);
  2141. }
  2142. });
  2143. if (isNavigation) {
  2144. navigate();
  2145. }
  2146. }
  2147. function destroy() {
  2148. events.forEach((event2) => {
  2149. event2.destroy();
  2150. });
  2151. empty(events);
  2152. }
  2153. function remount() {
  2154. destroy();
  2155. mount();
  2156. }
  2157. function sync(splide, target) {
  2158. const event2 = splide.event.create();
  2159. event2.on(EVENT_MOVE, (index, prev, dest) => {
  2160. target.go(target.is(LOOP) ? dest : index);
  2161. });
  2162. events.push(event2);
  2163. }
  2164. function navigate() {
  2165. const ev = event.create();
  2166. const { on } = ev;
  2167. on(EVENT_CLICK, onClick);
  2168. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2169. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2170. events.push(ev);
  2171. ev.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2172. }
  2173. function update() {
  2174. setAttribute(
  2175. Components.Elements.list,
  2176. ARIA_ORIENTATION,
  2177. options.direction === TTB ? "vertical" : ""
  2178. );
  2179. }
  2180. function onClick(Slide) {
  2181. Splide2.go(Slide.index);
  2182. }
  2183. function onKeydown(Slide, e) {
  2184. if (includes(TRIGGER_KEYS, e.key)) {
  2185. onClick(Slide);
  2186. prevent(e);
  2187. }
  2188. }
  2189. return {
  2190. setup: apply(
  2191. Components.Breakpoints.set,
  2192. { slideFocus: isUndefined(slideFocus) ? isNavigation : slideFocus },
  2193. true
  2194. ),
  2195. mount,
  2196. destroy,
  2197. remount
  2198. };
  2199. };
  2200. const Wheel = (Splide, Components, options, event) => {
  2201. let lastTime = 0;
  2202. function mount() {
  2203. event.destroy();
  2204. if (options.wheel) {
  2205. event.bind(Components.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
  2206. }
  2207. event.on(EVENT_UPDATED, mount);
  2208. }
  2209. function onWheel(e) {
  2210. if (e.cancelable) {
  2211. const delta = parse(e);
  2212. const backwards = delta < 0;
  2213. const timeStamp = timeOf(e);
  2214. const min = options.wheelMinThreshold || 0;
  2215. const sleep = options.wheelSleep || 0;
  2216. if (abs(delta) > min && timeStamp - lastTime > sleep) {
  2217. Splide.go(delta < 0 ? "<" : ">");
  2218. lastTime = timeStamp;
  2219. }
  2220. shouldPrevent(backwards) && prevent(e);
  2221. }
  2222. }
  2223. function parse(e) {
  2224. const { wheelAxis = "y" } = options;
  2225. const { deltaX, deltaY } = e;
  2226. const x = includes(wheelAxis, "x") ? Components.Direction.orient(-deltaX) : 0;
  2227. const y = includes(wheelAxis, "y") ? deltaY : 0;
  2228. return x || y;
  2229. }
  2230. function shouldPrevent(backwards) {
  2231. return !options.releaseWheel || Splide.state.is(MOVING) || Components.Controller.getAdjacent(backwards) !== -1;
  2232. }
  2233. return {
  2234. mount
  2235. };
  2236. };
  2237. const VISUALLY_HIDDEN = `border:0;clip:rect(0,0,0,0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px`;
  2238. const SR_REMOVAL_DELAY = 90;
  2239. const Live = (Splide, Components, options, event) => {
  2240. const { on } = event;
  2241. const { track } = Components.Elements;
  2242. const { live = true } = options;
  2243. const enabled = live && !options.isNavigation;
  2244. const sr = create("span", CLASS_SR);
  2245. const interval = RequestInterval(SR_REMOVAL_DELAY, apply(toggle, false));
  2246. function mount() {
  2247. if (enabled) {
  2248. disable(!Components.Autoplay.isPaused());
  2249. setAttribute(track, ARIA_ATOMIC, true);
  2250. sr.textContent = "\u2026";
  2251. sr.style.cssText = VISUALLY_HIDDEN;
  2252. on(EVENT_AUTOPLAY_PLAY, apply(disable, true));
  2253. on(EVENT_AUTOPLAY_PAUSE, apply(disable, false));
  2254. on([EVENT_MOVED, EVENT_SCROLLED], apply(toggle, true));
  2255. }
  2256. }
  2257. function toggle(active) {
  2258. setAttribute(track, ARIA_BUSY, active);
  2259. if (active) {
  2260. append(track, sr);
  2261. interval.start();
  2262. } else {
  2263. removeNode(sr);
  2264. interval.cancel();
  2265. }
  2266. }
  2267. function destroy() {
  2268. removeAttribute(track, [ARIA_LIVE, ARIA_ATOMIC, ARIA_BUSY]);
  2269. removeNode(sr);
  2270. }
  2271. function disable(disabled) {
  2272. if (enabled) {
  2273. setAttribute(track, ARIA_LIVE, disabled ? "off" : "polite");
  2274. }
  2275. }
  2276. return {
  2277. mount,
  2278. disable,
  2279. destroy
  2280. };
  2281. };
  2282. const COMPONENTS = {
  2283. Breakpoints,
  2284. Direction,
  2285. Elements,
  2286. Slides,
  2287. Layout,
  2288. Clones,
  2289. Move,
  2290. Controller,
  2291. Arrows,
  2292. Autoplay,
  2293. Scroll,
  2294. Drag,
  2295. Keyboard,
  2296. LazyLoad,
  2297. Pagination,
  2298. Sync,
  2299. Wheel,
  2300. Live
  2301. };
  2302. const I18N = {
  2303. prev: "Previous slide",
  2304. next: "Next slide",
  2305. first: "Go to first slide",
  2306. last: "Go to last slide",
  2307. slideX: "Go to slide %s",
  2308. pageX: "Go to page %s",
  2309. play: "Start autoplay",
  2310. pause: "Pause autoplay",
  2311. carousel: "carousel",
  2312. slide: "slide",
  2313. select: "Select a slide to show",
  2314. slideLabel: "%s of %s"
  2315. };
  2316. const DEFAULTS = {
  2317. type: "slide",
  2318. speed: 400,
  2319. perPage: 1,
  2320. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  2321. drag: true,
  2322. direction: "ltr",
  2323. trimSpace: true,
  2324. focusableNodes: "a, button, textarea, input, select, iframe",
  2325. classes: CLASSES,
  2326. i18n: I18N,
  2327. reducedMotion: {
  2328. speed: 0,
  2329. rewindSpeed: 0,
  2330. autoplay: "pause"
  2331. }
  2332. };
  2333. const Fade = (Splide, Components, options, event) => {
  2334. const { Slides } = Components;
  2335. function mount() {
  2336. event.on([EVENT_MOUNTED, EVENT_REFRESH], init);
  2337. }
  2338. function init() {
  2339. Slides.forEach((Slide) => {
  2340. Slide.style("transform", `translateX(-${100 * Slide.index}%)`);
  2341. });
  2342. }
  2343. function start(index, done) {
  2344. Slides.style("transition", `opacity ${options.speed}ms ${options.easing}`);
  2345. nextTick(done);
  2346. }
  2347. return {
  2348. mount,
  2349. start,
  2350. cancel: noop
  2351. };
  2352. };
  2353. const Slide = (Splide, Components, options, event) => {
  2354. const { Move, Controller, Scroll } = Components;
  2355. const { list } = Components.Elements;
  2356. const transition = apply(style, list, "transition");
  2357. let endCallback;
  2358. function mount() {
  2359. event.bind(list, "transitionend", (e) => {
  2360. if (e.target === list && endCallback) {
  2361. cancel();
  2362. endCallback();
  2363. }
  2364. });
  2365. }
  2366. function start(index, done) {
  2367. const destination = Move.toPosition(index, true);
  2368. const position = Move.getPosition();
  2369. const speed = getSpeed(index);
  2370. if (abs(destination - position) >= 1 && speed >= 1) {
  2371. if (options.useScroll) {
  2372. Scroll.scroll(destination, speed, false, done);
  2373. } else {
  2374. transition(`transform ${speed}ms ${options.easing}`);
  2375. Move.translate(destination, true);
  2376. endCallback = done;
  2377. }
  2378. } else {
  2379. Move.jump(index);
  2380. done();
  2381. }
  2382. }
  2383. function cancel() {
  2384. transition("");
  2385. Scroll.cancel();
  2386. }
  2387. function getSpeed(index) {
  2388. const { rewindSpeed } = options;
  2389. if (Splide.is(SLIDE) && rewindSpeed) {
  2390. const prev = Controller.getIndex(true);
  2391. const end = Controller.getEnd();
  2392. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2393. return rewindSpeed;
  2394. }
  2395. }
  2396. return options.speed;
  2397. }
  2398. return {
  2399. mount,
  2400. start,
  2401. cancel
  2402. };
  2403. };
  2404. class Splide {
  2405. static defaults = {};
  2406. static STATES = STATES;
  2407. root;
  2408. event = EventInterface();
  2409. Components = {};
  2410. state = State(CREATED);
  2411. splides = [];
  2412. _o = {};
  2413. _C;
  2414. _E = {};
  2415. _T;
  2416. constructor(target, options = {}) {
  2417. const root = isString(target) ? query(document, target) : target;
  2418. assert(root, `${root} is invalid.`);
  2419. this.root = root;
  2420. options = merge({
  2421. label: getAttribute(root, ARIA_LABEL) || "",
  2422. labelledby: getAttribute(root, ARIA_LABELLEDBY) || ""
  2423. }, DEFAULTS, Splide.defaults, options);
  2424. try {
  2425. merge(options, JSON.parse(getAttribute(root, DATA_ATTRIBUTE)));
  2426. } catch (e) {
  2427. assert(false, "Invalid JSON");
  2428. }
  2429. this._o = Object.create(merge({}, options));
  2430. }
  2431. mount(Extensions = this._E, Transition = this._T) {
  2432. const { state, Components: Components2 } = this;
  2433. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2434. state.set(CREATED);
  2435. this._C = Components2;
  2436. this._T = Transition || (this.is(FADE) ? Fade : Slide);
  2437. this._E = Extensions;
  2438. const Constructors = assign({}, COMPONENTS, this._E, { Transition: this._T });
  2439. forOwn(Constructors, (Component, key) => {
  2440. const component = Component(this, Components2, this._o, this.event.create());
  2441. Components2[key] = component;
  2442. component.setup && component.setup();
  2443. });
  2444. forOwn(Components2, (component) => {
  2445. component.mount && component.mount();
  2446. });
  2447. this.emit(EVENT_MOUNTED);
  2448. addClass(this.root, CLASS_INITIALIZED);
  2449. state.set(IDLE);
  2450. this.emit(EVENT_READY);
  2451. return this;
  2452. }
  2453. sync(splide) {
  2454. this.splides.push({ splide });
  2455. splide.splides.push({ splide: this, isParent: true });
  2456. if (this.state.is(IDLE)) {
  2457. this._C.Sync.remount();
  2458. splide.Components.Sync.remount();
  2459. }
  2460. return this;
  2461. }
  2462. go(control) {
  2463. this._C.Controller.go(control);
  2464. return this;
  2465. }
  2466. jump(control) {
  2467. this._C.Controller.jump(control);
  2468. return this;
  2469. }
  2470. on(events, callback) {
  2471. this.event.on(events, callback);
  2472. return this;
  2473. }
  2474. off(events, callback) {
  2475. this.event.off(events, callback);
  2476. return this;
  2477. }
  2478. emit(event, ...args) {
  2479. this.event.emit(event, ...args);
  2480. return this;
  2481. }
  2482. add(slides, index) {
  2483. this._C.Slides.add(slides, index);
  2484. return this;
  2485. }
  2486. remove(matcher) {
  2487. this._C.Slides.remove(matcher);
  2488. return this;
  2489. }
  2490. is(type) {
  2491. return this._o.type === type;
  2492. }
  2493. refresh() {
  2494. this.emit(EVENT_REFRESH);
  2495. return this;
  2496. }
  2497. destroy(completely = true) {
  2498. const { event, state } = this;
  2499. if (state.is(CREATED)) {
  2500. this.on(EVENT_READY, this.destroy.bind(this, completely));
  2501. } else {
  2502. forOwn(this._C, (component) => {
  2503. component.destroy && component.destroy(completely);
  2504. }, true);
  2505. event.emit(EVENT_DESTROY);
  2506. event.destroy();
  2507. completely && empty(this.splides);
  2508. state.set(DESTROYED);
  2509. }
  2510. return this;
  2511. }
  2512. get options() {
  2513. return this._o;
  2514. }
  2515. set options(options) {
  2516. this._C.Breakpoints.set(options, true, true);
  2517. }
  2518. get length() {
  2519. return this._C.Slides.getLength(true);
  2520. }
  2521. get index() {
  2522. return this._C.Controller.getIndex();
  2523. }
  2524. }
  2525. return Splide;
  2526. }));