splide.js 81 KB

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