splide.js 84 KB

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