splide.js 80 KB

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