splide.esm.js 81 KB

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