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