splide.js 78 KB

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