splide.cjs.js 78 KB

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