splide.js 79 KB

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