splide.cjs.js 83 KB

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