splide.js 83 KB

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