splide.esm.js 81 KB

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