splide.cjs.js 73 KB

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