splide.js 78 KB

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