splide.esm.js 77 KB

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