splide.js 77 KB

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