splide.esm.js 72 KB

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