splide.js 80 KB

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