splide.esm.js 78 KB

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