splide.esm.js 63 KB

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