splide.esm.js 76 KB

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