splide.js 79 KB

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