splide.cjs.js 65 KB

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