splide.js 78 KB

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