splide.esm.js 63 KB

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