splide.js 83 KB

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