splide.esm.js 81 KB

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