splide.esm.js 80 KB

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