splide.js 81 KB

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