splide.js 81 KB

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