splide.cjs.js 81 KB

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