splide.cjs.js 65 KB

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