splide.js 77 KB

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