splide.esm.js 85 KB

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