splide.cjs.js 78 KB

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