splide.js 82 KB

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