splide.cjs.js 80 KB

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