splide.cjs.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928
  1. /*!
  2. * Splide.js
  3. * Version : 3.6.14
  4. * License : MIT
  5. * Copyright: 2022 Naotoshi Fujita
  6. */
  7. 'use strict';
  8. Object.defineProperty(exports, '__esModule', { value: true });
  9. const EVENT_MOUNTED = "mounted";
  10. const EVENT_READY = "ready";
  11. const EVENT_MOVE = "move";
  12. const EVENT_MOVED = "moved";
  13. const EVENT_SHIFTED = "shifted";
  14. const EVENT_CLICK = "click";
  15. const EVENT_ACTIVE = "active";
  16. const EVENT_INACTIVE = "inactive";
  17. const EVENT_VISIBLE = "visible";
  18. const EVENT_HIDDEN = "hidden";
  19. const EVENT_SLIDE_KEYDOWN = "slide:keydown";
  20. const EVENT_REFRESH = "refresh";
  21. const EVENT_UPDATED = "updated";
  22. const EVENT_MEDIA = "media";
  23. const EVENT_RESIZE = "resize";
  24. const EVENT_RESIZED = "resized";
  25. const EVENT_REPOSITIONED = "repositioned";
  26. const EVENT_DRAG = "drag";
  27. const EVENT_DRAGGING = "dragging";
  28. const EVENT_DRAGGED = "dragged";
  29. const EVENT_SCROLL = "scroll";
  30. const EVENT_SCROLLED = "scrolled";
  31. const EVENT_DESTROY = "destroy";
  32. const EVENT_ARROWS_MOUNTED = "arrows:mounted";
  33. const EVENT_ARROWS_UPDATED = "arrows:updated";
  34. const EVENT_PAGINATION_MOUNTED = "pagination:mounted";
  35. const EVENT_PAGINATION_UPDATED = "pagination:updated";
  36. const EVENT_NAVIGATION_MOUNTED = "navigation:mounted";
  37. const EVENT_AUTOPLAY_PLAY = "autoplay:play";
  38. const EVENT_AUTOPLAY_PLAYING = "autoplay:playing";
  39. const EVENT_AUTOPLAY_PAUSE = "autoplay:pause";
  40. const EVENT_LAZYLOAD_LOADED = "lazyload:loaded";
  41. const CREATED = 1;
  42. const MOUNTED = 2;
  43. const IDLE = 3;
  44. const MOVING = 4;
  45. const DRAGGING = 5;
  46. const DESTROYED = 6;
  47. const STATES = {
  48. CREATED,
  49. MOUNTED,
  50. IDLE,
  51. MOVING,
  52. DRAGGING,
  53. DESTROYED
  54. };
  55. const DEFAULT_EVENT_PRIORITY = 10;
  56. const DEFAULT_USER_EVENT_PRIORITY = 20;
  57. function empty(array) {
  58. array.length = 0;
  59. }
  60. function slice(arrayLike, start, end) {
  61. return Array.prototype.slice.call(arrayLike, start, end);
  62. }
  63. function find(arrayLike, predicate) {
  64. return slice(arrayLike).filter(predicate)[0];
  65. }
  66. function apply(func) {
  67. return func.bind(null, ...slice(arguments, 1));
  68. }
  69. const nextTick = setTimeout;
  70. const noop = () => {
  71. };
  72. function raf(func) {
  73. return requestAnimationFrame(func);
  74. }
  75. function typeOf(type, subject) {
  76. return typeof subject === type;
  77. }
  78. function isObject(subject) {
  79. return !isNull(subject) && typeOf("object", subject);
  80. }
  81. const isArray = Array.isArray;
  82. const isFunction = apply(typeOf, "function");
  83. const isString = apply(typeOf, "string");
  84. const isUndefined = apply(typeOf, "undefined");
  85. function isNull(subject) {
  86. return subject === null;
  87. }
  88. function isHTMLElement(subject) {
  89. return subject instanceof HTMLElement;
  90. }
  91. function toArray(value) {
  92. return isArray(value) ? value : [value];
  93. }
  94. function forEach(values, iteratee) {
  95. toArray(values).forEach(iteratee);
  96. }
  97. function includes(array, value) {
  98. return array.indexOf(value) > -1;
  99. }
  100. function push(array, items) {
  101. array.push(...toArray(items));
  102. return array;
  103. }
  104. function toggleClass(elm, classes, add) {
  105. if (elm) {
  106. forEach(classes, (name) => {
  107. if (name) {
  108. elm.classList[add ? "add" : "remove"](name);
  109. }
  110. });
  111. }
  112. }
  113. function addClass(elm, classes) {
  114. toggleClass(elm, isString(classes) ? classes.split(" ") : classes, true);
  115. }
  116. function append(parent, children) {
  117. forEach(children, parent.appendChild.bind(parent));
  118. }
  119. function before(nodes, ref) {
  120. forEach(nodes, (node) => {
  121. const parent = ref.parentNode;
  122. if (parent) {
  123. parent.insertBefore(node, ref);
  124. }
  125. });
  126. }
  127. function matches(elm, selector) {
  128. return isHTMLElement(elm) && (elm["msMatchesSelector"] || elm.matches).call(elm, selector);
  129. }
  130. function children(parent, selector) {
  131. return parent ? slice(parent.children).filter((child) => matches(child, selector)) : [];
  132. }
  133. function child(parent, selector) {
  134. return selector ? children(parent, selector)[0] : parent.firstElementChild;
  135. }
  136. function forOwn(object, iteratee, right) {
  137. if (object) {
  138. let keys = Object.keys(object);
  139. keys = right ? keys.reverse() : keys;
  140. for (let i = 0; i < keys.length; i++) {
  141. const key = keys[i];
  142. if (key !== "__proto__") {
  143. if (iteratee(object[key], key) === false) {
  144. break;
  145. }
  146. }
  147. }
  148. }
  149. return object;
  150. }
  151. function assign(object) {
  152. slice(arguments, 1).forEach((source) => {
  153. forOwn(source, (value, key) => {
  154. object[key] = source[key];
  155. });
  156. });
  157. return object;
  158. }
  159. function merge(object) {
  160. slice(arguments).forEach((source) => {
  161. forOwn(source, (value, key) => {
  162. if (isArray(value)) {
  163. object[key] = value.slice();
  164. } else if (isObject(value)) {
  165. object[key] = merge(isObject(object[key]) ? object[key] : {}, value);
  166. } else {
  167. object[key] = value;
  168. }
  169. });
  170. });
  171. return object;
  172. }
  173. function removeAttribute(elms, attrs) {
  174. forEach(elms, (elm) => {
  175. forEach(attrs, (attr) => {
  176. elm && elm.removeAttribute(attr);
  177. });
  178. });
  179. }
  180. function setAttribute(elms, attrs, value) {
  181. if (isObject(attrs)) {
  182. forOwn(attrs, (value2, name) => {
  183. setAttribute(elms, name, value2);
  184. });
  185. } else {
  186. forEach(elms, (elm) => {
  187. isNull(value) ? removeAttribute(elm, attrs) : elm.setAttribute(attrs, String(value));
  188. });
  189. }
  190. }
  191. function create(tag, attrs, parent) {
  192. const elm = document.createElement(tag);
  193. if (attrs) {
  194. isString(attrs) ? addClass(elm, attrs) : setAttribute(elm, attrs);
  195. }
  196. parent && append(parent, elm);
  197. return elm;
  198. }
  199. function style(elm, prop, value) {
  200. if (isUndefined(value)) {
  201. return getComputedStyle(elm)[prop];
  202. }
  203. if (!isNull(value)) {
  204. const { style: style2 } = elm;
  205. value = `${value}`;
  206. if (style2[prop] !== value) {
  207. style2[prop] = value;
  208. }
  209. }
  210. }
  211. function display(elm, display2) {
  212. style(elm, "display", display2);
  213. }
  214. function focus(elm) {
  215. elm["setActive"] && elm["setActive"]() || elm.focus({ preventScroll: true });
  216. }
  217. function getAttribute(elm, attr) {
  218. return elm.getAttribute(attr);
  219. }
  220. function hasClass(elm, className) {
  221. return elm && elm.classList.contains(className);
  222. }
  223. function rect(target) {
  224. return target.getBoundingClientRect();
  225. }
  226. function remove(nodes) {
  227. forEach(nodes, (node) => {
  228. if (node && node.parentNode) {
  229. node.parentNode.removeChild(node);
  230. }
  231. });
  232. }
  233. function measure(parent, value) {
  234. if (isString(value)) {
  235. const div = create("div", { style: `width: ${value}; position: absolute;` }, parent);
  236. value = rect(div).width;
  237. remove(div);
  238. }
  239. return value;
  240. }
  241. function parseHtml(html) {
  242. return child(new DOMParser().parseFromString(html, "text/html").body);
  243. }
  244. function prevent(e, stopPropagation) {
  245. e.preventDefault();
  246. if (stopPropagation) {
  247. e.stopPropagation();
  248. e.stopImmediatePropagation();
  249. }
  250. }
  251. function query(parent, selector) {
  252. return parent && parent.querySelector(selector);
  253. }
  254. function queryAll(parent, selector) {
  255. return slice(parent.querySelectorAll(selector));
  256. }
  257. function removeClass(elm, classes) {
  258. toggleClass(elm, classes, false);
  259. }
  260. function timeOf(e) {
  261. return e.timeStamp;
  262. }
  263. function unit(value) {
  264. return isString(value) ? value : value ? `${value}px` : "";
  265. }
  266. const PROJECT_CODE = "splide";
  267. const DATA_ATTRIBUTE = `data-${PROJECT_CODE}`;
  268. function assert(condition, message) {
  269. if (!condition) {
  270. throw new Error(`[${PROJECT_CODE}] ${message || ""}`);
  271. }
  272. }
  273. const { min, max, floor, ceil, abs } = Math;
  274. function approximatelyEqual(x, y, epsilon) {
  275. return abs(x - y) < epsilon;
  276. }
  277. function between(number, minOrMax, maxOrMin, exclusive) {
  278. const minimum = min(minOrMax, maxOrMin);
  279. const maximum = max(minOrMax, maxOrMin);
  280. return exclusive ? minimum < number && number < maximum : minimum <= number && number <= maximum;
  281. }
  282. function clamp(number, x, y) {
  283. const minimum = min(x, y);
  284. const maximum = max(x, y);
  285. return min(max(minimum, number), maximum);
  286. }
  287. function sign(x) {
  288. return +(x > 0) - +(x < 0);
  289. }
  290. function camelToKebab(string) {
  291. return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
  292. }
  293. function format(string, replacements) {
  294. forEach(replacements, (replacement) => {
  295. string = string.replace("%s", `${replacement}`);
  296. });
  297. return string;
  298. }
  299. function pad(number) {
  300. return number < 10 ? `0${number}` : `${number}`;
  301. }
  302. const ids = {};
  303. function uniqueId(prefix) {
  304. return `${prefix}${pad(ids[prefix] = (ids[prefix] || 0) + 1)}`;
  305. }
  306. function EventBus() {
  307. let handlers = {};
  308. function on(events, callback, key, priority = DEFAULT_EVENT_PRIORITY) {
  309. forEachEvent(events, (event, namespace) => {
  310. const events2 = handlers[event] = handlers[event] || [];
  311. events2.push([callback, namespace, priority, key]);
  312. events2.sort((handler1, handler2) => handler1[2] - handler2[2]);
  313. });
  314. }
  315. function off(events, key) {
  316. forEachEvent(events, (event, namespace) => {
  317. handlers[event] = (handlers[event] || []).filter((handler) => {
  318. return handler[3] ? handler[3] !== key : key || handler[1] !== namespace;
  319. });
  320. });
  321. }
  322. function offBy(key) {
  323. forOwn(handlers, (eventHandlers, event) => {
  324. off(event, key);
  325. });
  326. }
  327. function emit(event) {
  328. (handlers[event] || []).forEach((handler) => {
  329. handler[0].apply(handler, slice(arguments, 1));
  330. });
  331. }
  332. function destroy() {
  333. handlers = {};
  334. }
  335. function forEachEvent(events, iteratee) {
  336. toArray(events).join(" ").split(" ").forEach((eventNS) => {
  337. const fragments = eventNS.split(".");
  338. iteratee(fragments[0], fragments[1]);
  339. });
  340. }
  341. return {
  342. on,
  343. off,
  344. offBy,
  345. emit,
  346. destroy
  347. };
  348. }
  349. function EventInterface(Splide2, manual) {
  350. const { event } = Splide2;
  351. const key = {};
  352. let listeners = [];
  353. function on(events, callback, priority) {
  354. event.on(events, callback, key, priority);
  355. }
  356. function off(events) {
  357. event.off(events, key);
  358. }
  359. function bind(targets, events, callback, options) {
  360. forEachEvent(targets, events, (target, event2) => {
  361. const isEventTarget = "addEventListener" in target;
  362. const remover = isEventTarget ? target.removeEventListener.bind(target, event2, callback, options) : target["removeListener"].bind(target, callback);
  363. isEventTarget ? target.addEventListener(event2, callback, options) : target["addListener"](callback);
  364. listeners.push([target, event2, callback, remover]);
  365. });
  366. }
  367. function unbind(targets, events, callback) {
  368. forEachEvent(targets, events, (target, event2) => {
  369. listeners = listeners.filter((listener) => {
  370. if (listener[0] === target && listener[1] === event2 && (!callback || listener[2] === callback)) {
  371. listener[3]();
  372. return false;
  373. }
  374. return true;
  375. });
  376. });
  377. }
  378. function forEachEvent(targets, events, iteratee) {
  379. forEach(targets, (target) => {
  380. if (target) {
  381. events.split(" ").forEach(apply(iteratee, target));
  382. }
  383. });
  384. }
  385. function destroy() {
  386. listeners = listeners.filter((data) => {
  387. data[3]();
  388. });
  389. event.offBy(key);
  390. }
  391. !manual && event.on(EVENT_DESTROY, destroy, key);
  392. return {
  393. on,
  394. off,
  395. emit: event.emit,
  396. bind,
  397. unbind,
  398. destroy
  399. };
  400. }
  401. function RequestInterval(interval, onInterval, onUpdate, limit) {
  402. const { now } = Date;
  403. let startTime;
  404. let rate = 0;
  405. let id;
  406. let paused = true;
  407. let count = 0;
  408. function update() {
  409. if (!paused) {
  410. const elapsed = now() - startTime;
  411. if (elapsed >= interval) {
  412. rate = 1;
  413. startTime = now();
  414. } else {
  415. rate = elapsed / interval;
  416. }
  417. if (onUpdate) {
  418. onUpdate(rate);
  419. }
  420. if (rate === 1) {
  421. onInterval();
  422. if (limit && ++count >= limit) {
  423. return pause();
  424. }
  425. }
  426. raf(update);
  427. }
  428. }
  429. function start(resume) {
  430. !resume && cancel();
  431. startTime = now() - (resume ? rate * interval : 0);
  432. paused = false;
  433. raf(update);
  434. }
  435. function pause() {
  436. paused = true;
  437. }
  438. function rewind() {
  439. startTime = now();
  440. rate = 0;
  441. if (onUpdate) {
  442. onUpdate(rate);
  443. }
  444. }
  445. function cancel() {
  446. cancelAnimationFrame(id);
  447. rate = 0;
  448. id = 0;
  449. paused = true;
  450. }
  451. function set(time) {
  452. interval = time;
  453. }
  454. function isPaused() {
  455. return paused;
  456. }
  457. return {
  458. start,
  459. rewind,
  460. pause,
  461. cancel,
  462. set,
  463. isPaused
  464. };
  465. }
  466. function State(initialState) {
  467. let state = initialState;
  468. function set(value) {
  469. state = value;
  470. }
  471. function is(states) {
  472. return includes(toArray(states), state);
  473. }
  474. return { set, is };
  475. }
  476. function Throttle(func, duration) {
  477. let interval;
  478. function throttled() {
  479. if (!interval) {
  480. const args = slice(arguments);
  481. interval = RequestInterval(duration || 0, () => {
  482. func.apply(this, args);
  483. interval = null;
  484. }, null, 1);
  485. interval.start();
  486. }
  487. }
  488. return throttled;
  489. }
  490. function Media(Splide2, Components2, options) {
  491. const event = EventInterface(Splide2, true);
  492. const breakpoints = options.breakpoints || {};
  493. const userOptions = merge({}, options);
  494. const queries = [];
  495. function setup() {
  496. const isMin = options.mediaQuery === "min";
  497. register(Object.keys(breakpoints).sort((n, m) => isMin ? +m - +n : +n - +m).map((key) => [breakpoints[key], `(${isMin ? "min" : "max"}-width:${key}px)`]).concat([[userOptions]]));
  498. register([[{
  499. speed: 0,
  500. autoplay: "pause"
  501. }, "(prefers-reduced-motion: reduce)"]]);
  502. update();
  503. }
  504. function destroy(completely) {
  505. if (completely) {
  506. event.destroy();
  507. }
  508. }
  509. function register(entries) {
  510. queries.push(entries.map((entry) => {
  511. const query = entry[1] && matchMedia(entry[1]);
  512. query && event.bind(query, "change", update);
  513. return [entry[0], query];
  514. }));
  515. }
  516. function update() {
  517. const options2 = accumulate();
  518. const { destroy: _destroy } = options2;
  519. if (_destroy) {
  520. Splide2.options = userOptions;
  521. Splide2.destroy(_destroy === "completely");
  522. } else if (Splide2.state.is(DESTROYED)) {
  523. destroy(true);
  524. Splide2.mount();
  525. } else {
  526. Splide2.options = options2;
  527. }
  528. }
  529. function accumulate() {
  530. return queries.reduce((merged, entries) => {
  531. const entry = find(entries, (entry2) => !entry2[1] || entry2[1].matches) || [];
  532. entry[1] && event.emit(EVENT_MEDIA, entry[1]);
  533. return merge(merged, entry[0] || {});
  534. }, merge({}, userOptions));
  535. }
  536. return {
  537. setup,
  538. mount: noop,
  539. destroy
  540. };
  541. }
  542. const RTL = "rtl";
  543. const TTB = "ttb";
  544. const ORIENTATION_MAP = {
  545. marginRight: ["marginBottom", "marginLeft"],
  546. autoWidth: ["autoHeight"],
  547. fixedWidth: ["fixedHeight"],
  548. paddingLeft: ["paddingTop", "paddingRight"],
  549. paddingRight: ["paddingBottom", "paddingLeft"],
  550. width: ["height"],
  551. left: ["top", "right"],
  552. right: ["bottom", "left"],
  553. x: ["y"],
  554. X: ["Y"],
  555. Y: ["X"],
  556. ArrowLeft: ["ArrowUp", "ArrowRight"],
  557. ArrowRight: ["ArrowDown", "ArrowLeft"]
  558. };
  559. function Direction(Splide2, Components2, options) {
  560. function resolve(prop, axisOnly) {
  561. const { direction } = options;
  562. const index = direction === RTL && !axisOnly ? 1 : direction === TTB ? 0 : -1;
  563. return ORIENTATION_MAP[prop][index] || prop;
  564. }
  565. function orient(value) {
  566. return value * (options.direction === RTL ? 1 : -1);
  567. }
  568. return {
  569. resolve,
  570. orient
  571. };
  572. }
  573. const ROLE = "role";
  574. const TAB_INDEX = "tabindex";
  575. const DISABLED = "disabled";
  576. const ARIA_PREFIX = "aria-";
  577. const ARIA_CONTROLS = `${ARIA_PREFIX}controls`;
  578. const ARIA_CURRENT = `${ARIA_PREFIX}current`;
  579. const ARIA_LABEL = `${ARIA_PREFIX}label`;
  580. const ARIA_HIDDEN = `${ARIA_PREFIX}hidden`;
  581. const ARIA_ORIENTATION = `${ARIA_PREFIX}orientation`;
  582. const ARIA_ROLEDESCRIPTION = `${ARIA_PREFIX}roledescription`;
  583. const ARIA_ATOMIC = `${ARIA_PREFIX}atomic`;
  584. const ARIA_LIVE = `${ARIA_PREFIX}live`;
  585. const ALL_ATTRIBUTES = [
  586. ROLE,
  587. TAB_INDEX,
  588. DISABLED,
  589. ARIA_CONTROLS,
  590. ARIA_CURRENT,
  591. ARIA_LABEL,
  592. ARIA_HIDDEN,
  593. ARIA_ORIENTATION,
  594. ARIA_ROLEDESCRIPTION,
  595. ARIA_ATOMIC,
  596. ARIA_LIVE
  597. ];
  598. const CLASS_ROOT = PROJECT_CODE;
  599. const CLASS_SLIDER = `${PROJECT_CODE}__slider`;
  600. const CLASS_TRACK = `${PROJECT_CODE}__track`;
  601. const CLASS_LIST = `${PROJECT_CODE}__list`;
  602. const CLASS_SLIDE = `${PROJECT_CODE}__slide`;
  603. const CLASS_CLONE = `${CLASS_SLIDE}--clone`;
  604. const CLASS_CONTAINER = `${CLASS_SLIDE}__container`;
  605. const CLASS_ARROWS = `${PROJECT_CODE}__arrows`;
  606. const CLASS_ARROW = `${PROJECT_CODE}__arrow`;
  607. const CLASS_ARROW_PREV = `${CLASS_ARROW}--prev`;
  608. const CLASS_ARROW_NEXT = `${CLASS_ARROW}--next`;
  609. const CLASS_PAGINATION = `${PROJECT_CODE}__pagination`;
  610. const CLASS_PAGINATION_PAGE = `${CLASS_PAGINATION}__page`;
  611. const CLASS_PROGRESS = `${PROJECT_CODE}__progress`;
  612. const CLASS_PROGRESS_BAR = `${CLASS_PROGRESS}__bar`;
  613. const CLASS_AUTOPLAY = `${PROJECT_CODE}__autoplay`;
  614. const CLASS_PLAY = `${PROJECT_CODE}__play`;
  615. const CLASS_PAUSE = `${PROJECT_CODE}__pause`;
  616. const CLASS_SPINNER = `${PROJECT_CODE}__spinner`;
  617. const CLASS_SR = `${PROJECT_CODE}__sr`;
  618. const CLASS_INITIALIZED = "is-initialized";
  619. const CLASS_ACTIVE = "is-active";
  620. const CLASS_PREV = "is-prev";
  621. const CLASS_NEXT = "is-next";
  622. const CLASS_VISIBLE = "is-visible";
  623. const CLASS_LOADING = "is-loading";
  624. const STATUS_CLASSES = [CLASS_ACTIVE, CLASS_VISIBLE, CLASS_PREV, CLASS_NEXT, CLASS_LOADING];
  625. const CLASSES = {
  626. slide: CLASS_SLIDE,
  627. clone: CLASS_CLONE,
  628. arrows: CLASS_ARROWS,
  629. arrow: CLASS_ARROW,
  630. prev: CLASS_ARROW_PREV,
  631. next: CLASS_ARROW_NEXT,
  632. pagination: CLASS_PAGINATION,
  633. page: CLASS_PAGINATION_PAGE,
  634. spinner: CLASS_SPINNER
  635. };
  636. function Elements(Splide2, Components2, options) {
  637. const { on } = EventInterface(Splide2);
  638. const { root } = Splide2;
  639. const { i18n } = options;
  640. const elements = {};
  641. const slides = [];
  642. let classes;
  643. let slider;
  644. let track;
  645. let list;
  646. function setup() {
  647. collect();
  648. init();
  649. addClass(root, classes = getClasses());
  650. }
  651. function mount() {
  652. on(EVENT_REFRESH, destroy);
  653. on(EVENT_REFRESH, setup);
  654. on(EVENT_UPDATED, update);
  655. }
  656. function destroy() {
  657. empty(slides);
  658. removeClass(root, classes);
  659. removeAttribute([root, track, list], ALL_ATTRIBUTES.concat("style"));
  660. }
  661. function update() {
  662. removeClass(root, classes);
  663. addClass(root, classes = getClasses());
  664. }
  665. function collect() {
  666. slider = child(root, `.${CLASS_SLIDER}`);
  667. track = query(root, `.${CLASS_TRACK}`);
  668. list = child(track, `.${CLASS_LIST}`);
  669. assert(track && list, "A track/list element is missing.");
  670. push(slides, children(list, `.${CLASS_SLIDE}:not(.${CLASS_CLONE})`));
  671. const autoplay = find(`.${CLASS_AUTOPLAY}`);
  672. const arrows = find(`.${CLASS_ARROWS}`);
  673. assign(elements, {
  674. root,
  675. slider,
  676. track,
  677. list,
  678. slides,
  679. arrows,
  680. autoplay,
  681. prev: query(arrows, `.${CLASS_ARROW_PREV}`),
  682. next: query(arrows, `.${CLASS_ARROW_NEXT}`),
  683. bar: query(find(`.${CLASS_PROGRESS}`), `.${CLASS_PROGRESS_BAR}`),
  684. play: query(autoplay, `.${CLASS_PLAY}`),
  685. pause: query(autoplay, `.${CLASS_PAUSE}`)
  686. });
  687. }
  688. function init() {
  689. const id = root.id || uniqueId(PROJECT_CODE);
  690. root.id = id;
  691. track.id = track.id || `${id}-track`;
  692. list.id = list.id || `${id}-list`;
  693. setAttribute(root, ARIA_ROLEDESCRIPTION, i18n.carousel);
  694. setAttribute(root, ROLE, root.tagName !== "SECTION" && options.role || null);
  695. setAttribute(list, ROLE, "none");
  696. }
  697. function find(selector) {
  698. return child(root, selector) || child(slider, selector);
  699. }
  700. function getClasses() {
  701. return [
  702. `${CLASS_ROOT}--${options.type}`,
  703. `${CLASS_ROOT}--${options.direction}`,
  704. options.drag && `${CLASS_ROOT}--draggable`,
  705. options.isNavigation && `${CLASS_ROOT}--nav`,
  706. CLASS_ACTIVE
  707. ];
  708. }
  709. return assign(elements, {
  710. setup,
  711. mount,
  712. destroy
  713. });
  714. }
  715. const SLIDE = "slide";
  716. const LOOP = "loop";
  717. const FADE = "fade";
  718. function Slide$1(Splide2, index, slideIndex, slide) {
  719. const { on, emit, bind, destroy: destroyEvents } = EventInterface(Splide2);
  720. const { Components, root, options } = Splide2;
  721. const { isNavigation, updateOnMove, i18n } = options;
  722. const { resolve } = Components.Direction;
  723. const styles = getAttribute(slide, "style");
  724. const isClone = slideIndex > -1;
  725. const container = child(slide, `.${CLASS_CONTAINER}`);
  726. const focusableNodes = options.focusableNodes && queryAll(slide, options.focusableNodes);
  727. let destroyed;
  728. function mount() {
  729. if (!isClone) {
  730. slide.id = `${root.id}-slide${pad(index + 1)}`;
  731. setAttribute(slide, ROLE, "group");
  732. setAttribute(slide, ARIA_ROLEDESCRIPTION, i18n.slide);
  733. setAttribute(slide, ARIA_LABEL, format(i18n.slideLabel, [index + 1, Splide2.length]));
  734. }
  735. listen();
  736. }
  737. function listen() {
  738. bind(slide, "click keydown", (e) => {
  739. emit(e.type === "click" ? EVENT_CLICK : EVENT_SLIDE_KEYDOWN, self, e);
  740. });
  741. on([EVENT_REFRESH, EVENT_REPOSITIONED, EVENT_SHIFTED, EVENT_MOVED, EVENT_SCROLLED], update);
  742. on(EVENT_NAVIGATION_MOUNTED, initNavigation);
  743. if (updateOnMove) {
  744. on(EVENT_MOVE, onMove);
  745. }
  746. }
  747. function destroy() {
  748. destroyed = true;
  749. destroyEvents();
  750. removeClass(slide, STATUS_CLASSES);
  751. removeAttribute(slide, ALL_ATTRIBUTES);
  752. setAttribute(slide, "style", styles);
  753. }
  754. function initNavigation() {
  755. const idx = isClone ? slideIndex : index;
  756. const label = format(i18n.slideX, idx + 1);
  757. const controls = Splide2.splides.map((target) => target.splide.root.id).join(" ");
  758. setAttribute(slide, ARIA_LABEL, label);
  759. setAttribute(slide, ARIA_CONTROLS, controls);
  760. setAttribute(slide, ROLE, "menuitem");
  761. updateActivity(isActive());
  762. }
  763. function onMove() {
  764. if (!destroyed) {
  765. update();
  766. }
  767. }
  768. function update() {
  769. if (!destroyed) {
  770. const { index: currIndex } = Splide2;
  771. updateActivity(isActive());
  772. updateVisibility(isVisible());
  773. toggleClass(slide, CLASS_PREV, index === currIndex - 1);
  774. toggleClass(slide, CLASS_NEXT, index === currIndex + 1);
  775. }
  776. }
  777. function updateActivity(active) {
  778. if (active !== hasClass(slide, CLASS_ACTIVE)) {
  779. toggleClass(slide, CLASS_ACTIVE, active);
  780. if (isNavigation) {
  781. setAttribute(slide, ARIA_CURRENT, active || null);
  782. }
  783. emit(active ? EVENT_ACTIVE : EVENT_INACTIVE, self);
  784. }
  785. }
  786. function updateVisibility(visible) {
  787. const hidden = !visible && (!isActive() || isClone);
  788. setAttribute(slide, ARIA_HIDDEN, hidden || null);
  789. setAttribute(slide, TAB_INDEX, !hidden && options.slideFocus ? 0 : null);
  790. setAttribute(focusableNodes || [], TAB_INDEX, hidden ? -1 : null);
  791. if (visible !== hasClass(slide, CLASS_VISIBLE)) {
  792. toggleClass(slide, CLASS_VISIBLE, visible);
  793. emit(visible ? EVENT_VISIBLE : EVENT_HIDDEN, self);
  794. }
  795. }
  796. function style$1(prop, value, useContainer) {
  797. style(useContainer && container || slide, prop, value);
  798. }
  799. function isActive() {
  800. const { index: curr } = Splide2;
  801. return curr === index || options.cloneStatus && curr === slideIndex;
  802. }
  803. function isVisible() {
  804. if (Splide2.is(FADE)) {
  805. return isActive();
  806. }
  807. const trackRect = rect(Components.Elements.track);
  808. const slideRect = rect(slide);
  809. const left = resolve("left");
  810. const right = resolve("right");
  811. return floor(trackRect[left]) <= ceil(slideRect[left]) && floor(slideRect[right]) <= ceil(trackRect[right]);
  812. }
  813. function isWithin(from, distance) {
  814. let diff = abs(from - index);
  815. if (!isClone && (options.rewind || Splide2.is(LOOP))) {
  816. diff = min(diff, Splide2.length - diff);
  817. }
  818. return diff <= distance;
  819. }
  820. const self = {
  821. index,
  822. slideIndex,
  823. slide,
  824. container,
  825. isClone,
  826. mount,
  827. destroy,
  828. update,
  829. style: style$1,
  830. isWithin
  831. };
  832. return self;
  833. }
  834. function Slides(Splide2, Components2, options) {
  835. const { on, emit, bind } = EventInterface(Splide2);
  836. const { slides, list } = Components2.Elements;
  837. const Slides2 = [];
  838. function mount() {
  839. init();
  840. on(EVENT_REFRESH, destroy);
  841. on(EVENT_REFRESH, init);
  842. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  843. Slides2.sort((Slide1, Slide2) => Slide1.index - Slide2.index);
  844. });
  845. }
  846. function init() {
  847. slides.forEach((slide, index) => {
  848. register(slide, index, -1);
  849. });
  850. }
  851. function destroy() {
  852. forEach$1((Slide2) => {
  853. Slide2.destroy();
  854. });
  855. empty(Slides2);
  856. }
  857. function update() {
  858. forEach$1((Slide2) => {
  859. Slide2.update();
  860. });
  861. }
  862. function register(slide, index, slideIndex) {
  863. const object = Slide$1(Splide2, index, slideIndex, slide);
  864. object.mount();
  865. Slides2.push(object);
  866. }
  867. function get(excludeClones) {
  868. return excludeClones ? filter((Slide2) => !Slide2.isClone) : Slides2;
  869. }
  870. function getIn(page) {
  871. const { Controller } = Components2;
  872. const index = Controller.toIndex(page);
  873. const max = Controller.hasFocus() ? 1 : options.perPage;
  874. return filter((Slide2) => between(Slide2.index, index, index + max - 1));
  875. }
  876. function getAt(index) {
  877. return filter(index)[0];
  878. }
  879. function add(items, index) {
  880. forEach(items, (slide) => {
  881. if (isString(slide)) {
  882. slide = parseHtml(slide);
  883. }
  884. if (isHTMLElement(slide)) {
  885. const ref = slides[index];
  886. ref ? before(slide, ref) : append(list, slide);
  887. addClass(slide, options.classes.slide);
  888. observeImages(slide, apply(emit, EVENT_RESIZE));
  889. }
  890. });
  891. emit(EVENT_REFRESH);
  892. }
  893. function remove$1(matcher) {
  894. remove(filter(matcher).map((Slide2) => Slide2.slide));
  895. emit(EVENT_REFRESH);
  896. }
  897. function forEach$1(iteratee, excludeClones) {
  898. get(excludeClones).forEach(iteratee);
  899. }
  900. function filter(matcher) {
  901. return Slides2.filter(isFunction(matcher) ? matcher : (Slide2) => isString(matcher) ? matches(Slide2.slide, matcher) : includes(toArray(matcher), Slide2.index));
  902. }
  903. function style(prop, value, useContainer) {
  904. forEach$1((Slide2) => {
  905. Slide2.style(prop, value, useContainer);
  906. });
  907. }
  908. function observeImages(elm, callback) {
  909. const images = queryAll(elm, "img");
  910. let { length } = images;
  911. if (length) {
  912. images.forEach((img) => {
  913. bind(img, "load error", () => {
  914. if (!--length) {
  915. callback();
  916. }
  917. });
  918. });
  919. } else {
  920. callback();
  921. }
  922. }
  923. function getLength(excludeClones) {
  924. return excludeClones ? slides.length : Slides2.length;
  925. }
  926. function isEnough() {
  927. return Slides2.length > options.perPage;
  928. }
  929. return {
  930. mount,
  931. destroy,
  932. update,
  933. register,
  934. get,
  935. getIn,
  936. getAt,
  937. add,
  938. remove: remove$1,
  939. forEach: forEach$1,
  940. filter,
  941. style,
  942. getLength,
  943. isEnough
  944. };
  945. }
  946. function Layout(Splide2, Components2, options) {
  947. const { on, bind, emit } = EventInterface(Splide2);
  948. const { Slides } = Components2;
  949. const { resolve } = Components2.Direction;
  950. const { root, track, list } = Components2.Elements;
  951. const { getAt, style: styleSlides } = Slides;
  952. let vertical;
  953. let rootRect;
  954. function mount() {
  955. init();
  956. bind(window, "resize load", Throttle(apply(emit, EVENT_RESIZE)));
  957. on([EVENT_UPDATED, EVENT_REFRESH], init);
  958. on(EVENT_RESIZE, resize);
  959. }
  960. function init() {
  961. rootRect = null;
  962. vertical = options.direction === TTB;
  963. style(root, "maxWidth", unit(options.width));
  964. style(track, resolve("paddingLeft"), cssPadding(false));
  965. style(track, resolve("paddingRight"), cssPadding(true));
  966. resize();
  967. }
  968. function resize() {
  969. const newRect = rect(root);
  970. if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  971. style(track, "height", cssTrackHeight());
  972. styleSlides(resolve("marginRight"), unit(options.gap));
  973. styleSlides("width", cssSlideWidth() || null);
  974. styleSlides("height", cssSlideHeight() || null, true);
  975. rootRect = newRect;
  976. emit(EVENT_RESIZED);
  977. }
  978. }
  979. function cssPadding(right) {
  980. const { padding } = options;
  981. const prop = resolve(right ? "right" : "left");
  982. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  983. }
  984. function cssTrackHeight() {
  985. let height = "";
  986. if (vertical) {
  987. height = cssHeight();
  988. assert(height, "height or heightRatio is missing.");
  989. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  990. }
  991. return height;
  992. }
  993. function cssHeight() {
  994. return unit(options.height || rect(list).width * options.heightRatio);
  995. }
  996. function cssSlideWidth() {
  997. return options.autoWidth ? "" : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  998. }
  999. function cssSlideHeight() {
  1000. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? "" : cssSlideSize() : cssHeight());
  1001. }
  1002. function cssSlideSize() {
  1003. const gap = unit(options.gap);
  1004. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  1005. }
  1006. function listSize() {
  1007. return rect(list)[resolve("width")];
  1008. }
  1009. function slideSize(index, withoutGap) {
  1010. const Slide = getAt(index || 0);
  1011. return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
  1012. }
  1013. function totalSize(index, withoutGap) {
  1014. const Slide = getAt(index);
  1015. if (Slide) {
  1016. const right = rect(Slide.slide)[resolve("right")];
  1017. const left = rect(list)[resolve("left")];
  1018. return abs(right - left) + (withoutGap ? 0 : getGap());
  1019. }
  1020. return 0;
  1021. }
  1022. function sliderSize() {
  1023. return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
  1024. }
  1025. function getGap() {
  1026. const Slide = getAt(0);
  1027. return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
  1028. }
  1029. function getPadding(right) {
  1030. return parseFloat(style(track, resolve(`padding${right ? "Right" : "Left"}`))) || 0;
  1031. }
  1032. return {
  1033. mount,
  1034. listSize,
  1035. slideSize,
  1036. sliderSize,
  1037. totalSize,
  1038. getPadding
  1039. };
  1040. }
  1041. function Clones(Splide2, Components2, options) {
  1042. const { on, emit } = EventInterface(Splide2);
  1043. const { Elements, Slides } = Components2;
  1044. const { resolve } = Components2.Direction;
  1045. const clones = [];
  1046. let cloneCount;
  1047. function mount() {
  1048. init();
  1049. on(EVENT_REFRESH, destroy);
  1050. on(EVENT_REFRESH, init);
  1051. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1052. }
  1053. function init() {
  1054. if (cloneCount = computeCloneCount()) {
  1055. generate(cloneCount);
  1056. emit(EVENT_RESIZE);
  1057. }
  1058. }
  1059. function destroy() {
  1060. remove(clones);
  1061. empty(clones);
  1062. }
  1063. function observe() {
  1064. if (cloneCount < computeCloneCount()) {
  1065. emit(EVENT_REFRESH);
  1066. }
  1067. }
  1068. function generate(count) {
  1069. const slides = Slides.get().slice();
  1070. const { length } = slides;
  1071. if (length) {
  1072. while (slides.length < count) {
  1073. push(slides, slides);
  1074. }
  1075. push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  1076. const isHead = index < count;
  1077. const clone = cloneDeep(Slide.slide, index);
  1078. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1079. push(clones, clone);
  1080. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1081. });
  1082. }
  1083. }
  1084. function cloneDeep(elm, index) {
  1085. const clone = elm.cloneNode(true);
  1086. addClass(clone, options.classes.clone);
  1087. clone.id = `${Splide2.root.id}-clone${pad(index + 1)}`;
  1088. return clone;
  1089. }
  1090. function computeCloneCount() {
  1091. let { clones: clones2 } = options;
  1092. if (!Splide2.is(LOOP)) {
  1093. clones2 = 0;
  1094. } else if (!clones2) {
  1095. const fixedSize = measure(Elements.list, options[resolve("fixedWidth")]);
  1096. const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1097. const baseCount = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage;
  1098. clones2 = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  1099. }
  1100. return clones2;
  1101. }
  1102. return {
  1103. mount,
  1104. destroy
  1105. };
  1106. }
  1107. function Move(Splide2, Components2, options) {
  1108. const { on, emit } = EventInterface(Splide2);
  1109. const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
  1110. const { resolve, orient } = Components2.Direction;
  1111. const { list, track } = Components2.Elements;
  1112. let Transition;
  1113. function mount() {
  1114. Transition = Components2.Transition;
  1115. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1116. }
  1117. function reposition() {
  1118. if (!isBusy()) {
  1119. Components2.Scroll.cancel();
  1120. jump(Splide2.index);
  1121. emit(EVENT_REPOSITIONED);
  1122. }
  1123. }
  1124. function move(dest, index, prev, callback) {
  1125. if (!isBusy()) {
  1126. const { set } = Splide2.state;
  1127. const position = getPosition();
  1128. if (dest !== index) {
  1129. Transition.cancel();
  1130. translate(shift(position, dest > index), true);
  1131. }
  1132. set(MOVING);
  1133. emit(EVENT_MOVE, index, prev, dest);
  1134. Transition.start(index, () => {
  1135. set(IDLE);
  1136. emit(EVENT_MOVED, index, prev, dest);
  1137. if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
  1138. Components2.Controller.go(dest > prev ? ">" : "<", false, callback);
  1139. } else {
  1140. callback && callback();
  1141. }
  1142. });
  1143. }
  1144. }
  1145. function jump(index) {
  1146. translate(toPosition(index, true));
  1147. }
  1148. function translate(position, preventLoop) {
  1149. if (!Splide2.is(FADE)) {
  1150. const destination = preventLoop ? position : loop(position);
  1151. list.style.transform = `translate${resolve("X")}(${destination}px)`;
  1152. position !== destination && emit(EVENT_SHIFTED);
  1153. }
  1154. }
  1155. function loop(position) {
  1156. if (Splide2.is(LOOP)) {
  1157. const diff = orient(position - getPosition());
  1158. const exceededMin = exceededLimit(false, position) && diff < 0;
  1159. const exceededMax = exceededLimit(true, position) && diff > 0;
  1160. if (exceededMin || exceededMax) {
  1161. position = shift(position, exceededMax);
  1162. }
  1163. }
  1164. return position;
  1165. }
  1166. function shift(position, backwards) {
  1167. const excess = position - getLimit(backwards);
  1168. const size = sliderSize();
  1169. position -= orient(size * (ceil(abs(excess) / size) || 1)) * (backwards ? 1 : -1);
  1170. return position;
  1171. }
  1172. function cancel() {
  1173. translate(getPosition());
  1174. Transition.cancel();
  1175. }
  1176. function toIndex(position) {
  1177. const Slides = Components2.Slides.get();
  1178. let index = 0;
  1179. let minDistance = Infinity;
  1180. for (let i = 0; i < Slides.length; i++) {
  1181. const slideIndex = Slides[i].index;
  1182. const distance = abs(toPosition(slideIndex, true) - position);
  1183. if (distance <= minDistance) {
  1184. minDistance = distance;
  1185. index = slideIndex;
  1186. } else {
  1187. break;
  1188. }
  1189. }
  1190. return index;
  1191. }
  1192. function toPosition(index, trimming) {
  1193. const position = orient(totalSize(index - 1) - offset(index));
  1194. return trimming ? trim(position) : position;
  1195. }
  1196. function getPosition() {
  1197. const left = resolve("left");
  1198. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1199. }
  1200. function trim(position) {
  1201. if (options.trimSpace && Splide2.is(SLIDE)) {
  1202. position = clamp(position, 0, orient(sliderSize() - listSize()));
  1203. }
  1204. return position;
  1205. }
  1206. function offset(index) {
  1207. const { focus } = options;
  1208. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1209. }
  1210. function getLimit(max) {
  1211. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1212. }
  1213. function isBusy() {
  1214. return Splide2.state.is(MOVING) && options.waitForTransition;
  1215. }
  1216. function exceededLimit(max, position) {
  1217. position = isUndefined(position) ? getPosition() : position;
  1218. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1219. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1220. return exceededMin || exceededMax;
  1221. }
  1222. return {
  1223. mount,
  1224. move,
  1225. jump,
  1226. translate,
  1227. shift,
  1228. cancel,
  1229. toIndex,
  1230. toPosition,
  1231. getPosition,
  1232. getLimit,
  1233. isBusy,
  1234. exceededLimit,
  1235. reposition
  1236. };
  1237. }
  1238. function Controller(Splide2, Components2, options) {
  1239. const { on } = EventInterface(Splide2);
  1240. const { Move } = Components2;
  1241. const { getPosition, getLimit } = Move;
  1242. const { isEnough, getLength } = Components2.Slides;
  1243. const isLoop = Splide2.is(LOOP);
  1244. const isSlide = Splide2.is(SLIDE);
  1245. const getNext = apply(getAdjacent, false);
  1246. const getPrev = apply(getAdjacent, true);
  1247. let currIndex = options.start || 0;
  1248. let prevIndex = currIndex;
  1249. let slideCount;
  1250. let perMove;
  1251. let perPage;
  1252. function mount() {
  1253. init();
  1254. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1255. }
  1256. function init() {
  1257. slideCount = getLength(true);
  1258. perMove = options.perMove;
  1259. perPage = options.perPage;
  1260. const index = clamp(currIndex, 0, slideCount - 1);
  1261. if (index !== currIndex) {
  1262. currIndex = index;
  1263. Move.reposition();
  1264. }
  1265. }
  1266. function go(control, allowSameIndex, callback) {
  1267. const dest = parse(control);
  1268. if (options.useScroll) {
  1269. scroll(dest, true, true, options.speed, callback);
  1270. } else {
  1271. const index = loop(dest);
  1272. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  1273. setIndex(index);
  1274. Move.move(dest, index, prevIndex, callback);
  1275. }
  1276. }
  1277. }
  1278. function scroll(destination, useIndex, snap, duration, callback) {
  1279. const dest = useIndex ? destination : toDest(destination);
  1280. Components2.Scroll.scroll(useIndex || snap ? Move.toPosition(dest, true) : destination, duration, () => {
  1281. setIndex(Move.toIndex(Move.getPosition()));
  1282. callback && callback();
  1283. });
  1284. }
  1285. function parse(control) {
  1286. let index = currIndex;
  1287. if (isString(control)) {
  1288. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1289. if (indicator === "+" || indicator === "-") {
  1290. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex, true);
  1291. } else if (indicator === ">") {
  1292. index = number ? toIndex(+number) : getNext(true);
  1293. } else if (indicator === "<") {
  1294. index = getPrev(true);
  1295. }
  1296. } else {
  1297. index = isLoop ? control : clamp(control, 0, getEnd());
  1298. }
  1299. return index;
  1300. }
  1301. function getAdjacent(prev, destination) {
  1302. const number = perMove || (hasFocus() ? 1 : perPage);
  1303. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
  1304. if (dest === -1 && isSlide) {
  1305. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1306. return prev ? 0 : getEnd();
  1307. }
  1308. }
  1309. return destination ? dest : loop(dest);
  1310. }
  1311. function computeDestIndex(dest, from, incremental) {
  1312. if (isEnough()) {
  1313. const end = getEnd();
  1314. if (dest < 0 || dest > end) {
  1315. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  1316. dest = toIndex(toPage(dest));
  1317. } else {
  1318. if (isLoop) {
  1319. dest = perMove || hasFocus() ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  1320. } else if (options.rewind) {
  1321. dest = dest < 0 ? end : 0;
  1322. } else {
  1323. dest = -1;
  1324. }
  1325. }
  1326. } else {
  1327. if (!incremental && dest !== from) {
  1328. dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
  1329. }
  1330. }
  1331. } else {
  1332. dest = -1;
  1333. }
  1334. return dest;
  1335. }
  1336. function getEnd() {
  1337. let end = slideCount - perPage;
  1338. if (hasFocus() || isLoop && perMove) {
  1339. end = slideCount - 1;
  1340. }
  1341. return max(end, 0);
  1342. }
  1343. function loop(index) {
  1344. if (isLoop) {
  1345. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  1346. }
  1347. return index;
  1348. }
  1349. function toIndex(page) {
  1350. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  1351. }
  1352. function toPage(index) {
  1353. if (!hasFocus()) {
  1354. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  1355. index = floor(index / perPage);
  1356. }
  1357. return index;
  1358. }
  1359. function toDest(destination) {
  1360. const closest = Move.toIndex(destination);
  1361. return isSlide ? clamp(closest, 0, getEnd()) : closest;
  1362. }
  1363. function setIndex(index) {
  1364. if (index !== currIndex) {
  1365. prevIndex = currIndex;
  1366. currIndex = index;
  1367. }
  1368. }
  1369. function getIndex(prev) {
  1370. return prev ? prevIndex : currIndex;
  1371. }
  1372. function hasFocus() {
  1373. return !isUndefined(options.focus) || options.isNavigation;
  1374. }
  1375. return {
  1376. mount,
  1377. go,
  1378. scroll,
  1379. getNext,
  1380. getPrev,
  1381. getAdjacent,
  1382. getEnd,
  1383. setIndex,
  1384. getIndex,
  1385. toIndex,
  1386. toPage,
  1387. toDest,
  1388. hasFocus
  1389. };
  1390. }
  1391. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1392. 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";
  1393. const SIZE = 40;
  1394. function Arrows(Splide2, Components2, options) {
  1395. const { on, bind, emit } = EventInterface(Splide2);
  1396. const { classes, i18n } = options;
  1397. const { Elements, Controller } = Components2;
  1398. let wrapper = Elements.arrows;
  1399. let prev = Elements.prev;
  1400. let next = Elements.next;
  1401. let created;
  1402. const arrows = {};
  1403. function mount() {
  1404. init();
  1405. on(EVENT_UPDATED, init);
  1406. }
  1407. function init() {
  1408. if (options.arrows) {
  1409. if (!prev || !next) {
  1410. createArrows();
  1411. }
  1412. }
  1413. if (prev && next) {
  1414. if (!arrows.prev) {
  1415. setAttribute([prev, next], ARIA_CONTROLS, Elements.list.id);
  1416. arrows.prev = prev;
  1417. arrows.next = next;
  1418. listen();
  1419. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1420. }
  1421. display(wrapper, options.arrows === false ? "none" : "");
  1422. }
  1423. }
  1424. function destroy() {
  1425. if (created) {
  1426. remove(wrapper);
  1427. } else {
  1428. removeAttribute([prev, next], ALL_ATTRIBUTES);
  1429. }
  1430. }
  1431. function listen() {
  1432. const { go } = Controller;
  1433. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  1434. bind(next, "click", apply(go, ">", true, void 0));
  1435. bind(prev, "click", apply(go, "<", true, void 0));
  1436. }
  1437. function createArrows() {
  1438. wrapper = create("div", classes.arrows);
  1439. prev = createArrow(true);
  1440. next = createArrow(false);
  1441. created = true;
  1442. append(wrapper, [prev, next]);
  1443. before(wrapper, child(options.arrows === "slider" && Elements.slider || Splide2.root));
  1444. }
  1445. function createArrow(prev2) {
  1446. 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}" />`;
  1447. return parseHtml(arrow);
  1448. }
  1449. function update() {
  1450. const index = Splide2.index;
  1451. const prevIndex = Controller.getPrev();
  1452. const nextIndex = Controller.getNext();
  1453. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1454. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1455. prev.disabled = prevIndex < 0;
  1456. next.disabled = nextIndex < 0;
  1457. setAttribute(prev, ARIA_LABEL, prevLabel);
  1458. setAttribute(next, ARIA_LABEL, nextLabel);
  1459. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1460. }
  1461. return {
  1462. arrows,
  1463. mount,
  1464. destroy
  1465. };
  1466. }
  1467. const INTERVAL_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-interval`;
  1468. function Autoplay(Splide2, Components2, options) {
  1469. const { on, bind, emit } = EventInterface(Splide2);
  1470. const interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), update);
  1471. const { isPaused } = interval;
  1472. const { Elements } = Components2;
  1473. const { autoplay } = options;
  1474. let hovered;
  1475. let focused;
  1476. let paused = autoplay === "pause";
  1477. function mount() {
  1478. if (autoplay) {
  1479. initButton(true);
  1480. initButton(false);
  1481. listen();
  1482. !paused && play();
  1483. }
  1484. }
  1485. function initButton(forPause) {
  1486. const prop = forPause ? "pause" : "play";
  1487. const button = Elements[prop];
  1488. if (button) {
  1489. setAttribute(button, ARIA_CONTROLS, Elements.track.id);
  1490. setAttribute(button, ARIA_LABEL, options.i18n[prop]);
  1491. bind(button, "click", forPause ? pause : play);
  1492. }
  1493. }
  1494. function listen() {
  1495. const { root } = Elements;
  1496. if (options.pauseOnHover) {
  1497. bind(root, "mouseenter mouseleave", (e) => {
  1498. hovered = e.type === "mouseenter";
  1499. autoToggle();
  1500. });
  1501. }
  1502. if (options.pauseOnFocus) {
  1503. bind(root, "focusin focusout", (e) => {
  1504. focused = e.type === "focusin";
  1505. autoToggle();
  1506. });
  1507. }
  1508. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1509. on(EVENT_MOVE, updateInterval);
  1510. }
  1511. function play() {
  1512. if (isPaused() && Components2.Slides.isEnough()) {
  1513. interval.start(!options.resetProgress);
  1514. focused = hovered = paused = false;
  1515. emit(EVENT_AUTOPLAY_PLAY);
  1516. }
  1517. }
  1518. function pause(manual = true) {
  1519. if (!isPaused()) {
  1520. interval.pause();
  1521. emit(EVENT_AUTOPLAY_PAUSE);
  1522. }
  1523. paused = manual;
  1524. }
  1525. function autoToggle() {
  1526. if (!paused) {
  1527. if (!hovered && !focused) {
  1528. play();
  1529. } else {
  1530. pause(false);
  1531. }
  1532. }
  1533. }
  1534. function update(rate) {
  1535. const { bar } = Elements;
  1536. bar && style(bar, "width", `${rate * 100}%`);
  1537. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1538. }
  1539. function updateInterval() {
  1540. const Slide = Components2.Slides.getAt(Splide2.index);
  1541. interval.set(Slide && +getAttribute(Slide.slide, INTERVAL_DATA_ATTRIBUTE) || options.interval);
  1542. }
  1543. return {
  1544. mount,
  1545. destroy: interval.cancel,
  1546. play,
  1547. pause,
  1548. isPaused
  1549. };
  1550. }
  1551. function Cover(Splide2, Components2, options) {
  1552. const { on } = EventInterface(Splide2);
  1553. function mount() {
  1554. if (options.cover) {
  1555. on(EVENT_LAZYLOAD_LOADED, apply(toggle, true));
  1556. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply(cover, true));
  1557. }
  1558. }
  1559. function cover(cover2) {
  1560. Components2.Slides.forEach((Slide) => {
  1561. const img = child(Slide.container || Slide.slide, "img");
  1562. if (img && img.src) {
  1563. toggle(cover2, img, Slide);
  1564. }
  1565. });
  1566. }
  1567. function toggle(cover2, img, Slide) {
  1568. Slide.style("background", cover2 ? `center/cover no-repeat url("${img.src}")` : "", true);
  1569. display(img, cover2 ? "none" : "");
  1570. }
  1571. return {
  1572. mount,
  1573. destroy: apply(cover, false)
  1574. };
  1575. }
  1576. const BOUNCE_DIFF_THRESHOLD = 10;
  1577. const BOUNCE_DURATION = 600;
  1578. const FRICTION_FACTOR = 0.6;
  1579. const BASE_VELOCITY = 1.5;
  1580. const MIN_DURATION = 800;
  1581. function Scroll(Splide2, Components2, options) {
  1582. const { on, emit } = EventInterface(Splide2);
  1583. const { Move } = Components2;
  1584. const { getPosition, getLimit, exceededLimit } = Move;
  1585. let interval;
  1586. let scrollCallback;
  1587. function mount() {
  1588. on(EVENT_MOVE, clear);
  1589. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1590. }
  1591. function scroll(destination, duration, callback, suppressConstraint) {
  1592. const start = getPosition();
  1593. let friction = 1;
  1594. duration = duration || computeDuration(abs(destination - start));
  1595. scrollCallback = callback;
  1596. clear();
  1597. interval = RequestInterval(duration, onScrolled, (rate) => {
  1598. const position = getPosition();
  1599. const target = start + (destination - start) * easing(rate);
  1600. const diff = (target - getPosition()) * friction;
  1601. Move.translate(position + diff);
  1602. if (Splide2.is(SLIDE) && !suppressConstraint && exceededLimit()) {
  1603. friction *= FRICTION_FACTOR;
  1604. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1605. bounce(exceededLimit(false));
  1606. }
  1607. }
  1608. }, 1);
  1609. emit(EVENT_SCROLL);
  1610. interval.start();
  1611. }
  1612. function bounce(backwards) {
  1613. scroll(getLimit(!backwards), BOUNCE_DURATION, null, true);
  1614. }
  1615. function onScrolled() {
  1616. const position = getPosition();
  1617. const index = Move.toIndex(position);
  1618. if (!between(index, 0, Splide2.length - 1)) {
  1619. Move.translate(Move.shift(position, index > 0), true);
  1620. }
  1621. scrollCallback && scrollCallback();
  1622. emit(EVENT_SCROLLED);
  1623. }
  1624. function computeDuration(distance) {
  1625. return max(distance / BASE_VELOCITY, MIN_DURATION);
  1626. }
  1627. function clear() {
  1628. if (interval) {
  1629. interval.cancel();
  1630. }
  1631. }
  1632. function cancel() {
  1633. if (interval && !interval.isPaused()) {
  1634. clear();
  1635. onScrolled();
  1636. }
  1637. }
  1638. function easing(t) {
  1639. const { easingFunc } = options;
  1640. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1641. }
  1642. return {
  1643. mount,
  1644. destroy: clear,
  1645. scroll,
  1646. cancel
  1647. };
  1648. }
  1649. const SCROLL_LISTENER_OPTIONS = { passive: false, capture: true };
  1650. const FRICTION = 5;
  1651. const LOG_INTERVAL = 200;
  1652. const POINTER_DOWN_EVENTS = "touchstart mousedown";
  1653. const POINTER_MOVE_EVENTS = "touchmove mousemove";
  1654. const POINTER_UP_EVENTS = "touchend touchcancel mouseup";
  1655. function Drag(Splide2, Components2, options) {
  1656. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1657. const { state } = Splide2;
  1658. const { Move, Scroll, Controller } = Components2;
  1659. const { track } = Components2.Elements;
  1660. const { resolve, orient } = Components2.Direction;
  1661. const { getPosition, exceededLimit } = Move;
  1662. let basePosition;
  1663. let baseEvent;
  1664. let prevBaseEvent;
  1665. let isFree;
  1666. let dragging;
  1667. let exceeded = false;
  1668. let clickPrevented;
  1669. let disabled;
  1670. let target;
  1671. function mount() {
  1672. bind(track, POINTER_MOVE_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1673. bind(track, POINTER_UP_EVENTS, noop, SCROLL_LISTENER_OPTIONS);
  1674. bind(track, POINTER_DOWN_EVENTS, onPointerDown, SCROLL_LISTENER_OPTIONS);
  1675. bind(track, "click", onClick, { capture: true });
  1676. bind(track, "dragstart", prevent);
  1677. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1678. }
  1679. function init() {
  1680. const { drag } = options;
  1681. disable(!drag);
  1682. isFree = drag === "free";
  1683. }
  1684. function onPointerDown(e) {
  1685. clickPrevented = false;
  1686. if (!disabled) {
  1687. const { noDrag } = options;
  1688. const isTouch = isTouchEvent(e);
  1689. const isDraggable = !noDrag || !matches(e.target, noDrag);
  1690. if (isDraggable && (isTouch || !e.button)) {
  1691. if (!Move.isBusy()) {
  1692. target = isTouch ? track : window;
  1693. dragging = state.is(MOVING);
  1694. prevBaseEvent = null;
  1695. bind(target, POINTER_MOVE_EVENTS, onPointerMove, SCROLL_LISTENER_OPTIONS);
  1696. bind(target, POINTER_UP_EVENTS, onPointerUp, SCROLL_LISTENER_OPTIONS);
  1697. Move.cancel();
  1698. Scroll.cancel();
  1699. save(e);
  1700. } else {
  1701. prevent(e, true);
  1702. }
  1703. }
  1704. }
  1705. }
  1706. function onPointerMove(e) {
  1707. if (!state.is(DRAGGING)) {
  1708. state.set(DRAGGING);
  1709. emit(EVENT_DRAG);
  1710. }
  1711. if (e.cancelable) {
  1712. if (dragging) {
  1713. Move.translate(basePosition + constrain(diffCoord(e)));
  1714. const expired = diffTime(e) > LOG_INTERVAL;
  1715. const hasExceeded = exceeded !== (exceeded = exceededLimit());
  1716. if (expired || hasExceeded) {
  1717. save(e);
  1718. }
  1719. clickPrevented = true;
  1720. emit(EVENT_DRAGGING);
  1721. prevent(e);
  1722. } else if (isSliderDirection(e)) {
  1723. dragging = shouldStart(e);
  1724. prevent(e);
  1725. }
  1726. }
  1727. }
  1728. function onPointerUp(e) {
  1729. if (state.is(DRAGGING)) {
  1730. state.set(IDLE);
  1731. emit(EVENT_DRAGGED);
  1732. }
  1733. if (dragging) {
  1734. move(e);
  1735. prevent(e);
  1736. }
  1737. unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1738. unbind(target, POINTER_UP_EVENTS, onPointerUp);
  1739. dragging = false;
  1740. }
  1741. function onClick(e) {
  1742. if (!disabled && clickPrevented) {
  1743. prevent(e, true);
  1744. }
  1745. }
  1746. function save(e) {
  1747. prevBaseEvent = baseEvent;
  1748. baseEvent = e;
  1749. basePosition = getPosition();
  1750. }
  1751. function move(e) {
  1752. const velocity = computeVelocity(e);
  1753. const destination = computeDestination(velocity);
  1754. const rewind = options.rewind && options.rewindByDrag;
  1755. if (isFree) {
  1756. Controller.scroll(destination);
  1757. } else if (Splide2.is(FADE)) {
  1758. Controller.go(orient(sign(velocity)) < 0 ? rewind ? "<" : "-" : rewind ? ">" : "+");
  1759. } else if (Splide2.is(SLIDE) && exceeded && rewind) {
  1760. Controller.go(exceededLimit(true) ? ">" : "<");
  1761. } else {
  1762. Controller.go(Controller.toDest(destination), true);
  1763. }
  1764. }
  1765. function shouldStart(e) {
  1766. const { dragMinThreshold: thresholds } = options;
  1767. const isObj = isObject(thresholds);
  1768. const mouse = isObj && thresholds.mouse || 0;
  1769. const touch = (isObj ? thresholds.touch : +thresholds) || 10;
  1770. return abs(diffCoord(e)) > (isTouchEvent(e) ? touch : mouse);
  1771. }
  1772. function isSliderDirection(e) {
  1773. return abs(diffCoord(e)) > abs(diffCoord(e, true));
  1774. }
  1775. function computeVelocity(e) {
  1776. if (Splide2.is(LOOP) || !exceeded) {
  1777. const time = diffTime(e);
  1778. if (time && time < LOG_INTERVAL) {
  1779. return diffCoord(e) / time;
  1780. }
  1781. }
  1782. return 0;
  1783. }
  1784. function computeDestination(velocity) {
  1785. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1786. }
  1787. function diffCoord(e, orthogonal) {
  1788. return coordOf(e, orthogonal) - coordOf(getBaseEvent(e), orthogonal);
  1789. }
  1790. function diffTime(e) {
  1791. return timeOf(e) - timeOf(getBaseEvent(e));
  1792. }
  1793. function getBaseEvent(e) {
  1794. return baseEvent === e && prevBaseEvent || baseEvent;
  1795. }
  1796. function coordOf(e, orthogonal) {
  1797. return (isTouchEvent(e) ? e.changedTouches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
  1798. }
  1799. function constrain(diff) {
  1800. return diff / (exceeded && Splide2.is(SLIDE) ? FRICTION : 1);
  1801. }
  1802. function isTouchEvent(e) {
  1803. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1804. }
  1805. function isDragging() {
  1806. return dragging;
  1807. }
  1808. function disable(value) {
  1809. disabled = value;
  1810. }
  1811. return {
  1812. mount,
  1813. disable,
  1814. isDragging
  1815. };
  1816. }
  1817. const IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1818. const KEYBOARD_EVENT = "keydown";
  1819. function Keyboard(Splide2, Components2, options) {
  1820. const { on, bind, unbind } = EventInterface(Splide2);
  1821. const { root } = Splide2;
  1822. const { resolve } = Components2.Direction;
  1823. let target;
  1824. let disabled;
  1825. function mount() {
  1826. init();
  1827. on(EVENT_UPDATED, onUpdated);
  1828. on(EVENT_MOVE, onMove);
  1829. }
  1830. function init() {
  1831. const { keyboard } = options;
  1832. if (keyboard) {
  1833. if (keyboard === "focused") {
  1834. target = root;
  1835. setAttribute(root, TAB_INDEX, 0);
  1836. } else {
  1837. target = window;
  1838. }
  1839. bind(target, KEYBOARD_EVENT, onKeydown);
  1840. }
  1841. }
  1842. function destroy() {
  1843. unbind(target, KEYBOARD_EVENT);
  1844. }
  1845. function disable(value) {
  1846. disabled = value;
  1847. }
  1848. function onMove() {
  1849. const _disabled = disabled;
  1850. disabled = true;
  1851. nextTick(() => {
  1852. disabled = _disabled;
  1853. });
  1854. }
  1855. function onUpdated() {
  1856. destroy();
  1857. init();
  1858. }
  1859. function onKeydown(e) {
  1860. if (!disabled) {
  1861. const { key } = e;
  1862. const normalizedKey = includes(IE_ARROW_KEYS, key) ? `Arrow${key}` : key;
  1863. if (normalizedKey === resolve("ArrowLeft")) {
  1864. Splide2.go("<");
  1865. } else if (normalizedKey === resolve("ArrowRight")) {
  1866. Splide2.go(">");
  1867. }
  1868. }
  1869. }
  1870. return {
  1871. mount,
  1872. destroy,
  1873. disable
  1874. };
  1875. }
  1876. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1877. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1878. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1879. function LazyLoad(Splide2, Components2, options) {
  1880. const { on, off, bind, emit } = EventInterface(Splide2);
  1881. const isSequential = options.lazyLoad === "sequential";
  1882. let images = [];
  1883. let index = 0;
  1884. function mount() {
  1885. if (options.lazyLoad) {
  1886. init();
  1887. on(EVENT_REFRESH, destroy);
  1888. on(EVENT_REFRESH, init);
  1889. if (!isSequential) {
  1890. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED, EVENT_SCROLLED], observe);
  1891. }
  1892. }
  1893. }
  1894. function init() {
  1895. Components2.Slides.forEach((_Slide) => {
  1896. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach((_img) => {
  1897. const src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  1898. const srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  1899. if (src !== _img.src || srcset !== _img.srcset) {
  1900. const className = options.classes.spinner;
  1901. const parent = _img.parentElement;
  1902. const _spinner = child(parent, `.${className}`) || create("span", className, parent);
  1903. setAttribute(_spinner, ROLE, "presentation");
  1904. images.push({ _img, _Slide, src, srcset, _spinner });
  1905. !_img.src && display(_img, "none");
  1906. }
  1907. });
  1908. });
  1909. if (isSequential) {
  1910. loadNext();
  1911. }
  1912. }
  1913. function destroy() {
  1914. index = 0;
  1915. images = [];
  1916. }
  1917. function observe() {
  1918. images = images.filter((data) => {
  1919. const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  1920. if (data._Slide.isWithin(Splide2.index, distance)) {
  1921. return load(data);
  1922. }
  1923. return true;
  1924. });
  1925. if (!images.length) {
  1926. off(EVENT_MOVED);
  1927. }
  1928. }
  1929. function load(data) {
  1930. const { _img } = data;
  1931. addClass(data._Slide.slide, CLASS_LOADING);
  1932. bind(_img, "load error", (e) => {
  1933. onLoad(data, e.type === "error");
  1934. });
  1935. ["srcset", "src"].forEach((name) => {
  1936. if (data[name]) {
  1937. setAttribute(_img, name, data[name]);
  1938. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  1939. }
  1940. });
  1941. }
  1942. function onLoad(data, error) {
  1943. const { _Slide } = data;
  1944. removeClass(_Slide.slide, CLASS_LOADING);
  1945. if (!error) {
  1946. remove(data._spinner);
  1947. display(data._img, "");
  1948. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  1949. emit(EVENT_RESIZE);
  1950. }
  1951. if (isSequential) {
  1952. loadNext();
  1953. }
  1954. }
  1955. function loadNext() {
  1956. if (index < images.length) {
  1957. load(images[index++]);
  1958. }
  1959. }
  1960. return {
  1961. mount,
  1962. destroy
  1963. };
  1964. }
  1965. function Pagination(Splide2, Components2, options) {
  1966. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1967. const { Slides, Elements, Controller } = Components2;
  1968. const { hasFocus, getIndex } = Controller;
  1969. const items = [];
  1970. let list;
  1971. function mount() {
  1972. init();
  1973. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1974. on([EVENT_MOVE, EVENT_SCROLLED], update);
  1975. }
  1976. function init() {
  1977. destroy();
  1978. if (options.pagination && Slides.isEnough()) {
  1979. createPagination();
  1980. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
  1981. update();
  1982. }
  1983. }
  1984. function destroy() {
  1985. if (list) {
  1986. remove(list);
  1987. items.forEach((item) => {
  1988. unbind(item.button, "click");
  1989. });
  1990. empty(items);
  1991. list = null;
  1992. }
  1993. }
  1994. function createPagination() {
  1995. const { length } = Splide2;
  1996. const { classes, i18n, perPage } = options;
  1997. const parent = options.pagination === "slider" && Elements.slider || Elements.root;
  1998. const max = hasFocus() ? length : ceil(length / perPage);
  1999. list = create("ul", classes.pagination, parent);
  2000. for (let i = 0; i < max; i++) {
  2001. const li = create("li", null, list);
  2002. const button = create("button", { class: classes.page, type: "button" }, li);
  2003. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  2004. bind(button, "click", apply(onClick, i));
  2005. setAttribute(button, ARIA_CONTROLS, Components2.Elements.list.id);
  2006. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  2007. items.push({ li, button, page: i });
  2008. }
  2009. }
  2010. function onClick(page) {
  2011. Controller.go(`>${page}`, true, () => {
  2012. const Slide = Slides.getAt(Controller.toIndex(page));
  2013. Slide && focus(Slide.slide);
  2014. });
  2015. }
  2016. function getAt(index) {
  2017. return items[Controller.toPage(index)];
  2018. }
  2019. function update() {
  2020. const prev = getAt(getIndex(true));
  2021. const curr = getAt(getIndex());
  2022. if (prev) {
  2023. removeClass(prev.button, CLASS_ACTIVE);
  2024. removeAttribute(prev.button, ARIA_CURRENT);
  2025. }
  2026. if (curr) {
  2027. addClass(curr.button, CLASS_ACTIVE);
  2028. setAttribute(curr.button, ARIA_CURRENT, true);
  2029. }
  2030. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  2031. }
  2032. return {
  2033. items,
  2034. mount,
  2035. destroy,
  2036. getAt,
  2037. update
  2038. };
  2039. }
  2040. const TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2041. function Sync(Splide2, Components2, options) {
  2042. const { list } = Components2.Elements;
  2043. const events = [];
  2044. function mount() {
  2045. Splide2.splides.forEach((target) => {
  2046. !target.isParent && sync(target.splide);
  2047. });
  2048. if (options.isNavigation) {
  2049. navigate();
  2050. }
  2051. }
  2052. function destroy() {
  2053. removeAttribute(list, ALL_ATTRIBUTES);
  2054. events.forEach((event) => {
  2055. event.destroy();
  2056. });
  2057. empty(events);
  2058. }
  2059. function remount() {
  2060. destroy();
  2061. mount();
  2062. }
  2063. function sync(splide) {
  2064. [Splide2, splide].forEach((instance) => {
  2065. const event = EventInterface(instance);
  2066. const target = instance === Splide2 ? splide : Splide2;
  2067. event.on(EVENT_MOVE, (index, prev, dest) => {
  2068. target.go(target.is(LOOP) ? dest : index);
  2069. });
  2070. events.push(event);
  2071. });
  2072. }
  2073. function navigate() {
  2074. const event = EventInterface(Splide2);
  2075. const { on } = event;
  2076. on(EVENT_CLICK, onClick);
  2077. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2078. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2079. setAttribute(list, ROLE, "menu");
  2080. events.push(event);
  2081. event.emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2082. }
  2083. function update() {
  2084. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2085. }
  2086. function onClick(Slide) {
  2087. Splide2.go(Slide.index);
  2088. }
  2089. function onKeydown(Slide, e) {
  2090. if (includes(TRIGGER_KEYS, e.key)) {
  2091. onClick(Slide);
  2092. prevent(e);
  2093. }
  2094. }
  2095. return {
  2096. mount,
  2097. destroy,
  2098. remount
  2099. };
  2100. }
  2101. function Wheel(Splide2, Components2, options) {
  2102. const { bind } = EventInterface(Splide2);
  2103. const { wheel: wheelOption } = options;
  2104. const wheel = isObject(wheelOption) ? wheelOption : wheelOption && {};
  2105. let lastTime = 0;
  2106. function mount() {
  2107. if (wheel) {
  2108. bind(Components2.Elements.track, "wheel", onWheel, SCROLL_LISTENER_OPTIONS);
  2109. }
  2110. }
  2111. function onWheel(e) {
  2112. if (e.cancelable) {
  2113. const { deltaY } = e;
  2114. const backwards = deltaY < 0;
  2115. const timeStamp = timeOf(e);
  2116. if (abs(deltaY) > (wheel.min || 0) && timeStamp - lastTime > (wheel.sleep || 0)) {
  2117. Splide2.go(backwards ? "<" : ">");
  2118. lastTime = timeStamp;
  2119. }
  2120. shouldPrevent(backwards) && prevent(e);
  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. exports.CLASSES = CLASSES;
  2761. exports.CLASS_ACTIVE = CLASS_ACTIVE;
  2762. exports.CLASS_ARROW = CLASS_ARROW;
  2763. exports.CLASS_ARROWS = CLASS_ARROWS;
  2764. exports.CLASS_ARROW_NEXT = CLASS_ARROW_NEXT;
  2765. exports.CLASS_ARROW_PREV = CLASS_ARROW_PREV;
  2766. exports.CLASS_AUTOPLAY = CLASS_AUTOPLAY;
  2767. exports.CLASS_CLONE = CLASS_CLONE;
  2768. exports.CLASS_CONTAINER = CLASS_CONTAINER;
  2769. exports.CLASS_INITIALIZED = CLASS_INITIALIZED;
  2770. exports.CLASS_LIST = CLASS_LIST;
  2771. exports.CLASS_LOADING = CLASS_LOADING;
  2772. exports.CLASS_NEXT = CLASS_NEXT;
  2773. exports.CLASS_PAGINATION = CLASS_PAGINATION;
  2774. exports.CLASS_PAGINATION_PAGE = CLASS_PAGINATION_PAGE;
  2775. exports.CLASS_PAUSE = CLASS_PAUSE;
  2776. exports.CLASS_PLAY = CLASS_PLAY;
  2777. exports.CLASS_PREV = CLASS_PREV;
  2778. exports.CLASS_PROGRESS = CLASS_PROGRESS;
  2779. exports.CLASS_PROGRESS_BAR = CLASS_PROGRESS_BAR;
  2780. exports.CLASS_ROOT = CLASS_ROOT;
  2781. exports.CLASS_SLIDE = CLASS_SLIDE;
  2782. exports.CLASS_SLIDER = CLASS_SLIDER;
  2783. exports.CLASS_SPINNER = CLASS_SPINNER;
  2784. exports.CLASS_SR = CLASS_SR;
  2785. exports.CLASS_TRACK = CLASS_TRACK;
  2786. exports.CLASS_VISIBLE = CLASS_VISIBLE;
  2787. exports.EVENT_ACTIVE = EVENT_ACTIVE;
  2788. exports.EVENT_ARROWS_MOUNTED = EVENT_ARROWS_MOUNTED;
  2789. exports.EVENT_ARROWS_UPDATED = EVENT_ARROWS_UPDATED;
  2790. exports.EVENT_AUTOPLAY_PAUSE = EVENT_AUTOPLAY_PAUSE;
  2791. exports.EVENT_AUTOPLAY_PLAY = EVENT_AUTOPLAY_PLAY;
  2792. exports.EVENT_AUTOPLAY_PLAYING = EVENT_AUTOPLAY_PLAYING;
  2793. exports.EVENT_CLICK = EVENT_CLICK;
  2794. exports.EVENT_DESTROY = EVENT_DESTROY;
  2795. exports.EVENT_DRAG = EVENT_DRAG;
  2796. exports.EVENT_DRAGGED = EVENT_DRAGGED;
  2797. exports.EVENT_DRAGGING = EVENT_DRAGGING;
  2798. exports.EVENT_HIDDEN = EVENT_HIDDEN;
  2799. exports.EVENT_INACTIVE = EVENT_INACTIVE;
  2800. exports.EVENT_LAZYLOAD_LOADED = EVENT_LAZYLOAD_LOADED;
  2801. exports.EVENT_MEDIA = EVENT_MEDIA;
  2802. exports.EVENT_MOUNTED = EVENT_MOUNTED;
  2803. exports.EVENT_MOVE = EVENT_MOVE;
  2804. exports.EVENT_MOVED = EVENT_MOVED;
  2805. exports.EVENT_NAVIGATION_MOUNTED = EVENT_NAVIGATION_MOUNTED;
  2806. exports.EVENT_PAGINATION_MOUNTED = EVENT_PAGINATION_MOUNTED;
  2807. exports.EVENT_PAGINATION_UPDATED = EVENT_PAGINATION_UPDATED;
  2808. exports.EVENT_READY = EVENT_READY;
  2809. exports.EVENT_REFRESH = EVENT_REFRESH;
  2810. exports.EVENT_REPOSITIONED = EVENT_REPOSITIONED;
  2811. exports.EVENT_RESIZE = EVENT_RESIZE;
  2812. exports.EVENT_RESIZED = EVENT_RESIZED;
  2813. exports.EVENT_SCROLL = EVENT_SCROLL;
  2814. exports.EVENT_SCROLLED = EVENT_SCROLLED;
  2815. exports.EVENT_SHIFTED = EVENT_SHIFTED;
  2816. exports.EVENT_SLIDE_KEYDOWN = EVENT_SLIDE_KEYDOWN;
  2817. exports.EVENT_UPDATED = EVENT_UPDATED;
  2818. exports.EVENT_VISIBLE = EVENT_VISIBLE;
  2819. exports.EventBus = EventBus;
  2820. exports.EventInterface = EventInterface;
  2821. exports.RequestInterval = RequestInterval;
  2822. exports.STATUS_CLASSES = STATUS_CLASSES;
  2823. exports.Splide = Splide;
  2824. exports.SplideRenderer = SplideRenderer;
  2825. exports.State = State;
  2826. exports.Throttle = Throttle;
  2827. exports["default"] = Splide;