splide.js 82 KB

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