splide.esm.js 64 KB

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