splide.js 82 KB

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