splide.js 77 KB

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