splide.esm.js 79 KB

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