splide.js 75 KB

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