splide.js 83 KB

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