splide.js 81 KB

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