splide.cjs.js 73 KB

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