splide.js 80 KB

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