splide.js 82 KB

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