splide.esm.js 86 KB

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