splide.esm.js 64 KB

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