splide.js 84 KB

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