splide.esm.js 63 KB

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