splide.js 78 KB

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