splide.js 78 KB

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