splide.cjs.js 79 KB

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