splide.esm.js 85 KB

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