splide.cjs.js 66 KB

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