splide.js 77 KB

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