splide.cjs.js 64 KB

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