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