splide.cjs.js 64 KB

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