splide.js 79 KB

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