splide.cjs.js 75 KB

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