splide.esm.js 77 KB

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