splide.cjs.js 66 KB

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