splide.js 83 KB

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