splide.js 78 KB

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