splide.esm.js 86 KB

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