splide.js 77 KB

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