splide.js 83 KB

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