splide.cjs.js 78 KB

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