splide.js 83 KB

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