splide.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038
  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.6.11
  6. * License : MIT
  7. * Copyright: 2022 Naotoshi Fujita
  8. */
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Splide = factory());
  11. })(this, function () {
  12. 'use strict';
  13. var 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 hidden = !visible && (!isActive() || isClone);
  800. setAttribute(slide, ARIA_HIDDEN, hidden || null);
  801. setAttribute(slide, TAB_INDEX, !hidden && options.slideFocus ? 0 : null);
  802. if (focusableNodes) {
  803. focusableNodes.forEach(function (node) {
  804. setAttribute(node, TAB_INDEX, hidden ? -1 : null);
  805. });
  806. }
  807. if (visible !== hasClass(slide, CLASS_VISIBLE)) {
  808. toggleClass(slide, CLASS_VISIBLE, visible);
  809. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
  810. }
  811. }
  812. function style$1(prop, value, useContainer) {
  813. style(useContainer && container || slide, prop, value);
  814. }
  815. function isActive() {
  816. var curr = Splide2.index;
  817. return curr === index || options.cloneStatus && curr === slideIndex;
  818. }
  819. function isVisible() {
  820. if (Splide2.is(FADE)) {
  821. return isActive();
  822. }
  823. var trackRect = rect(Components.Elements.track);
  824. var slideRect = rect(slide);
  825. var left = resolve("left");
  826. var right = resolve("right");
  827. return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
  828. }
  829. function isWithin(from, distance) {
  830. var diff = abs(from - index);
  831. if (!isClone && (options.rewind || Splide2.is(LOOP))) {
  832. diff = min(diff, Splide2.length - diff);
  833. }
  834. return diff <= distance;
  835. }
  836. var self = {
  837. index: index,
  838. slideIndex: slideIndex,
  839. slide: slide,
  840. container: container,
  841. isClone: isClone,
  842. mount: mount,
  843. destroy: destroy,
  844. update: update,
  845. style: style$1,
  846. isWithin: isWithin
  847. };
  848. return self;
  849. }
  850. function Slides(Splide2, Components2, options) {
  851. var _EventInterface3 = EventInterface(Splide2),
  852. on = _EventInterface3.on,
  853. emit = _EventInterface3.emit,
  854. bind = _EventInterface3.bind;
  855. var _Components2$Elements = Components2.Elements,
  856. slides = _Components2$Elements.slides,
  857. list = _Components2$Elements.list;
  858. var Slides2 = [];
  859. function mount() {
  860. init();
  861. on(EVENT_REFRESH, refresh);
  862. on([EVENT_MOUNTED, EVENT_REFRESH], function () {
  863. Slides2.sort(function (Slide1, Slide2) {
  864. return Slide1.index - Slide2.index;
  865. });
  866. });
  867. }
  868. function init() {
  869. slides.forEach(function (slide, index) {
  870. register(slide, index, -1);
  871. });
  872. }
  873. function destroy() {
  874. forEach$1(function (Slide2) {
  875. Slide2.destroy();
  876. });
  877. empty(Slides2);
  878. }
  879. function refresh() {
  880. destroy();
  881. init();
  882. }
  883. function update() {
  884. forEach$1(function (Slide2) {
  885. Slide2.update();
  886. });
  887. }
  888. function register(slide, index, slideIndex) {
  889. var object = Slide$1(Splide2, index, slideIndex, slide);
  890. object.mount();
  891. Slides2.push(object);
  892. }
  893. function get(excludeClones) {
  894. return excludeClones ? filter(function (Slide2) {
  895. return !Slide2.isClone;
  896. }) : Slides2;
  897. }
  898. function getIn(page) {
  899. var Controller = Components2.Controller;
  900. var index = Controller.toIndex(page);
  901. var max = Controller.hasFocus() ? 1 : options.perPage;
  902. return filter(function (Slide2) {
  903. return between(Slide2.index, index, index + max - 1);
  904. });
  905. }
  906. function getAt(index) {
  907. return filter(index)[0];
  908. }
  909. function add(items, index) {
  910. forEach(items, function (slide) {
  911. if (isString(slide)) {
  912. slide = parseHtml(slide);
  913. }
  914. if (isHTMLElement(slide)) {
  915. var ref = slides[index];
  916. ref ? before(slide, ref) : append(list, slide);
  917. addClass(slide, options.classes.slide);
  918. observeImages(slide, emit.bind(null, EVENT_RESIZE));
  919. }
  920. });
  921. emit(EVENT_REFRESH);
  922. }
  923. function remove$1(matcher) {
  924. remove(filter(matcher).map(function (Slide2) {
  925. return Slide2.slide;
  926. }));
  927. emit(EVENT_REFRESH);
  928. }
  929. function forEach$1(iteratee, excludeClones) {
  930. get(excludeClones).forEach(iteratee);
  931. }
  932. function filter(matcher) {
  933. return Slides2.filter(isFunction(matcher) ? matcher : function (Slide2) {
  934. return isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index);
  935. });
  936. }
  937. function style(prop, value, useContainer) {
  938. forEach$1(function (Slide2) {
  939. Slide2.style(prop, value, useContainer);
  940. });
  941. }
  942. function observeImages(elm, callback) {
  943. var images = queryAll(elm, "img");
  944. var length = images.length;
  945. if (length) {
  946. images.forEach(function (img) {
  947. bind(img, "load error", function () {
  948. if (! --length) {
  949. callback();
  950. }
  951. });
  952. });
  953. } else {
  954. callback();
  955. }
  956. }
  957. function getLength(excludeClones) {
  958. return excludeClones ? slides.length : Slides2.length;
  959. }
  960. function isEnough() {
  961. return Slides2.length > options.perPage;
  962. }
  963. return {
  964. mount: mount,
  965. destroy: destroy,
  966. update: update,
  967. register: register,
  968. get: get,
  969. getIn: getIn,
  970. getAt: getAt,
  971. add: add,
  972. remove: remove$1,
  973. forEach: forEach$1,
  974. filter: filter,
  975. style: style,
  976. getLength: getLength,
  977. isEnough: isEnough
  978. };
  979. }
  980. function Layout(Splide2, Components2, options) {
  981. var _EventInterface4 = EventInterface(Splide2),
  982. on = _EventInterface4.on,
  983. bind = _EventInterface4.bind,
  984. emit = _EventInterface4.emit;
  985. var Slides = Components2.Slides;
  986. var resolve = Components2.Direction.resolve;
  987. var _Components2$Elements2 = Components2.Elements,
  988. root = _Components2$Elements2.root,
  989. track = _Components2$Elements2.track,
  990. list = _Components2$Elements2.list;
  991. var getAt = Slides.getAt;
  992. var vertical;
  993. var rootRect;
  994. function mount() {
  995. init();
  996. bind(window, "resize load", Throttle(emit.bind(this, EVENT_RESIZE)));
  997. on([EVENT_UPDATED, EVENT_REFRESH], init);
  998. on(EVENT_RESIZE, resize);
  999. }
  1000. function init() {
  1001. rootRect = null;
  1002. vertical = options.direction === TTB;
  1003. style(root, "maxWidth", unit(options.width));
  1004. style(track, resolve("paddingLeft"), cssPadding(false));
  1005. style(track, resolve("paddingRight"), cssPadding(true));
  1006. resize();
  1007. }
  1008. function resize() {
  1009. var newRect = rect(root);
  1010. if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  1011. style(track, "height", cssTrackHeight());
  1012. Slides.style(resolve("marginRight"), unit(options.gap));
  1013. Slides.style("width", cssSlideWidth() || null);
  1014. setSlidesHeight();
  1015. rootRect = newRect;
  1016. emit(EVENT_RESIZED);
  1017. }
  1018. }
  1019. function setSlidesHeight() {
  1020. Slides.style("height", cssSlideHeight() || null, true);
  1021. }
  1022. function cssPadding(right) {
  1023. var padding = options.padding;
  1024. var prop = resolve(right ? "right" : "left");
  1025. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  1026. }
  1027. function cssTrackHeight() {
  1028. var height = "";
  1029. if (vertical) {
  1030. height = cssHeight();
  1031. assert(height, "height or heightRatio is missing.");
  1032. height = "calc(" + height + " - " + cssPadding(false) + " - " + cssPadding(true) + ")";
  1033. }
  1034. return height;
  1035. }
  1036. function cssHeight() {
  1037. return unit(options.height || rect(list).width * options.heightRatio);
  1038. }
  1039. function cssSlideWidth() {
  1040. return options.autoWidth ? "" : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  1041. }
  1042. function cssSlideHeight() {
  1043. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? "" : cssSlideSize() : cssHeight());
  1044. }
  1045. function cssSlideSize() {
  1046. var gap = unit(options.gap);
  1047. return "calc((100%" + (gap && " + " + gap) + ")/" + (options.perPage || 1) + (gap && " - " + gap) + ")";
  1048. }
  1049. function listSize() {
  1050. return rect(list)[resolve("width")];
  1051. }
  1052. function slideSize(index, withoutGap) {
  1053. var Slide = getAt(index || 0);
  1054. return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
  1055. }
  1056. function totalSize(index, withoutGap) {
  1057. var Slide = getAt(index);
  1058. if (Slide) {
  1059. var right = rect(Slide.slide)[resolve("right")];
  1060. var left = rect(list)[resolve("left")];
  1061. return abs(right - left) + (withoutGap ? 0 : getGap());
  1062. }
  1063. return 0;
  1064. }
  1065. function sliderSize() {
  1066. return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
  1067. }
  1068. function getGap() {
  1069. var Slide = getAt(0);
  1070. return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
  1071. }
  1072. function getPadding(right) {
  1073. return parseFloat(style(track, resolve("padding" + (right ? "Right" : "Left")))) || 0;
  1074. }
  1075. return {
  1076. mount: mount,
  1077. listSize: listSize,
  1078. slideSize: slideSize,
  1079. sliderSize: sliderSize,
  1080. totalSize: totalSize,
  1081. getPadding: getPadding
  1082. };
  1083. }
  1084. function Clones(Splide2, Components2, options) {
  1085. var _EventInterface5 = EventInterface(Splide2),
  1086. on = _EventInterface5.on,
  1087. emit = _EventInterface5.emit;
  1088. var Elements = Components2.Elements,
  1089. Slides = Components2.Slides;
  1090. var resolve = Components2.Direction.resolve;
  1091. var clones = [];
  1092. var cloneCount;
  1093. function mount() {
  1094. init();
  1095. on(EVENT_REFRESH, refresh);
  1096. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1097. }
  1098. function init() {
  1099. if (cloneCount = computeCloneCount()) {
  1100. generate(cloneCount);
  1101. emit(EVENT_RESIZE);
  1102. }
  1103. }
  1104. function destroy() {
  1105. remove(clones);
  1106. empty(clones);
  1107. }
  1108. function refresh() {
  1109. destroy();
  1110. init();
  1111. }
  1112. function observe() {
  1113. if (cloneCount < computeCloneCount()) {
  1114. emit(EVENT_REFRESH);
  1115. }
  1116. }
  1117. function generate(count) {
  1118. var slides = Slides.get().slice();
  1119. var length = slides.length;
  1120. if (length) {
  1121. while (slides.length < count) {
  1122. push(slides, slides);
  1123. }
  1124. push(slides.slice(-count), slides.slice(0, count)).forEach(function (Slide, index) {
  1125. var isHead = index < count;
  1126. var clone = cloneDeep(Slide.slide, index);
  1127. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1128. push(clones, clone);
  1129. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1130. });
  1131. }
  1132. }
  1133. function cloneDeep(elm, index) {
  1134. var clone = elm.cloneNode(true);
  1135. addClass(clone, options.classes.clone);
  1136. clone.id = Splide2.root.id + "-clone" + pad(index + 1);
  1137. return clone;
  1138. }
  1139. function computeCloneCount() {
  1140. var clones2 = options.clones;
  1141. if (!Splide2.is(LOOP)) {
  1142. clones2 = 0;
  1143. } else if (!clones2) {
  1144. var fixedSize = measure(Elements.list, options[resolve("fixedWidth")]);
  1145. var fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1146. var baseCount = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage;
  1147. clones2 = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  1148. }
  1149. return clones2;
  1150. }
  1151. return {
  1152. mount: mount,
  1153. destroy: destroy
  1154. };
  1155. }
  1156. function Move(Splide2, Components2, options) {
  1157. var _EventInterface6 = EventInterface(Splide2),
  1158. on = _EventInterface6.on,
  1159. emit = _EventInterface6.emit;
  1160. var _Components2$Layout = Components2.Layout,
  1161. slideSize = _Components2$Layout.slideSize,
  1162. getPadding = _Components2$Layout.getPadding,
  1163. totalSize = _Components2$Layout.totalSize,
  1164. listSize = _Components2$Layout.listSize,
  1165. sliderSize = _Components2$Layout.sliderSize;
  1166. var _Components2$Directio = Components2.Direction,
  1167. resolve = _Components2$Directio.resolve,
  1168. orient = _Components2$Directio.orient;
  1169. var _Components2$Elements3 = Components2.Elements,
  1170. list = _Components2$Elements3.list,
  1171. track = _Components2$Elements3.track;
  1172. var Transition;
  1173. function mount() {
  1174. Transition = Components2.Transition;
  1175. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1176. }
  1177. function destroy() {
  1178. removeAttribute(list, "style");
  1179. }
  1180. function reposition() {
  1181. if (!isBusy()) {
  1182. Components2.Scroll.cancel();
  1183. jump(Splide2.index);
  1184. emit(EVENT_REPOSITIONED);
  1185. }
  1186. }
  1187. function move(dest, index, prev, callback) {
  1188. if (!isBusy()) {
  1189. var set = Splide2.state.set;
  1190. var position = getPosition();
  1191. if (dest !== index) {
  1192. Transition.cancel();
  1193. translate(shift(position, dest > index), true);
  1194. }
  1195. set(MOVING);
  1196. emit(EVENT_MOVE, index, prev, dest);
  1197. Transition.start(index, function () {
  1198. set(IDLE);
  1199. emit(EVENT_MOVED, index, prev, dest);
  1200. if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
  1201. Components2.Controller.go(dest > prev ? ">" : "<", false, callback);
  1202. } else {
  1203. callback && callback();
  1204. }
  1205. });
  1206. }
  1207. }
  1208. function jump(index) {
  1209. translate(toPosition(index, true));
  1210. }
  1211. function translate(position, preventLoop) {
  1212. if (!Splide2.is(FADE)) {
  1213. var destination = preventLoop ? position : loop(position);
  1214. list.style.transform = "translate" + resolve("X") + "(" + destination + "px)";
  1215. position !== destination && emit(EVENT_SHIFTED);
  1216. }
  1217. }
  1218. function loop(position) {
  1219. if (Splide2.is(LOOP)) {
  1220. var diff = orient(position - getPosition());
  1221. var exceededMin = exceededLimit(false, position) && diff < 0;
  1222. var exceededMax = exceededLimit(true, position) && diff > 0;
  1223. if (exceededMin || exceededMax) {
  1224. position = shift(position, exceededMax);
  1225. }
  1226. }
  1227. return position;
  1228. }
  1229. function shift(position, backwards) {
  1230. var excess = position - getLimit(backwards);
  1231. var size = sliderSize();
  1232. position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
  1233. return position;
  1234. }
  1235. function cancel() {
  1236. translate(getPosition());
  1237. Transition.cancel();
  1238. }
  1239. function toIndex(position) {
  1240. var Slides = Components2.Slides.get();
  1241. var index = 0;
  1242. var minDistance = Infinity;
  1243. for (var i = 0; i < Slides.length; i++) {
  1244. var slideIndex = Slides[i].index;
  1245. var distance = abs(toPosition(slideIndex, true) - position);
  1246. if (distance <= minDistance) {
  1247. minDistance = distance;
  1248. index = slideIndex;
  1249. } else {
  1250. break;
  1251. }
  1252. }
  1253. return index;
  1254. }
  1255. function toPosition(index, trimming) {
  1256. var position = orient(totalSize(index - 1) - offset(index));
  1257. return trimming ? trim(position) : position;
  1258. }
  1259. function getPosition() {
  1260. var left = resolve("left");
  1261. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1262. }
  1263. function trim(position) {
  1264. if (options.trimSpace && Splide2.is(SLIDE)) {
  1265. position = clamp(position, 0, orient(sliderSize() - listSize()));
  1266. }
  1267. return position;
  1268. }
  1269. function offset(index) {
  1270. var focus = options.focus;
  1271. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1272. }
  1273. function getLimit(max) {
  1274. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1275. }
  1276. function isBusy() {
  1277. return Splide2.state.is(MOVING) && options.waitForTransition;
  1278. }
  1279. function exceededLimit(max, position) {
  1280. position = isUndefined(position) ? getPosition() : position;
  1281. var exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1282. var exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1283. return exceededMin || exceededMax;
  1284. }
  1285. return {
  1286. mount: mount,
  1287. destroy: destroy,
  1288. move: move,
  1289. jump: jump,
  1290. translate: translate,
  1291. shift: shift,
  1292. cancel: cancel,
  1293. toIndex: toIndex,
  1294. toPosition: toPosition,
  1295. getPosition: getPosition,
  1296. getLimit: getLimit,
  1297. isBusy: isBusy,
  1298. exceededLimit: exceededLimit
  1299. };
  1300. }
  1301. function Controller(Splide2, Components2, options) {
  1302. var _EventInterface7 = EventInterface(Splide2),
  1303. on = _EventInterface7.on;
  1304. var Move = Components2.Move;
  1305. var getPosition = Move.getPosition,
  1306. getLimit = Move.getLimit;
  1307. var _Components2$Slides = Components2.Slides,
  1308. isEnough = _Components2$Slides.isEnough,
  1309. getLength = _Components2$Slides.getLength;
  1310. var isLoop = Splide2.is(LOOP);
  1311. var isSlide = Splide2.is(SLIDE);
  1312. var currIndex = options.start || 0;
  1313. var prevIndex = currIndex;
  1314. var slideCount;
  1315. var perMove;
  1316. var perPage;
  1317. function mount() {
  1318. init();
  1319. on([EVENT_UPDATED, EVENT_REFRESH], init, DEFAULT_EVENT_PRIORITY - 1);
  1320. }
  1321. function init() {
  1322. slideCount = getLength(true);
  1323. perMove = options.perMove;
  1324. perPage = options.perPage;
  1325. currIndex = clamp(currIndex, 0, slideCount - 1);
  1326. }
  1327. function go(control, allowSameIndex, callback) {
  1328. var dest = parse(control);
  1329. if (options.useScroll) {
  1330. scroll(dest, true, true, options.speed, callback);
  1331. } else {
  1332. var index = loop(dest);
  1333. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  1334. setIndex(index);
  1335. Move.move(dest, index, prevIndex, callback);
  1336. }
  1337. }
  1338. }
  1339. function scroll(destination, useIndex, snap, duration, callback) {
  1340. var dest = useIndex ? destination : toDest(destination);
  1341. Components2.Scroll.scroll(useIndex || snap ? Move.toPosition(dest, true) : destination, duration, function () {
  1342. setIndex(Move.toIndex(Move.getPosition()));
  1343. callback && callback();
  1344. });
  1345. }
  1346. function parse(control) {
  1347. var index = currIndex;
  1348. if (isString(control)) {
  1349. var _ref = control.match(/([+\-<>])(\d+)?/) || [],
  1350. indicator = _ref[1],
  1351. number = _ref[2];
  1352. if (indicator === "+" || indicator === "-") {
  1353. index = computeDestIndex(currIndex + +("" + indicator + (+number || 1)), currIndex, true);
  1354. } else if (indicator === ">") {
  1355. index = number ? toIndex(+number) : getNext(true);
  1356. } else if (indicator === "<") {
  1357. index = getPrev(true);
  1358. }
  1359. } else {
  1360. index = isLoop ? control : clamp(control, 0, getEnd());
  1361. }
  1362. return index;
  1363. }
  1364. function getNext(destination) {
  1365. return getAdjacent(false, destination);
  1366. }
  1367. function getPrev(destination) {
  1368. return getAdjacent(true, destination);
  1369. }
  1370. function getAdjacent(prev, destination) {
  1371. var number = perMove || (hasFocus() ? 1 : perPage);
  1372. var dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
  1373. if (dest === -1 && isSlide) {
  1374. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1375. return prev ? 0 : getEnd();
  1376. }
  1377. }
  1378. return destination ? dest : loop(dest);
  1379. }
  1380. function computeDestIndex(dest, from, incremental) {
  1381. if (isEnough()) {
  1382. var end = getEnd();
  1383. if (dest < 0 || dest > end) {
  1384. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  1385. dest = toIndex(toPage(dest));
  1386. } else {
  1387. if (isLoop) {
  1388. dest = perMove || hasFocus() ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  1389. } else if (options.rewind) {
  1390. dest = dest < 0 ? end : 0;
  1391. } else {
  1392. dest = -1;
  1393. }
  1394. }
  1395. } else {
  1396. if (!incremental && dest !== from) {
  1397. dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
  1398. }
  1399. }
  1400. } else {
  1401. dest = -1;
  1402. }
  1403. return dest;
  1404. }
  1405. function getEnd() {
  1406. var end = slideCount - perPage;
  1407. if (hasFocus() || isLoop && perMove) {
  1408. end = slideCount - 1;
  1409. }
  1410. return max(end, 0);
  1411. }
  1412. function loop(index) {
  1413. if (isLoop) {
  1414. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  1415. }
  1416. return index;
  1417. }
  1418. function toIndex(page) {
  1419. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  1420. }
  1421. function toPage(index) {
  1422. if (!hasFocus()) {
  1423. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  1424. index = floor(index / perPage);
  1425. }
  1426. return index;
  1427. }
  1428. function toDest(destination) {
  1429. var closest = Move.toIndex(destination);
  1430. return isSlide ? clamp(closest, 0, getEnd()) : closest;
  1431. }
  1432. function setIndex(index) {
  1433. if (index !== currIndex) {
  1434. prevIndex = currIndex;
  1435. currIndex = index;
  1436. }
  1437. }
  1438. function getIndex(prev) {
  1439. return prev ? prevIndex : currIndex;
  1440. }
  1441. function hasFocus() {
  1442. return !isUndefined(options.focus) || options.isNavigation;
  1443. }
  1444. return {
  1445. mount: mount,
  1446. go: go,
  1447. scroll: scroll,
  1448. getNext: getNext,
  1449. getPrev: getPrev,
  1450. getAdjacent: getAdjacent,
  1451. getEnd: getEnd,
  1452. setIndex: setIndex,
  1453. getIndex: getIndex,
  1454. toIndex: toIndex,
  1455. toPage: toPage,
  1456. toDest: toDest,
  1457. hasFocus: hasFocus
  1458. };
  1459. }
  1460. var XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1461. var PATH = "m15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z";
  1462. var SIZE = 40;
  1463. function Arrows(Splide2, Components2, options) {
  1464. var _EventInterface8 = EventInterface(Splide2),
  1465. on = _EventInterface8.on,
  1466. bind = _EventInterface8.bind,
  1467. emit = _EventInterface8.emit;
  1468. var classes = options.classes,
  1469. i18n = options.i18n;
  1470. var Elements = Components2.Elements,
  1471. Controller = Components2.Controller;
  1472. var wrapper = Elements.arrows;
  1473. var prev = Elements.prev;
  1474. var next = Elements.next;
  1475. var created;
  1476. var arrows = {};
  1477. function mount() {
  1478. init();
  1479. on(EVENT_UPDATED, init);
  1480. }
  1481. function init() {
  1482. if (options.arrows) {
  1483. if (!prev || !next) {
  1484. createArrows();
  1485. }
  1486. }
  1487. if (prev && next) {
  1488. if (!arrows.prev) {
  1489. var id = Elements.track.id;
  1490. setAttribute(prev, ARIA_CONTROLS, id);
  1491. setAttribute(next, ARIA_CONTROLS, id);
  1492. arrows.prev = prev;
  1493. arrows.next = next;
  1494. listen();
  1495. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1496. } else {
  1497. display(wrapper, options.arrows === false ? "none" : "");
  1498. }
  1499. }
  1500. }
  1501. function destroy() {
  1502. if (created) {
  1503. remove(wrapper);
  1504. } else {
  1505. removeAttribute(prev, ALL_ATTRIBUTES);
  1506. removeAttribute(next, ALL_ATTRIBUTES);
  1507. }
  1508. }
  1509. function listen() {
  1510. var go = Controller.go;
  1511. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  1512. bind(next, "click", function () {
  1513. go(">", true);
  1514. });
  1515. bind(prev, "click", function () {
  1516. go("<", true);
  1517. });
  1518. }
  1519. function createArrows() {
  1520. wrapper = create("div", classes.arrows);
  1521. prev = createArrow(true);
  1522. next = createArrow(false);
  1523. created = true;
  1524. append(wrapper, [prev, next]);
  1525. before(wrapper, child(options.arrows === "slider" && Elements.slider || Splide2.root));
  1526. }
  1527. function createArrow(prev2) {
  1528. var arrow = "<button class=\"" + classes.arrow + " " + (prev2 ? classes.prev : classes.next) + "\" type=\"button\"><svg xmlns=\"" + XML_NAME_SPACE + "\" viewBox=\"0 0 " + SIZE + " " + SIZE + "\" width=\"" + SIZE + "\" height=\"" + SIZE + "\"><path d=\"" + (options.arrowPath || PATH) + "\" />";
  1529. return parseHtml(arrow);
  1530. }
  1531. function update() {
  1532. var index = Splide2.index;
  1533. var prevIndex = Controller.getPrev();
  1534. var nextIndex = Controller.getNext();
  1535. var prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1536. var nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1537. prev.disabled = prevIndex < 0;
  1538. next.disabled = nextIndex < 0;
  1539. setAttribute(prev, ARIA_LABEL, prevLabel);
  1540. setAttribute(next, ARIA_LABEL, nextLabel);
  1541. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1542. }
  1543. return {
  1544. arrows: arrows,
  1545. mount: mount,
  1546. destroy: destroy
  1547. };
  1548. }
  1549. var INTERVAL_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-interval";
  1550. function Autoplay(Splide2, Components2, options) {
  1551. var _EventInterface9 = EventInterface(Splide2),
  1552. on = _EventInterface9.on,
  1553. bind = _EventInterface9.bind,
  1554. emit = _EventInterface9.emit;
  1555. var interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), update);
  1556. var isPaused = interval.isPaused;
  1557. var Elements = Components2.Elements;
  1558. var hovered;
  1559. var focused;
  1560. var paused;
  1561. function mount() {
  1562. var autoplay = options.autoplay;
  1563. if (autoplay) {
  1564. initButton(true);
  1565. initButton(false);
  1566. listen();
  1567. if (autoplay !== "pause") {
  1568. play();
  1569. }
  1570. }
  1571. }
  1572. function initButton(forPause) {
  1573. var prop = forPause ? "pause" : "play";
  1574. var button = Elements[prop];
  1575. if (button) {
  1576. setAttribute(button, ARIA_CONTROLS, Elements.track.id);
  1577. setAttribute(button, ARIA_LABEL, options.i18n[prop]);
  1578. bind(button, "click", forPause ? pause : play);
  1579. }
  1580. }
  1581. function listen() {
  1582. var root = Elements.root;
  1583. if (options.pauseOnHover) {
  1584. bind(root, "mouseenter mouseleave", function (e) {
  1585. hovered = e.type === "mouseenter";
  1586. autoToggle();
  1587. });
  1588. }
  1589. if (options.pauseOnFocus) {
  1590. bind(root, "focusin focusout", function (e) {
  1591. focused = e.type === "focusin";
  1592. autoToggle();
  1593. });
  1594. }
  1595. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1596. on(EVENT_MOVE, updateInterval);
  1597. }
  1598. function play() {
  1599. if (isPaused() && Components2.Slides.isEnough()) {
  1600. interval.start(!options.resetProgress);
  1601. focused = hovered = paused = false;
  1602. emit(EVENT_AUTOPLAY_PLAY);
  1603. }
  1604. }
  1605. function pause(manual) {
  1606. if (manual === void 0) {
  1607. manual = true;
  1608. }
  1609. if (!isPaused()) {
  1610. interval.pause();
  1611. emit(EVENT_AUTOPLAY_PAUSE);
  1612. }
  1613. paused = manual;
  1614. }
  1615. function autoToggle() {
  1616. if (!paused) {
  1617. if (!hovered && !focused) {
  1618. play();
  1619. } else {
  1620. pause(false);
  1621. }
  1622. }
  1623. }
  1624. function update(rate) {
  1625. var bar = Elements.bar;
  1626. bar && style(bar, "width", rate * 100 + "%");
  1627. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1628. }
  1629. function updateInterval() {
  1630. var Slide = Components2.Slides.getAt(Splide2.index);
  1631. interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1632. }
  1633. return {
  1634. mount: mount,
  1635. destroy: interval.cancel,
  1636. play: play,
  1637. pause: pause,
  1638. isPaused: isPaused
  1639. };
  1640. }
  1641. function Cover(Splide2, Components2, options) {
  1642. var _EventInterface10 = EventInterface(Splide2),
  1643. on = _EventInterface10.on;
  1644. function mount() {
  1645. if (options.cover) {
  1646. on(EVENT_LAZYLOAD_LOADED, function (img, Slide) {
  1647. toggle(true, img, Slide);
  1648. });
  1649. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply.bind(null, true));
  1650. }
  1651. }
  1652. function destroy() {
  1653. apply(false);
  1654. }
  1655. function apply(cover) {
  1656. Components2.Slides.forEach(function (Slide) {
  1657. var img = child(Slide.container || Slide.slide, "img");
  1658. if (img && img.src) {
  1659. toggle(cover, img, Slide);
  1660. }
  1661. });
  1662. }
  1663. function toggle(cover, img, Slide) {
  1664. Slide.style("background", cover ? "center/cover no-repeat url(\"" + img.src + "\")" : "", true);
  1665. display(img, cover ? "none" : "");
  1666. }
  1667. return {
  1668. mount: mount,
  1669. destroy: destroy
  1670. };
  1671. }
  1672. var BOUNCE_DIFF_THRESHOLD = 10;
  1673. var BOUNCE_DURATION = 600;
  1674. var FRICTION_FACTOR = 0.6;
  1675. var BASE_VELOCITY = 1.5;
  1676. var MIN_DURATION = 800;
  1677. function Scroll(Splide2, Components2, options) {
  1678. var _EventInterface11 = EventInterface(Splide2),
  1679. on = _EventInterface11.on,
  1680. emit = _EventInterface11.emit;
  1681. var Move = Components2.Move;
  1682. var getPosition = Move.getPosition,
  1683. getLimit = Move.getLimit,
  1684. exceededLimit = Move.exceededLimit;
  1685. var interval;
  1686. var scrollCallback;
  1687. function mount() {
  1688. on(EVENT_MOVE, clear);
  1689. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1690. }
  1691. function scroll(destination, duration, callback, suppressConstraint) {
  1692. var start = getPosition();
  1693. var friction = 1;
  1694. duration = duration || computeDuration(abs(destination - start));
  1695. scrollCallback = callback;
  1696. clear();
  1697. interval = RequestInterval(duration, onScrolled, function (rate) {
  1698. var position = getPosition();
  1699. var target = start + (destination - start) * easing(rate);
  1700. var diff = (target - getPosition()) * friction;
  1701. Move.translate(position + diff);
  1702. if (Splide2.is(SLIDE) && !suppressConstraint && exceededLimit()) {
  1703. friction *= FRICTION_FACTOR;
  1704. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1705. bounce(exceededLimit(false));
  1706. }
  1707. }
  1708. }, 1);
  1709. emit(EVENT_SCROLL);
  1710. interval.start();
  1711. }
  1712. function bounce(backwards) {
  1713. scroll(getLimit(!backwards), BOUNCE_DURATION, null, true);
  1714. }
  1715. function onScrolled() {
  1716. var position = getPosition();
  1717. var index = Move.toIndex(position);
  1718. if (!between(index, 0, Splide2.length - 1)) {
  1719. Move.translate(Move.shift(position, index > 0), true);
  1720. }
  1721. scrollCallback && scrollCallback();
  1722. emit(EVENT_SCROLLED);
  1723. }
  1724. function computeDuration(distance) {
  1725. return max(distance / BASE_VELOCITY, MIN_DURATION);
  1726. }
  1727. function clear() {
  1728. if (interval) {
  1729. interval.cancel();
  1730. }
  1731. }
  1732. function cancel() {
  1733. if (interval && !interval.isPaused()) {
  1734. clear();
  1735. onScrolled();
  1736. }
  1737. }
  1738. function easing(t) {
  1739. var easingFunc = options.easingFunc;
  1740. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1741. }
  1742. return {
  1743. mount: mount,
  1744. destroy: clear,
  1745. scroll: scroll,
  1746. cancel: cancel
  1747. };
  1748. }
  1749. var SCROLL_LISTENER_OPTIONS = {
  1750. passive: false,
  1751. capture: true
  1752. };
  1753. var FRICTION = 5;
  1754. var LOG_INTERVAL = 200;
  1755. var POINTER_DOWN_EVENTS = "touchstart mousedown";
  1756. var POINTER_MOVE_EVENTS = "touchmove mousemove";
  1757. var POINTER_UP_EVENTS = "touchend touchcancel mouseup";
  1758. function Drag(Splide2, Components2, options) {
  1759. var _EventInterface12 = EventInterface(Splide2),
  1760. on = _EventInterface12.on,
  1761. emit = _EventInterface12.emit,
  1762. bind = _EventInterface12.bind,
  1763. unbind = _EventInterface12.unbind;
  1764. var Move = Components2.Move,
  1765. Scroll = Components2.Scroll,
  1766. Controller = Components2.Controller;
  1767. var track = Components2.Elements.track;
  1768. var _Components2$Directio2 = Components2.Direction,
  1769. resolve = _Components2$Directio2.resolve,
  1770. orient = _Components2$Directio2.orient;
  1771. var getPosition = Move.getPosition,
  1772. exceededLimit = Move.exceededLimit;
  1773. var basePosition;
  1774. var baseEvent;
  1775. var prevBaseEvent;
  1776. var lastEvent;
  1777. var isFree;
  1778. var dragging;
  1779. var hasExceeded = false;
  1780. var clickPrevented;
  1781. var disabled;
  1782. var target;
  1783. function mount() {
  1784. bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1785. bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1786. bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
  1787. bind(track, "click", onClick, {
  1788. capture: true
  1789. });
  1790. bind(track, "dragstart", prevent);
  1791. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1792. }
  1793. function init() {
  1794. var drag = options.drag;
  1795. disable(!drag);
  1796. isFree = drag === "free";
  1797. }
  1798. function onPointerDown(e) {
  1799. if (!disabled) {
  1800. var noDrag = options.noDrag;
  1801. var isTouch = isTouchEvent(e);
  1802. var isDraggable = !noDrag || !matches(e.target, noDrag);
  1803. clickPrevented = false;
  1804. if (isDraggable && (isTouch || !e.button)) {
  1805. if (!Move.isBusy()) {
  1806. target = isTouch ? track : window;
  1807. prevBaseEvent = null;
  1808. lastEvent = null;
  1809. bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
  1810. bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
  1811. Move.cancel();
  1812. Scroll.cancel();
  1813. save(e);
  1814. } else {
  1815. prevent(e, true);
  1816. }
  1817. }
  1818. }
  1819. }
  1820. function onPointerMove(e) {
  1821. if (!lastEvent) {
  1822. emit(EVENT_DRAG);
  1823. }
  1824. lastEvent = e;
  1825. if (e.cancelable) {
  1826. var diff = coordOf(e) - coordOf(baseEvent);
  1827. if (dragging) {
  1828. Move.translate(basePosition + constrain(diff));
  1829. var expired = timeOf(e) - timeOf(baseEvent) > LOG_INTERVAL;
  1830. var exceeded = hasExceeded !== (hasExceeded = exceededLimit());
  1831. if (expired || exceeded) {
  1832. save(e);
  1833. }
  1834. emit(EVENT_DRAGGING);
  1835. clickPrevented = true;
  1836. prevent(e);
  1837. } else {
  1838. var thresholds = options.dragMinThreshold;
  1839. thresholds = isObject(thresholds) ? thresholds : {
  1840. mouse: 0,
  1841. touch: +thresholds || 10
  1842. };
  1843. dragging = abs(diff) > (isTouchEvent(e) ? thresholds.touch : thresholds.mouse);
  1844. if (isSliderDirection()) {
  1845. prevent(e);
  1846. }
  1847. }
  1848. }
  1849. }
  1850. function onPointerUp(e) {
  1851. unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1852. unbind(target, POINTER_UP_EVENTS, onPointerUp);
  1853. var index = Splide2.index;
  1854. if (lastEvent) {
  1855. if (dragging || e.cancelable && isSliderDirection()) {
  1856. var velocity = computeVelocity(e);
  1857. var destination = computeDestination(velocity);
  1858. if (isFree) {
  1859. Controller.scroll(destination);
  1860. } else if (Splide2.is(FADE)) {
  1861. Controller.go(index + orient(sign(velocity)));
  1862. } else {
  1863. Controller.go(Controller.toDest(destination), true);
  1864. }
  1865. prevent(e);
  1866. }
  1867. emit(EVENT_DRAGGED);
  1868. } else {
  1869. if (!isFree && getPosition() !== Move.toPosition(index)) {
  1870. Controller.go(index, true);
  1871. }
  1872. }
  1873. dragging = false;
  1874. }
  1875. function save(e) {
  1876. prevBaseEvent = baseEvent;
  1877. baseEvent = e;
  1878. basePosition = getPosition();
  1879. }
  1880. function onClick(e) {
  1881. if (!disabled && clickPrevented) {
  1882. prevent(e, true);
  1883. }
  1884. }
  1885. function isSliderDirection() {
  1886. var diffX = abs(coordOf(lastEvent) - coordOf(baseEvent));
  1887. var diffY = abs(coordOf(lastEvent, true) - coordOf(baseEvent, true));
  1888. return diffX > diffY;
  1889. }
  1890. function computeVelocity(e) {
  1891. if (Splide2.is(LOOP) || !hasExceeded) {
  1892. var base = baseEvent === lastEvent && prevBaseEvent || baseEvent;
  1893. var diffCoord = coordOf(lastEvent) - coordOf(base);
  1894. var diffTime = timeOf(e) - timeOf(base);
  1895. var isFlick = timeOf(e) - timeOf(lastEvent) < LOG_INTERVAL;
  1896. if (diffTime && isFlick) {
  1897. return diffCoord / diffTime;
  1898. }
  1899. }
  1900. return 0;
  1901. }
  1902. function computeDestination(velocity) {
  1903. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1904. }
  1905. function coordOf(e, orthogonal) {
  1906. return (isTouchEvent(e) ? e.touches[0] : e)["page" + resolve(orthogonal ? "Y" : "X")];
  1907. }
  1908. function timeOf(e) {
  1909. return e.timeStamp;
  1910. }
  1911. function constrain(diff) {
  1912. return diff / (hasExceeded && Splide2.is(SLIDE) ? FRICTION : 1);
  1913. }
  1914. function isTouchEvent(e) {
  1915. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1916. }
  1917. function isDragging() {
  1918. return dragging;
  1919. }
  1920. function disable(value) {
  1921. disabled = value;
  1922. }
  1923. return {
  1924. mount: mount,
  1925. disable: disable,
  1926. isDragging: isDragging
  1927. };
  1928. }
  1929. var IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1930. var KEYBOARD_EVENT = "keydown";
  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 = Splide2.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 keyboard = options.keyboard;
  1947. if (keyboard) {
  1948. if (keyboard === "focused") {
  1949. target = root;
  1950. setAttribute(root, TAB_INDEX, 0);
  1951. } else {
  1952. target = window;
  1953. }
  1954. bind(target, KEYBOARD_EVENT, onKeydown);
  1955. }
  1956. }
  1957. function destroy() {
  1958. unbind(target, KEYBOARD_EVENT);
  1959. if (isHTMLElement(target)) {
  1960. removeAttribute(target, TAB_INDEX);
  1961. }
  1962. }
  1963. function disable(value) {
  1964. disabled = value;
  1965. }
  1966. function onMove() {
  1967. var _disabled = disabled;
  1968. disabled = true;
  1969. nextTick(function () {
  1970. disabled = _disabled;
  1971. });
  1972. }
  1973. function onUpdated() {
  1974. destroy();
  1975. init();
  1976. }
  1977. function onKeydown(e) {
  1978. if (!disabled) {
  1979. var key = e.key;
  1980. var normalizedKey = includes(IE_ARROW_KEYS, key) ? "Arrow" + key : key;
  1981. if (normalizedKey === resolve("ArrowLeft")) {
  1982. Splide2.go("<");
  1983. } else if (normalizedKey === resolve("ArrowRight")) {
  1984. Splide2.go(">");
  1985. }
  1986. }
  1987. }
  1988. return {
  1989. mount: mount,
  1990. destroy: destroy,
  1991. disable: disable
  1992. };
  1993. }
  1994. var SRC_DATA_ATTRIBUTE = DATA_ATTRIBUTE + "-lazy";
  1995. var SRCSET_DATA_ATTRIBUTE = SRC_DATA_ATTRIBUTE + "-srcset";
  1996. var IMAGE_SELECTOR = "[" + SRC_DATA_ATTRIBUTE + "], [" + SRCSET_DATA_ATTRIBUTE + "]";
  1997. function LazyLoad(Splide2, Components2, options) {
  1998. var _EventInterface14 = EventInterface(Splide2),
  1999. on = _EventInterface14.on,
  2000. off = _EventInterface14.off,
  2001. bind = _EventInterface14.bind,
  2002. emit = _EventInterface14.emit;
  2003. var isSequential = options.lazyLoad === "sequential";
  2004. var images = [];
  2005. var index = 0;
  2006. function mount() {
  2007. if (options.lazyLoad) {
  2008. init();
  2009. on(EVENT_REFRESH, refresh);
  2010. if (!isSequential) {
  2011. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED, EVENT_SCROLLED], observe);
  2012. }
  2013. }
  2014. }
  2015. function refresh() {
  2016. destroy();
  2017. init();
  2018. }
  2019. function init() {
  2020. Components2.Slides.forEach(function (_Slide) {
  2021. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach(function (_img) {
  2022. var src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  2023. var srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  2024. if (src !== _img.src || srcset !== _img.srcset) {
  2025. var className = options.classes.spinner;
  2026. var parent = _img.parentElement;
  2027. var _spinner = child(parent, "." + className) || create("span", className, parent);
  2028. setAttribute(_spinner, ROLE, "presentation");
  2029. images.push({
  2030. _img: _img,
  2031. _Slide: _Slide,
  2032. src: src,
  2033. srcset: srcset,
  2034. _spinner: _spinner
  2035. });
  2036. !_img.src && display(_img, "none");
  2037. }
  2038. });
  2039. });
  2040. if (isSequential) {
  2041. loadNext();
  2042. }
  2043. }
  2044. function destroy() {
  2045. index = 0;
  2046. images = [];
  2047. }
  2048. function observe() {
  2049. images = images.filter(function (data) {
  2050. var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  2051. if (data._Slide.isWithin(Splide2.index, distance)) {
  2052. return load(data);
  2053. }
  2054. return true;
  2055. });
  2056. if (!images.length) {
  2057. off(EVENT_MOVED);
  2058. }
  2059. }
  2060. function load(data) {
  2061. var _img = data._img;
  2062. addClass(data._Slide.slide, CLASS_LOADING);
  2063. bind(_img, "load error", function (e) {
  2064. onLoad(data, e.type === "error");
  2065. });
  2066. ["src", "srcset"].forEach(function (name) {
  2067. if (data[name]) {
  2068. setAttribute(_img, name, data[name]);
  2069. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  2070. }
  2071. });
  2072. }
  2073. function onLoad(data, error) {
  2074. var _Slide = data._Slide;
  2075. removeClass(_Slide.slide, CLASS_LOADING);
  2076. if (!error) {
  2077. remove(data._spinner);
  2078. display(data._img, "");
  2079. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  2080. emit(EVENT_RESIZE);
  2081. }
  2082. if (isSequential) {
  2083. loadNext();
  2084. }
  2085. }
  2086. function loadNext() {
  2087. if (index < images.length) {
  2088. load(images[index++]);
  2089. }
  2090. }
  2091. return {
  2092. mount: mount,
  2093. destroy: destroy
  2094. };
  2095. }
  2096. function Pagination(Splide2, Components2, options) {
  2097. var _EventInterface15 = EventInterface(Splide2),
  2098. on = _EventInterface15.on,
  2099. emit = _EventInterface15.emit,
  2100. bind = _EventInterface15.bind,
  2101. unbind = _EventInterface15.unbind;
  2102. var Slides = Components2.Slides,
  2103. Elements = Components2.Elements,
  2104. Controller = Components2.Controller;
  2105. var hasFocus = Controller.hasFocus,
  2106. getIndex = Controller.getIndex;
  2107. var items = [];
  2108. var list;
  2109. function mount() {
  2110. init();
  2111. on([EVENT_UPDATED, EVENT_REFRESH], init);
  2112. on([EVENT_MOVE, EVENT_SCROLLED], update);
  2113. }
  2114. function init() {
  2115. destroy();
  2116. if (options.pagination && Slides.isEnough()) {
  2117. createPagination();
  2118. emit(EVENT_PAGINATION_MOUNTED, {
  2119. list: list,
  2120. items: items
  2121. }, getAt(Splide2.index));
  2122. update();
  2123. }
  2124. }
  2125. function destroy() {
  2126. if (list) {
  2127. remove(list);
  2128. items.forEach(function (item) {
  2129. unbind(item.button, "click");
  2130. });
  2131. empty(items);
  2132. list = null;
  2133. }
  2134. }
  2135. function createPagination() {
  2136. var length = Splide2.length;
  2137. var classes = options.classes,
  2138. i18n = options.i18n,
  2139. perPage = options.perPage;
  2140. var parent = options.pagination === "slider" && Elements.slider || Elements.root;
  2141. var max = hasFocus() ? length : ceil(length / perPage);
  2142. list = create("ul", classes.pagination, parent);
  2143. for (var i = 0; i < max; i++) {
  2144. var li = create("li", null, list);
  2145. var button = create("button", {
  2146. class: classes.page,
  2147. type: "button"
  2148. }, li);
  2149. var controls = Slides.getIn(i).map(function (Slide) {
  2150. return Slide.slide.id;
  2151. });
  2152. var text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  2153. bind(button, "click", onClick.bind(null, i));
  2154. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  2155. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  2156. items.push({
  2157. li: li,
  2158. button: button,
  2159. page: i
  2160. });
  2161. }
  2162. }
  2163. function onClick(page) {
  2164. Controller.go(">" + page, true, function () {
  2165. var Slide = Slides.getAt(Controller.toIndex(page));
  2166. Slide && focus(Slide.slide);
  2167. });
  2168. }
  2169. function getAt(index) {
  2170. return items[Controller.toPage(index)];
  2171. }
  2172. function update() {
  2173. var prev = getAt(getIndex(true));
  2174. var curr = getAt(getIndex());
  2175. if (prev) {
  2176. removeClass(prev.button, CLASS_ACTIVE);
  2177. removeAttribute(prev.button, ARIA_CURRENT);
  2178. }
  2179. if (curr) {
  2180. addClass(curr.button, CLASS_ACTIVE);
  2181. setAttribute(curr.button, ARIA_CURRENT, true);
  2182. }
  2183. emit(EVENT_PAGINATION_UPDATED, {
  2184. list: list,
  2185. items: items
  2186. }, prev, curr);
  2187. }
  2188. return {
  2189. items: items,
  2190. mount: mount,
  2191. destroy: destroy,
  2192. getAt: getAt,
  2193. update: update
  2194. };
  2195. }
  2196. var TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2197. function Sync(Splide2, Components2, options) {
  2198. var list = Components2.Elements.list;
  2199. var events = [];
  2200. function mount() {
  2201. Splide2.splides.forEach(function (target) {
  2202. !target.isParent && sync(target.splide);
  2203. });
  2204. if (options.isNavigation) {
  2205. navigate();
  2206. }
  2207. }
  2208. function destroy() {
  2209. removeAttribute(list, ALL_ATTRIBUTES);
  2210. events.forEach(function (event) {
  2211. event.destroy();
  2212. });
  2213. empty(events);
  2214. }
  2215. function remount() {
  2216. destroy();
  2217. mount();
  2218. }
  2219. function sync(splide) {
  2220. [Splide2, splide].forEach(function (instance) {
  2221. var event = EventInterface(instance);
  2222. var target = instance === Splide2 ? splide : Splide2;
  2223. event.on(EVENT_MOVE, function (index, prev, dest) {
  2224. target.go(target.is(LOOP) ? dest : index);
  2225. });
  2226. events.push(event);
  2227. });
  2228. }
  2229. function navigate() {
  2230. var event = EventInterface(Splide2);
  2231. var on = event.on;
  2232. on(EVENT_CLICK, onClick);
  2233. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2234. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2235. setAttribute(list, ROLE, "menu");
  2236. events.push(event);
  2237. event.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2238. }
  2239. function update() {
  2240. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2241. }
  2242. function onClick(Slide) {
  2243. Splide2.go(Slide.index);
  2244. }
  2245. function onKeydown(Slide, e) {
  2246. if (includes(TRIGGER_KEYS, e.key)) {
  2247. onClick(Slide);
  2248. prevent(e);
  2249. }
  2250. }
  2251. return {
  2252. mount: mount,
  2253. destroy: destroy,
  2254. remount: remount
  2255. };
  2256. }
  2257. function Wheel(Splide2, Components2, options) {
  2258. var _EventInterface16 = EventInterface(Splide2),
  2259. bind = _EventInterface16.bind;
  2260. function mount() {
  2261. if (options.wheel) {
  2262. bind(Components2.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
  2263. }
  2264. }
  2265. function onWheel(e) {
  2266. if (e.cancelable) {
  2267. var deltaY = e.deltaY;
  2268. if (deltaY) {
  2269. var backwards = deltaY < 0;
  2270. Splide2.go(backwards ? "<" : ">");
  2271. shouldPrevent(backwards) && prevent(e);
  2272. }
  2273. }
  2274. }
  2275. function shouldPrevent(backwards) {
  2276. return !options.releaseWheel || Splide2.state.is(MOVING) || Components2.Controller.getAdjacent(backwards) !== -1;
  2277. }
  2278. return {
  2279. mount: mount
  2280. };
  2281. }
  2282. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2283. __proto__: null,
  2284. Options: Options,
  2285. Direction: Direction,
  2286. Elements: Elements,
  2287. Slides: Slides,
  2288. Layout: Layout,
  2289. Clones: Clones,
  2290. Move: Move,
  2291. Controller: Controller,
  2292. Arrows: Arrows,
  2293. Autoplay: Autoplay,
  2294. Cover: Cover,
  2295. Scroll: Scroll,
  2296. Drag: Drag,
  2297. Keyboard: Keyboard,
  2298. LazyLoad: LazyLoad,
  2299. Pagination: Pagination,
  2300. Sync: Sync,
  2301. Wheel: Wheel
  2302. });
  2303. var I18N = {
  2304. prev: "Previous slide",
  2305. next: "Next slide",
  2306. first: "Go to first slide",
  2307. last: "Go to last slide",
  2308. slideX: "Go to slide %s",
  2309. pageX: "Go to page %s",
  2310. play: "Start autoplay",
  2311. pause: "Pause autoplay"
  2312. };
  2313. var DEFAULTS = {
  2314. type: "slide",
  2315. speed: 400,
  2316. waitForTransition: true,
  2317. perPage: 1,
  2318. cloneStatus: true,
  2319. arrows: true,
  2320. pagination: true,
  2321. interval: 5e3,
  2322. pauseOnHover: true,
  2323. pauseOnFocus: true,
  2324. resetProgress: true,
  2325. keyboard: true,
  2326. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  2327. drag: true,
  2328. direction: "ltr",
  2329. slideFocus: true,
  2330. trimSpace: true,
  2331. focusableNodes: "a, button, textarea, input, select, iframe",
  2332. classes: CLASSES,
  2333. i18n: I18N
  2334. };
  2335. function Fade(Splide2, Components2, options) {
  2336. var _EventInterface17 = EventInterface(Splide2),
  2337. on = _EventInterface17.on;
  2338. function mount() {
  2339. on([EVENT_MOUNTED, EVENT_REFRESH], function () {
  2340. nextTick(function () {
  2341. Components2.Slides.style("transition", "opacity " + options.speed + "ms " + options.easing);
  2342. });
  2343. });
  2344. }
  2345. function start(index, done) {
  2346. var track = Components2.Elements.track;
  2347. style(track, "height", unit(rect(track).height));
  2348. nextTick(function () {
  2349. done();
  2350. style(track, "height", "");
  2351. });
  2352. }
  2353. return {
  2354. mount: mount,
  2355. start: start,
  2356. cancel: noop
  2357. };
  2358. }
  2359. function Slide(Splide2, Components2, options) {
  2360. var _EventInterface18 = EventInterface(Splide2),
  2361. bind = _EventInterface18.bind;
  2362. var Move = Components2.Move,
  2363. Controller = Components2.Controller;
  2364. var list = Components2.Elements.list;
  2365. var endCallback;
  2366. function mount() {
  2367. bind(list, "transitionend", function (e) {
  2368. if (e.target === list && endCallback) {
  2369. cancel();
  2370. endCallback();
  2371. }
  2372. });
  2373. }
  2374. function start(index, done) {
  2375. var destination = Move.toPosition(index, true);
  2376. var position = Move.getPosition();
  2377. var speed = getSpeed(index);
  2378. if (abs(destination - position) >= 1 && speed >= 1) {
  2379. apply("transform " + speed + "ms " + options.easing);
  2380. Move.translate(destination, true);
  2381. endCallback = done;
  2382. } else {
  2383. Move.jump(index);
  2384. done();
  2385. }
  2386. }
  2387. function cancel() {
  2388. apply("");
  2389. }
  2390. function getSpeed(index) {
  2391. var rewindSpeed = options.rewindSpeed;
  2392. if (Splide2.is(SLIDE) && rewindSpeed) {
  2393. var prev = Controller.getIndex(true);
  2394. var end = Controller.getEnd();
  2395. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2396. return rewindSpeed;
  2397. }
  2398. }
  2399. return options.speed;
  2400. }
  2401. function apply(transition) {
  2402. style(list, "transition", transition);
  2403. }
  2404. return {
  2405. mount: mount,
  2406. start: start,
  2407. cancel: cancel
  2408. };
  2409. }
  2410. var _Splide = /*#__PURE__*/function () {
  2411. function _Splide(target, options) {
  2412. this.event = EventBus();
  2413. this.Components = {};
  2414. this.state = State(CREATED);
  2415. this.splides = [];
  2416. this._options = {};
  2417. this._Extensions = {};
  2418. var root = isString(target) ? query(document, target) : target;
  2419. assert(root, root + " is invalid.");
  2420. this.root = root;
  2421. merge(DEFAULTS, _Splide.defaults);
  2422. merge(merge(this._options, DEFAULTS), options || {});
  2423. }
  2424. var _proto = _Splide.prototype;
  2425. _proto.mount = function mount(Extensions, Transition) {
  2426. var _this2 = this;
  2427. var state = this.state,
  2428. Components2 = this.Components;
  2429. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2430. state.set(CREATED);
  2431. this._Components = Components2;
  2432. this._Transition = Transition || this._Transition || (this.is(FADE) ? Fade : Slide);
  2433. this._Extensions = Extensions || this._Extensions;
  2434. var Constructors = assign({}, ComponentConstructors, this._Extensions, {
  2435. Transition: this._Transition
  2436. });
  2437. forOwn(Constructors, function (Component, key) {
  2438. var component = Component(_this2, Components2, _this2._options);
  2439. Components2[key] = component;
  2440. component.setup && component.setup();
  2441. });
  2442. forOwn(Components2, function (component) {
  2443. component.mount && component.mount();
  2444. });
  2445. this.emit(EVENT_MOUNTED);
  2446. addClass(this.root, CLASS_INITIALIZED);
  2447. state.set(IDLE);
  2448. this.emit(EVENT_READY);
  2449. return this;
  2450. };
  2451. _proto.sync = function sync(splide) {
  2452. this.splides.push({
  2453. splide: splide
  2454. });
  2455. splide.splides.push({
  2456. splide: this,
  2457. isParent: true
  2458. });
  2459. if (this.state.is(IDLE)) {
  2460. this._Components.Sync.remount();
  2461. splide.Components.Sync.remount();
  2462. }
  2463. return this;
  2464. };
  2465. _proto.go = function go(control) {
  2466. this._Components.Controller.go(control);
  2467. return this;
  2468. };
  2469. _proto.on = function on(events, callback) {
  2470. this.event.on(events, callback, null, DEFAULT_USER_EVENT_PRIORITY);
  2471. return this;
  2472. };
  2473. _proto.off = function off(events) {
  2474. this.event.off(events);
  2475. return this;
  2476. };
  2477. _proto.emit = function emit(event) {
  2478. var _this$event;
  2479. (_this$event = this.event).emit.apply(_this$event, [event].concat(slice(arguments, 1)));
  2480. return this;
  2481. };
  2482. _proto.add = function add(slides, index) {
  2483. this._Components.Slides.add(slides, index);
  2484. return this;
  2485. };
  2486. _proto.remove = function remove(matcher) {
  2487. this._Components.Slides.remove(matcher);
  2488. return this;
  2489. };
  2490. _proto.is = function is(type) {
  2491. return this._options.type === type;
  2492. };
  2493. _proto.refresh = function refresh() {
  2494. this.emit(EVENT_REFRESH);
  2495. return this;
  2496. };
  2497. _proto.destroy = function destroy(completely) {
  2498. if (completely === void 0) {
  2499. completely = true;
  2500. }
  2501. var event = this.event,
  2502. state = this.state;
  2503. if (state.is(CREATED)) {
  2504. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  2505. } else {
  2506. forOwn(this._Components, function (component) {
  2507. component.destroy && component.destroy(completely);
  2508. }, true);
  2509. event.emit(EVENT_DESTROY);
  2510. event.destroy();
  2511. completely && empty(this.splides);
  2512. state.set(DESTROYED);
  2513. }
  2514. return this;
  2515. };
  2516. _createClass(_Splide, [{
  2517. key: "options",
  2518. get: function get() {
  2519. return this._options;
  2520. },
  2521. set: function set(options) {
  2522. var _options = this._options;
  2523. merge(_options, options);
  2524. if (!this.state.is(CREATED)) {
  2525. this.emit(EVENT_UPDATED, _options);
  2526. }
  2527. }
  2528. }, {
  2529. key: "length",
  2530. get: function get() {
  2531. return this._Components.Slides.getLength(true);
  2532. }
  2533. }, {
  2534. key: "index",
  2535. get: function get() {
  2536. return this._Components.Controller.getIndex();
  2537. }
  2538. }]);
  2539. return _Splide;
  2540. }();
  2541. var Splide = _Splide;
  2542. Splide.defaults = {};
  2543. Splide.STATES = STATES;
  2544. return Splide;
  2545. });
  2546. //# sourceMappingURL=splide.js.map