splide.js 78 KB

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