splide.cjs.js 65 KB

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