splide.js 76 KB

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