splide.esm.js 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779
  1. /*!
  2. * Splide.js
  3. * Version : 3.2.5
  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 { root, track, list } = Components2.Elements;
  934. const { getAt } = Slides;
  935. let vertical;
  936. let rootRect;
  937. function mount() {
  938. init();
  939. bind(window, "resize load", Throttle(emit.bind(this, EVENT_RESIZE)));
  940. on([EVENT_UPDATED, EVENT_REFRESH], init);
  941. on(EVENT_RESIZE, resize);
  942. }
  943. function init() {
  944. rootRect = null;
  945. vertical = options.direction === TTB;
  946. style(root, "maxWidth", unit(options.width));
  947. style(track, resolve("paddingLeft"), cssPadding(false));
  948. style(track, resolve("paddingRight"), cssPadding(true));
  949. resize();
  950. }
  951. function resize() {
  952. const newRect = rect(root);
  953. if (!rootRect || rootRect.width !== newRect.width || rootRect.height !== newRect.height) {
  954. style(track, "height", cssTrackHeight());
  955. Slides.style(resolve("marginRight"), unit(options.gap));
  956. Slides.style("width", cssSlideWidth() || null);
  957. setSlidesHeight();
  958. rootRect = newRect;
  959. emit(EVENT_RESIZED);
  960. }
  961. }
  962. function setSlidesHeight() {
  963. Slides.style("height", cssSlideHeight() || null, true);
  964. }
  965. function cssPadding(right) {
  966. const { padding } = options;
  967. const prop = resolve(right ? "right" : "left");
  968. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  969. }
  970. function cssTrackHeight() {
  971. let height = "";
  972. if (vertical) {
  973. height = cssHeight();
  974. assert(height, "height or heightRatio is missing.");
  975. height = `calc(${height} - ${cssPadding(false)} - ${cssPadding(true)})`;
  976. }
  977. return height;
  978. }
  979. function cssHeight() {
  980. return unit(options.height || rect(list).width * options.heightRatio);
  981. }
  982. function cssSlideWidth() {
  983. return options.autoWidth ? "" : unit(options.fixedWidth) || (vertical ? "" : cssSlideSize());
  984. }
  985. function cssSlideHeight() {
  986. return unit(options.fixedHeight) || (vertical ? options.autoHeight ? "" : cssSlideSize() : cssHeight());
  987. }
  988. function cssSlideSize() {
  989. const gap = unit(options.gap);
  990. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  991. }
  992. function listSize() {
  993. return rect(list)[resolve("width")];
  994. }
  995. function slideSize(index, withoutGap) {
  996. const Slide = getAt(index || 0);
  997. return Slide ? rect(Slide.slide)[resolve("width")] + (withoutGap ? 0 : getGap()) : 0;
  998. }
  999. function totalSize(index, withoutGap) {
  1000. const Slide = getAt(index);
  1001. if (Slide) {
  1002. const right = rect(Slide.slide)[resolve("right")];
  1003. const left = rect(list)[resolve("left")];
  1004. return abs(right - left) + (withoutGap ? 0 : getGap());
  1005. }
  1006. return 0;
  1007. }
  1008. function sliderSize() {
  1009. return totalSize(Splide2.length - 1, true) - totalSize(-1, true);
  1010. }
  1011. function getGap() {
  1012. const Slide = getAt(0);
  1013. return Slide && parseFloat(style(Slide.slide, resolve("marginRight"))) || 0;
  1014. }
  1015. function getPadding(right) {
  1016. return parseFloat(style(track, resolve(`padding${right ? "Right" : "Left"}`))) || 0;
  1017. }
  1018. return {
  1019. mount,
  1020. listSize,
  1021. slideSize,
  1022. sliderSize,
  1023. totalSize,
  1024. getPadding
  1025. };
  1026. }
  1027. function Clones(Splide2, Components2, options) {
  1028. const { on, emit } = EventInterface(Splide2);
  1029. const { Elements, Slides } = Components2;
  1030. const { resolve } = Components2.Direction;
  1031. const clones = [];
  1032. let cloneCount;
  1033. function mount() {
  1034. init();
  1035. on(EVENT_REFRESH, refresh);
  1036. on([EVENT_UPDATED, EVENT_RESIZE], observe);
  1037. }
  1038. function init() {
  1039. if (cloneCount = computeCloneCount()) {
  1040. generate(cloneCount);
  1041. emit(EVENT_RESIZE);
  1042. }
  1043. }
  1044. function destroy() {
  1045. remove(clones);
  1046. empty(clones);
  1047. }
  1048. function refresh() {
  1049. destroy();
  1050. init();
  1051. }
  1052. function observe() {
  1053. if (cloneCount < computeCloneCount()) {
  1054. emit(EVENT_REFRESH);
  1055. }
  1056. }
  1057. function generate(count) {
  1058. const slides = Slides.get().slice();
  1059. const { length } = slides;
  1060. if (length) {
  1061. while (slides.length < count) {
  1062. push(slides, slides);
  1063. }
  1064. push(slides.slice(-count), slides.slice(0, count)).forEach((Slide, index) => {
  1065. const isHead = index < count;
  1066. const clone = cloneDeep(Slide.slide, index);
  1067. isHead ? before(clone, slides[0].slide) : append(Elements.list, clone);
  1068. push(clones, clone);
  1069. Slides.register(clone, index - count + (isHead ? 0 : length), Slide.index);
  1070. });
  1071. }
  1072. }
  1073. function cloneDeep(elm, index) {
  1074. const clone = elm.cloneNode(true);
  1075. addClass(clone, options.classes.clone);
  1076. clone.id = `${Splide2.root.id}-clone${pad(index + 1)}`;
  1077. return clone;
  1078. }
  1079. function computeCloneCount() {
  1080. let { clones: clones2 } = options;
  1081. if (!Splide2.is(LOOP)) {
  1082. clones2 = 0;
  1083. } else if (!clones2) {
  1084. const fixedSize = measure(Elements.list, options[resolve("fixedWidth")]);
  1085. const fixedCount = fixedSize && ceil(rect(Elements.track)[resolve("width")] / fixedSize);
  1086. const baseCount = fixedCount || options[resolve("autoWidth")] && Splide2.length || options.perPage;
  1087. clones2 = baseCount * (options.drag ? (options.flickMaxPages || 1) + 1 : 2);
  1088. }
  1089. return clones2;
  1090. }
  1091. return {
  1092. mount,
  1093. destroy
  1094. };
  1095. }
  1096. function Move(Splide2, Components2, options) {
  1097. const { on, emit } = EventInterface(Splide2);
  1098. const { slideSize, getPadding, totalSize, listSize, sliderSize } = Components2.Layout;
  1099. const { resolve, orient } = Components2.Direction;
  1100. const { list, track } = Components2.Elements;
  1101. let waiting;
  1102. function mount() {
  1103. on([EVENT_MOUNTED, EVENT_RESIZED, EVENT_UPDATED, EVENT_REFRESH], reposition);
  1104. }
  1105. function destroy() {
  1106. removeAttribute(list, "style");
  1107. }
  1108. function reposition() {
  1109. if (!isBusy()) {
  1110. Components2.Scroll.cancel();
  1111. jump(Splide2.index);
  1112. emit(EVENT_REPOSITIONED);
  1113. }
  1114. }
  1115. function move(dest, index, prev, callback) {
  1116. if (!isBusy()) {
  1117. const { set } = Splide2.state;
  1118. const position = getPosition();
  1119. const looping = dest !== index;
  1120. waiting = looping || options.waitForTransition;
  1121. set(MOVING);
  1122. emit(EVENT_MOVE, index, prev, dest);
  1123. Components2.Transition.start(dest, () => {
  1124. looping && jump(index);
  1125. waiting = false;
  1126. set(IDLE);
  1127. emit(EVENT_MOVED, index, prev, dest);
  1128. if (options.trimSpace === "move" && dest !== prev && position === getPosition()) {
  1129. Components2.Controller.go(dest > prev ? ">" : "<", false, callback);
  1130. } else {
  1131. callback && callback();
  1132. }
  1133. });
  1134. }
  1135. }
  1136. function jump(index) {
  1137. translate(toPosition(index, true));
  1138. }
  1139. function translate(position, preventLoop) {
  1140. if (!Splide2.is(FADE)) {
  1141. list.style.transform = `translate${resolve("X")}(${preventLoop ? position : loop(position)}px)`;
  1142. }
  1143. }
  1144. function loop(position) {
  1145. if (!waiting && Splide2.is(LOOP)) {
  1146. const diff = orient(position - getPosition());
  1147. const exceededMin = exceededLimit(false, position) && diff < 0;
  1148. const exceededMax = exceededLimit(true, position) && diff > 0;
  1149. if (exceededMin || exceededMax) {
  1150. position = shift(position, exceededMax);
  1151. }
  1152. }
  1153. return position;
  1154. }
  1155. function shift(position, backwards) {
  1156. const excess = position - getLimit(backwards);
  1157. const size = sliderSize();
  1158. position -= sign(excess) * size * ceil(abs(excess) / size);
  1159. return position;
  1160. }
  1161. function cancel() {
  1162. waiting = false;
  1163. translate(getPosition());
  1164. Components2.Transition.cancel();
  1165. }
  1166. function toIndex(position) {
  1167. const Slides = Components2.Slides.get();
  1168. let index = 0;
  1169. let minDistance = Infinity;
  1170. for (let i = 0; i < Slides.length; i++) {
  1171. const slideIndex = Slides[i].index;
  1172. const distance = abs(toPosition(slideIndex, true) - position);
  1173. if (distance <= minDistance) {
  1174. minDistance = distance;
  1175. index = slideIndex;
  1176. } else {
  1177. break;
  1178. }
  1179. }
  1180. return index;
  1181. }
  1182. function toPosition(index, trimming) {
  1183. const position = orient(totalSize(index - 1) - offset(index));
  1184. return trimming ? trim(position) : position;
  1185. }
  1186. function getPosition() {
  1187. const left = resolve("left");
  1188. return rect(list)[left] - rect(track)[left] + orient(getPadding(false));
  1189. }
  1190. function trim(position) {
  1191. if (options.trimSpace && Splide2.is(SLIDE)) {
  1192. position = clamp(position, 0, orient(sliderSize() - listSize()));
  1193. }
  1194. return position;
  1195. }
  1196. function offset(index) {
  1197. const { focus } = options;
  1198. return focus === "center" ? (listSize() - slideSize(index, true)) / 2 : +focus * slideSize(index) || 0;
  1199. }
  1200. function getLimit(max) {
  1201. return toPosition(max ? Components2.Controller.getEnd() : 0, !!options.trimSpace);
  1202. }
  1203. function isBusy() {
  1204. return !!waiting;
  1205. }
  1206. function exceededLimit(max, position) {
  1207. position = isUndefined(position) ? getPosition() : position;
  1208. const exceededMin = max !== true && orient(position) < orient(getLimit(false));
  1209. const exceededMax = max !== false && orient(position) > orient(getLimit(true));
  1210. return exceededMin || exceededMax;
  1211. }
  1212. return {
  1213. mount,
  1214. destroy,
  1215. move,
  1216. jump,
  1217. translate,
  1218. shift,
  1219. cancel,
  1220. toIndex,
  1221. toPosition,
  1222. getPosition,
  1223. getLimit,
  1224. isBusy,
  1225. exceededLimit
  1226. };
  1227. }
  1228. function Controller(Splide2, Components2, options) {
  1229. const { on } = EventInterface(Splide2);
  1230. const { Move } = Components2;
  1231. const { getPosition, getLimit } = Move;
  1232. const { isEnough, getLength } = Components2.Slides;
  1233. const isLoop = Splide2.is(LOOP);
  1234. const isSlide = Splide2.is(SLIDE);
  1235. let currIndex = options.start || 0;
  1236. let prevIndex = currIndex;
  1237. let slideCount;
  1238. let perMove;
  1239. let perPage;
  1240. function mount() {
  1241. init();
  1242. on([EVENT_UPDATED, EVENT_REFRESH], init, DEFAULT_EVENT_PRIORITY - 1);
  1243. }
  1244. function init() {
  1245. slideCount = getLength(true);
  1246. perMove = options.perMove;
  1247. perPage = options.perPage;
  1248. currIndex = clamp(currIndex, 0, slideCount - 1);
  1249. }
  1250. function go(control, allowSameIndex, callback) {
  1251. const dest = parse(control);
  1252. if (options.useScroll) {
  1253. scroll(dest, true, true, options.speed, callback);
  1254. } else {
  1255. const index = loop(dest);
  1256. if (index > -1 && !Move.isBusy() && (allowSameIndex || index !== currIndex)) {
  1257. setIndex(index);
  1258. Move.move(dest, index, prevIndex, callback);
  1259. }
  1260. }
  1261. }
  1262. function scroll(destination, useIndex, snap, duration, callback) {
  1263. const dest = useIndex ? destination : toDest(destination);
  1264. Components2.Scroll.scroll(useIndex || snap ? Move.toPosition(dest, true) : destination, duration, () => {
  1265. setIndex(Move.toIndex(Move.getPosition()));
  1266. callback && callback();
  1267. });
  1268. }
  1269. function parse(control) {
  1270. let index = currIndex;
  1271. if (isString(control)) {
  1272. const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
  1273. if (indicator === "+" || indicator === "-") {
  1274. index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex, true);
  1275. } else if (indicator === ">") {
  1276. index = number ? toIndex(+number) : getNext(true);
  1277. } else if (indicator === "<") {
  1278. index = getPrev(true);
  1279. }
  1280. } else {
  1281. if (isLoop) {
  1282. index = clamp(control, -perPage, slideCount + perPage - 1);
  1283. } else {
  1284. index = clamp(control, 0, getEnd());
  1285. }
  1286. }
  1287. return index;
  1288. }
  1289. function getNext(destination) {
  1290. return getAdjacent(false, destination);
  1291. }
  1292. function getPrev(destination) {
  1293. return getAdjacent(true, destination);
  1294. }
  1295. function getAdjacent(prev, destination) {
  1296. const number = perMove || (hasFocus() ? 1 : perPage);
  1297. const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
  1298. if (dest === -1 && isSlide) {
  1299. if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {
  1300. return prev ? 0 : getEnd();
  1301. }
  1302. }
  1303. return destination ? dest : loop(dest);
  1304. }
  1305. function computeDestIndex(dest, from, incremental) {
  1306. if (isEnough()) {
  1307. const end = getEnd();
  1308. if (dest < 0 || dest > end) {
  1309. if (between(0, dest, from, true) || between(end, from, dest, true)) {
  1310. dest = toIndex(toPage(dest));
  1311. } else {
  1312. if (isLoop) {
  1313. dest = perMove ? dest : dest < 0 ? -(slideCount % perPage || perPage) : slideCount;
  1314. } else if (options.rewind) {
  1315. dest = dest < 0 ? end : 0;
  1316. } else {
  1317. dest = -1;
  1318. }
  1319. }
  1320. } else {
  1321. if (!incremental && dest !== from) {
  1322. dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
  1323. }
  1324. }
  1325. } else {
  1326. dest = -1;
  1327. }
  1328. return dest;
  1329. }
  1330. function getEnd() {
  1331. let end = slideCount - perPage;
  1332. if (hasFocus() || isLoop && perMove) {
  1333. end = slideCount - 1;
  1334. }
  1335. return max(end, 0);
  1336. }
  1337. function loop(index) {
  1338. if (isLoop) {
  1339. return isEnough() ? index % slideCount + (index < 0 ? slideCount : 0) : -1;
  1340. }
  1341. return index;
  1342. }
  1343. function toIndex(page) {
  1344. return clamp(hasFocus() ? page : perPage * page, 0, getEnd());
  1345. }
  1346. function toPage(index) {
  1347. if (!hasFocus()) {
  1348. index = between(index, slideCount - perPage, slideCount - 1) ? slideCount - 1 : index;
  1349. index = floor(index / perPage);
  1350. }
  1351. return index;
  1352. }
  1353. function toDest(destination) {
  1354. const closest = Move.toIndex(destination);
  1355. return isSlide ? clamp(closest, 0, getEnd()) : closest;
  1356. }
  1357. function setIndex(index) {
  1358. if (index !== currIndex) {
  1359. prevIndex = currIndex;
  1360. currIndex = index;
  1361. }
  1362. }
  1363. function getIndex(prev) {
  1364. return prev ? prevIndex : currIndex;
  1365. }
  1366. function hasFocus() {
  1367. return !isUndefined(options.focus) || options.isNavigation;
  1368. }
  1369. return {
  1370. mount,
  1371. go,
  1372. scroll,
  1373. getNext,
  1374. getPrev,
  1375. getEnd,
  1376. setIndex,
  1377. getIndex,
  1378. toIndex,
  1379. toPage,
  1380. toDest,
  1381. hasFocus
  1382. };
  1383. }
  1384. const XML_NAME_SPACE = "http://www.w3.org/2000/svg";
  1385. const PATH = "m15.5 0.932-4.3 4.38 14.5 14.6-14.5 14.5 4.3 4.4 14.6-14.6 4.4-4.3-4.4-4.4-14.6-14.6z";
  1386. const SIZE = 40;
  1387. function Arrows(Splide2, Components2, options) {
  1388. const { on, bind, emit } = EventInterface(Splide2);
  1389. const { classes, i18n } = options;
  1390. const { Elements, Controller } = Components2;
  1391. let wrapper = Elements.arrows;
  1392. let prev = Elements.prev;
  1393. let next = Elements.next;
  1394. let created;
  1395. const arrows = {};
  1396. function mount() {
  1397. init();
  1398. on(EVENT_UPDATED, init);
  1399. }
  1400. function init() {
  1401. if (options.arrows) {
  1402. if (!prev || !next) {
  1403. createArrows();
  1404. }
  1405. }
  1406. if (prev && next) {
  1407. if (!arrows.prev) {
  1408. const { id } = Elements.track;
  1409. setAttribute(prev, ARIA_CONTROLS, id);
  1410. setAttribute(next, ARIA_CONTROLS, id);
  1411. arrows.prev = prev;
  1412. arrows.next = next;
  1413. listen();
  1414. emit(EVENT_ARROWS_MOUNTED, prev, next);
  1415. } else {
  1416. display(wrapper, options.arrows === false ? "none" : "");
  1417. }
  1418. }
  1419. }
  1420. function destroy() {
  1421. if (created) {
  1422. remove(wrapper);
  1423. } else {
  1424. removeAttribute(prev, ALL_ATTRIBUTES);
  1425. removeAttribute(next, ALL_ATTRIBUTES);
  1426. }
  1427. }
  1428. function listen() {
  1429. const { go } = Controller;
  1430. on([EVENT_MOUNTED, EVENT_MOVED, EVENT_UPDATED, EVENT_REFRESH, EVENT_SCROLLED], update);
  1431. bind(next, "click", () => {
  1432. go(">", true);
  1433. });
  1434. bind(prev, "click", () => {
  1435. go("<", true);
  1436. });
  1437. }
  1438. function createArrows() {
  1439. wrapper = create("div", classes.arrows);
  1440. prev = createArrow(true);
  1441. next = createArrow(false);
  1442. created = true;
  1443. append(wrapper, [prev, next]);
  1444. before(wrapper, child(options.arrows === "slider" && Elements.slider || Splide2.root));
  1445. }
  1446. function createArrow(prev2) {
  1447. const arrow = `<button class="${classes.arrow} ${prev2 ? classes.prev : classes.next}" type="button"><svg xmlns="${XML_NAME_SPACE}" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}"><path d="${options.arrowPath || PATH}" />`;
  1448. return parseHtml(arrow);
  1449. }
  1450. function update() {
  1451. const index = Splide2.index;
  1452. const prevIndex = Controller.getPrev();
  1453. const nextIndex = Controller.getNext();
  1454. const prevLabel = prevIndex > -1 && index < prevIndex ? i18n.last : i18n.prev;
  1455. const nextLabel = nextIndex > -1 && index > nextIndex ? i18n.first : i18n.next;
  1456. prev.disabled = prevIndex < 0;
  1457. next.disabled = nextIndex < 0;
  1458. setAttribute(prev, ARIA_LABEL, prevLabel);
  1459. setAttribute(next, ARIA_LABEL, nextLabel);
  1460. emit(EVENT_ARROWS_UPDATED, prev, next, prevIndex, nextIndex);
  1461. }
  1462. return {
  1463. arrows,
  1464. mount,
  1465. destroy
  1466. };
  1467. }
  1468. function Autoplay(Splide2, Components2, options) {
  1469. const { on, bind, emit } = EventInterface(Splide2);
  1470. const { Elements } = Components2;
  1471. const interval = RequestInterval(options.interval, Splide2.go.bind(Splide2, ">"), update);
  1472. const { isPaused } = interval;
  1473. let hovered;
  1474. let focused;
  1475. let paused;
  1476. function mount() {
  1477. const { autoplay } = options;
  1478. if (autoplay) {
  1479. initButton(true);
  1480. initButton(false);
  1481. listen();
  1482. if (autoplay !== "pause") {
  1483. play();
  1484. }
  1485. }
  1486. }
  1487. function initButton(forPause) {
  1488. const prop = forPause ? "pause" : "play";
  1489. const button = Elements[prop];
  1490. if (button) {
  1491. setAttribute(button, ARIA_CONTROLS, Elements.track.id);
  1492. setAttribute(button, ARIA_LABEL, options.i18n[prop]);
  1493. bind(button, "click", forPause ? pause : play);
  1494. }
  1495. }
  1496. function listen() {
  1497. const { root } = Elements;
  1498. if (options.pauseOnHover) {
  1499. bind(root, "mouseenter mouseleave", (e) => {
  1500. hovered = e.type === "mouseenter";
  1501. autoToggle();
  1502. });
  1503. }
  1504. if (options.pauseOnFocus) {
  1505. bind(root, "focusin focusout", (e) => {
  1506. focused = e.type === "focusin";
  1507. autoToggle();
  1508. });
  1509. }
  1510. on([EVENT_MOVE, EVENT_SCROLL, EVENT_REFRESH], interval.rewind);
  1511. }
  1512. function play() {
  1513. if (isPaused() && Components2.Slides.isEnough()) {
  1514. interval.start(!options.resetProgress);
  1515. focused = hovered = paused = false;
  1516. emit(EVENT_AUTOPLAY_PLAY);
  1517. }
  1518. }
  1519. function pause(manual = true) {
  1520. if (!isPaused()) {
  1521. interval.pause();
  1522. emit(EVENT_AUTOPLAY_PAUSE);
  1523. }
  1524. paused = manual;
  1525. }
  1526. function autoToggle() {
  1527. if (!paused) {
  1528. if (!hovered && !focused) {
  1529. play();
  1530. } else {
  1531. pause(false);
  1532. }
  1533. }
  1534. }
  1535. function update(rate) {
  1536. const { bar } = Elements;
  1537. if (bar) {
  1538. style(bar, "width", `${rate * 100}%`);
  1539. }
  1540. emit(EVENT_AUTOPLAY_PLAYING, rate);
  1541. }
  1542. return {
  1543. mount,
  1544. destroy: interval.cancel,
  1545. play,
  1546. pause,
  1547. isPaused
  1548. };
  1549. }
  1550. function Cover(Splide2, Components2, options) {
  1551. const { on } = EventInterface(Splide2);
  1552. function mount() {
  1553. if (options.cover) {
  1554. on(EVENT_LAZYLOAD_LOADED, (img, Slide) => {
  1555. toggle(true, img, Slide);
  1556. });
  1557. on([EVENT_MOUNTED, EVENT_UPDATED, EVENT_REFRESH], apply.bind(null, true));
  1558. }
  1559. }
  1560. function destroy() {
  1561. apply(false);
  1562. }
  1563. function apply(cover) {
  1564. Components2.Slides.forEach((Slide) => {
  1565. const img = child(Slide.container || Slide.slide, "img");
  1566. if (img && img.src) {
  1567. toggle(cover, img, Slide);
  1568. }
  1569. });
  1570. }
  1571. function toggle(cover, img, Slide) {
  1572. Slide.style("background", cover ? `center/cover no-repeat url("${img.src}")` : "", true);
  1573. display(img, cover ? "none" : "");
  1574. }
  1575. return {
  1576. mount,
  1577. destroy
  1578. };
  1579. }
  1580. const BOUNCE_DIFF_THRESHOLD = 10;
  1581. const BOUNCE_DURATION = 600;
  1582. const FRICTION_FACTOR = 0.6;
  1583. const BASE_VELOCITY = 1.5;
  1584. const MIN_DURATION = 800;
  1585. function Scroll(Splide2, Components2, options) {
  1586. const { on, emit } = EventInterface(Splide2);
  1587. const { Move } = Components2;
  1588. const { getPosition, getLimit, exceededLimit } = Move;
  1589. let interval;
  1590. let scrollCallback;
  1591. function mount() {
  1592. on(EVENT_MOVE, clear);
  1593. on([EVENT_UPDATED, EVENT_REFRESH], cancel);
  1594. }
  1595. function scroll(destination, duration, callback, suppressConstraint) {
  1596. const start = getPosition();
  1597. let friction = 1;
  1598. duration = duration || computeDuration(abs(destination - start));
  1599. scrollCallback = callback;
  1600. clear();
  1601. interval = RequestInterval(duration, onScrolled, (rate) => {
  1602. const position = getPosition();
  1603. const target = start + (destination - start) * easing(rate);
  1604. const diff = (target - getPosition()) * friction;
  1605. Move.translate(position + diff);
  1606. if (Splide2.is(SLIDE) && !suppressConstraint && exceededLimit()) {
  1607. friction *= FRICTION_FACTOR;
  1608. if (abs(diff) < BOUNCE_DIFF_THRESHOLD) {
  1609. bounce(exceededLimit(false));
  1610. }
  1611. }
  1612. }, 1);
  1613. emit(EVENT_SCROLL);
  1614. interval.start();
  1615. }
  1616. function bounce(backwards) {
  1617. scroll(getLimit(!backwards), BOUNCE_DURATION, null, true);
  1618. }
  1619. function onScrolled() {
  1620. const position = getPosition();
  1621. const index = Move.toIndex(position);
  1622. if (!between(index, 0, Splide2.length - 1)) {
  1623. Move.translate(Move.shift(position, index > 0), true);
  1624. }
  1625. scrollCallback && scrollCallback();
  1626. emit(EVENT_SCROLLED);
  1627. }
  1628. function computeDuration(distance) {
  1629. return max(distance / BASE_VELOCITY, MIN_DURATION);
  1630. }
  1631. function clear() {
  1632. if (interval) {
  1633. interval.cancel();
  1634. }
  1635. }
  1636. function cancel() {
  1637. if (interval && !interval.isPaused()) {
  1638. clear();
  1639. onScrolled();
  1640. }
  1641. }
  1642. function easing(t) {
  1643. const { easingFunc } = options;
  1644. return easingFunc ? easingFunc(t) : 1 - Math.pow(1 - t, 4);
  1645. }
  1646. return {
  1647. mount,
  1648. destroy: clear,
  1649. scroll,
  1650. cancel
  1651. };
  1652. }
  1653. const FRICTION = 5;
  1654. const LOG_INTERVAL = 200;
  1655. const POINTER_DOWN_EVENTS = "touchstart mousedown";
  1656. const POINTER_MOVE_EVENTS = "touchmove mousemove";
  1657. const POINTER_UP_EVENTS = "touchend touchcancel mouseup";
  1658. function Drag(Splide2, Components2, options) {
  1659. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1660. const { Move, Scroll, Controller } = Components2;
  1661. const { track } = Components2.Elements;
  1662. const { resolve, orient } = Components2.Direction;
  1663. const { getPosition, exceededLimit } = Move;
  1664. const listenerOptions = { passive: false, capture: true };
  1665. let basePosition;
  1666. let baseEvent;
  1667. let prevBaseEvent;
  1668. let lastEvent;
  1669. let isFree;
  1670. let dragging;
  1671. let hasExceeded = false;
  1672. let clickPrevented;
  1673. let disabled;
  1674. let target;
  1675. function mount() {
  1676. bind(track, POINTER_MOVE_EVENTS, noop, listenerOptions);
  1677. bind(track, POINTER_UP_EVENTS, noop, listenerOptions);
  1678. bind(track, POINTER_DOWN_EVENTS, onPointerDown, listenerOptions);
  1679. bind(track, "click", onClick, { capture: true });
  1680. bind(track, "dragstart", prevent);
  1681. on([EVENT_MOUNTED, EVENT_UPDATED], init);
  1682. }
  1683. function init() {
  1684. const { drag } = options;
  1685. disable(!drag);
  1686. isFree = drag === "free";
  1687. }
  1688. function onPointerDown(e) {
  1689. if (!disabled) {
  1690. const { noDrag } = options;
  1691. const isTouch = isTouchEvent(e);
  1692. const isDraggable = !noDrag || isHTMLElement(e.target) && !matches(e.target, noDrag);
  1693. if (isDraggable && (isTouch || !e.button)) {
  1694. if (!Move.isBusy()) {
  1695. target = isTouch ? track : window;
  1696. prevBaseEvent = null;
  1697. lastEvent = null;
  1698. clickPrevented = false;
  1699. bind(target, POINTER_MOVE_EVENTS, onPointerMove, listenerOptions);
  1700. bind(target, POINTER_UP_EVENTS, onPointerUp, listenerOptions);
  1701. Move.cancel();
  1702. Scroll.cancel();
  1703. save(e);
  1704. } else {
  1705. prevent(e, true);
  1706. }
  1707. }
  1708. }
  1709. }
  1710. function onPointerMove(e) {
  1711. if (!lastEvent) {
  1712. emit(EVENT_DRAG);
  1713. }
  1714. lastEvent = e;
  1715. if (e.cancelable) {
  1716. const diff = coordOf(e) - coordOf(baseEvent);
  1717. if (dragging) {
  1718. Move.translate(basePosition + constrain(diff));
  1719. const expired = timeOf(e) - timeOf(baseEvent) > LOG_INTERVAL;
  1720. const exceeded = hasExceeded !== (hasExceeded = exceededLimit());
  1721. if (expired || exceeded) {
  1722. save(e);
  1723. }
  1724. emit(EVENT_DRAGGING);
  1725. clickPrevented = true;
  1726. prevent(e);
  1727. } else {
  1728. let { dragMinThreshold: thresholds } = options;
  1729. thresholds = isObject(thresholds) ? thresholds : { mouse: 0, touch: +thresholds || 10 };
  1730. dragging = abs(diff) > (isTouchEvent(e) ? thresholds.touch : thresholds.mouse);
  1731. if (isSliderDirection()) {
  1732. prevent(e);
  1733. }
  1734. }
  1735. }
  1736. }
  1737. function onPointerUp(e) {
  1738. unbind(target, POINTER_MOVE_EVENTS, onPointerMove);
  1739. unbind(target, POINTER_UP_EVENTS, onPointerUp);
  1740. if (lastEvent) {
  1741. if (dragging || e.cancelable && isSliderDirection()) {
  1742. const velocity = computeVelocity(e);
  1743. const destination = computeDestination(velocity);
  1744. if (isFree) {
  1745. Controller.scroll(destination);
  1746. } else if (Splide2.is(FADE)) {
  1747. Controller.go(Splide2.index + orient(sign(velocity)));
  1748. } else {
  1749. Controller.go(Controller.toDest(destination), true);
  1750. }
  1751. prevent(e);
  1752. }
  1753. emit(EVENT_DRAGGED);
  1754. }
  1755. dragging = false;
  1756. }
  1757. function save(e) {
  1758. prevBaseEvent = baseEvent;
  1759. baseEvent = e;
  1760. basePosition = getPosition();
  1761. }
  1762. function onClick(e) {
  1763. if (!disabled && clickPrevented) {
  1764. prevent(e, true);
  1765. }
  1766. }
  1767. function isSliderDirection() {
  1768. const diffX = abs(coordOf(lastEvent) - coordOf(baseEvent));
  1769. const diffY = abs(coordOf(lastEvent, true) - coordOf(baseEvent, true));
  1770. return diffX > diffY;
  1771. }
  1772. function computeVelocity(e) {
  1773. if (Splide2.is(LOOP) || !hasExceeded) {
  1774. const base = baseEvent === lastEvent && prevBaseEvent || baseEvent;
  1775. const diffCoord = coordOf(lastEvent) - coordOf(base);
  1776. const diffTime = timeOf(e) - timeOf(base);
  1777. const isFlick = timeOf(e) - timeOf(lastEvent) < LOG_INTERVAL;
  1778. if (diffTime && isFlick) {
  1779. return diffCoord / diffTime;
  1780. }
  1781. }
  1782. return 0;
  1783. }
  1784. function computeDestination(velocity) {
  1785. return getPosition() + sign(velocity) * min(abs(velocity) * (options.flickPower || 600), isFree ? Infinity : Components2.Layout.listSize() * (options.flickMaxPages || 1));
  1786. }
  1787. function coordOf(e, orthogonal) {
  1788. return (isTouchEvent(e) ? e.touches[0] : e)[`page${resolve(orthogonal ? "Y" : "X")}`];
  1789. }
  1790. function timeOf(e) {
  1791. return e.timeStamp;
  1792. }
  1793. function constrain(diff) {
  1794. return diff / (hasExceeded && Splide2.is(SLIDE) ? FRICTION : 1);
  1795. }
  1796. function isTouchEvent(e) {
  1797. return typeof TouchEvent !== "undefined" && e instanceof TouchEvent;
  1798. }
  1799. function isDragging() {
  1800. return dragging;
  1801. }
  1802. function disable(value) {
  1803. disabled = value;
  1804. }
  1805. return {
  1806. mount,
  1807. disable,
  1808. isDragging
  1809. };
  1810. }
  1811. const IE_ARROW_KEYS = ["Left", "Right", "Up", "Down"];
  1812. function Keyboard(Splide2, Components2, options) {
  1813. const { on, bind, unbind } = EventInterface(Splide2);
  1814. const { root } = Components2.Elements;
  1815. const { resolve } = Components2.Direction;
  1816. let target;
  1817. function mount() {
  1818. init();
  1819. on(EVENT_UPDATED, () => {
  1820. destroy();
  1821. init();
  1822. });
  1823. }
  1824. function init() {
  1825. const { keyboard = "global" } = options;
  1826. if (keyboard) {
  1827. if (keyboard === "focused") {
  1828. target = root;
  1829. setAttribute(root, TAB_INDEX, 0);
  1830. } else {
  1831. target = window;
  1832. }
  1833. bind(target, "keydown", onKeydown);
  1834. }
  1835. }
  1836. function destroy() {
  1837. unbind(target, "keydown");
  1838. if (isHTMLElement(target)) {
  1839. removeAttribute(target, TAB_INDEX);
  1840. }
  1841. }
  1842. function onKeydown(e) {
  1843. const { key } = e;
  1844. const normalizedKey = includes(IE_ARROW_KEYS, key) ? `Arrow${key}` : key;
  1845. if (normalizedKey === resolve("ArrowLeft")) {
  1846. Splide2.go("<");
  1847. } else if (normalizedKey === resolve("ArrowRight")) {
  1848. Splide2.go(">");
  1849. }
  1850. }
  1851. return {
  1852. mount,
  1853. destroy
  1854. };
  1855. }
  1856. const SRC_DATA_ATTRIBUTE = `${DATA_ATTRIBUTE}-lazy`;
  1857. const SRCSET_DATA_ATTRIBUTE = `${SRC_DATA_ATTRIBUTE}-srcset`;
  1858. const IMAGE_SELECTOR = `[${SRC_DATA_ATTRIBUTE}], [${SRCSET_DATA_ATTRIBUTE}]`;
  1859. function LazyLoad(Splide2, Components2, options) {
  1860. const { on, off, bind, emit } = EventInterface(Splide2);
  1861. const isSequential = options.lazyLoad === "sequential";
  1862. let images = [];
  1863. let index = 0;
  1864. function mount() {
  1865. if (options.lazyLoad) {
  1866. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  1867. destroy();
  1868. init();
  1869. });
  1870. if (!isSequential) {
  1871. on([EVENT_MOUNTED, EVENT_REFRESH, EVENT_MOVED], observe);
  1872. }
  1873. }
  1874. }
  1875. function init() {
  1876. Components2.Slides.forEach((_Slide) => {
  1877. queryAll(_Slide.slide, IMAGE_SELECTOR).forEach((_img) => {
  1878. const src = getAttribute(_img, SRC_DATA_ATTRIBUTE);
  1879. const srcset = getAttribute(_img, SRCSET_DATA_ATTRIBUTE);
  1880. if (src !== _img.src || srcset !== _img.srcset) {
  1881. const _spinner = create("span", options.classes.spinner, _img.parentElement);
  1882. setAttribute(_spinner, ROLE, "presentation");
  1883. images.push({ _img, _Slide, src, srcset, _spinner });
  1884. !_img.src && display(_img, "none");
  1885. }
  1886. });
  1887. });
  1888. if (isSequential) {
  1889. loadNext();
  1890. }
  1891. }
  1892. function destroy() {
  1893. index = 0;
  1894. images = [];
  1895. }
  1896. function observe() {
  1897. images = images.filter((data) => {
  1898. const distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
  1899. if (data._Slide.isWithin(Splide2.index, distance)) {
  1900. return load(data);
  1901. }
  1902. return true;
  1903. });
  1904. if (!images.length) {
  1905. off(EVENT_MOVED);
  1906. }
  1907. }
  1908. function load(data) {
  1909. const { _img } = data;
  1910. addClass(data._Slide.slide, CLASS_LOADING);
  1911. bind(_img, "load error", (e) => {
  1912. onLoad(data, e.type === "error");
  1913. });
  1914. ["src", "srcset"].forEach((name) => {
  1915. if (data[name]) {
  1916. setAttribute(_img, name, data[name]);
  1917. removeAttribute(_img, name === "src" ? SRC_DATA_ATTRIBUTE : SRCSET_DATA_ATTRIBUTE);
  1918. }
  1919. });
  1920. }
  1921. function onLoad(data, error) {
  1922. const { _Slide } = data;
  1923. removeClass(_Slide.slide, CLASS_LOADING);
  1924. if (!error) {
  1925. remove(data._spinner);
  1926. display(data._img, "");
  1927. emit(EVENT_LAZYLOAD_LOADED, data._img, _Slide);
  1928. emit(EVENT_RESIZE);
  1929. }
  1930. if (isSequential) {
  1931. loadNext();
  1932. }
  1933. }
  1934. function loadNext() {
  1935. if (index < images.length) {
  1936. load(images[index++]);
  1937. }
  1938. }
  1939. return {
  1940. mount,
  1941. destroy
  1942. };
  1943. }
  1944. function Pagination(Splide2, Components2, options) {
  1945. const { on, emit, bind, unbind } = EventInterface(Splide2);
  1946. const { Slides, Elements, Controller } = Components2;
  1947. const { hasFocus, getIndex } = Controller;
  1948. const items = [];
  1949. let list;
  1950. function mount() {
  1951. init();
  1952. on([EVENT_UPDATED, EVENT_REFRESH], init);
  1953. on([EVENT_MOVE, EVENT_SCROLLED], update);
  1954. }
  1955. function init() {
  1956. destroy();
  1957. if (options.pagination && Slides.isEnough()) {
  1958. createPagination();
  1959. emit(EVENT_PAGINATION_MOUNTED, { list, items }, getAt(Splide2.index));
  1960. update();
  1961. }
  1962. }
  1963. function destroy() {
  1964. if (list) {
  1965. remove(list);
  1966. items.forEach((item) => {
  1967. unbind(item.button, "click");
  1968. });
  1969. empty(items);
  1970. list = null;
  1971. }
  1972. }
  1973. function createPagination() {
  1974. const { length } = Splide2;
  1975. const { classes, i18n, perPage } = options;
  1976. const parent = options.pagination === "slider" && Elements.slider || Elements.root;
  1977. const max = hasFocus() ? length : ceil(length / perPage);
  1978. list = create("ul", classes.pagination, parent);
  1979. for (let i = 0; i < max; i++) {
  1980. const li = create("li", null, list);
  1981. const button = create("button", { class: classes.page, type: "button" }, li);
  1982. const controls = Slides.getIn(i).map((Slide) => Slide.slide.id);
  1983. const text = !hasFocus() && perPage > 1 ? i18n.pageX : i18n.slideX;
  1984. bind(button, "click", onClick.bind(null, i));
  1985. setAttribute(button, ARIA_CONTROLS, controls.join(" "));
  1986. setAttribute(button, ARIA_LABEL, format(text, i + 1));
  1987. items.push({ li, button, page: i });
  1988. }
  1989. }
  1990. function onClick(page) {
  1991. Controller.go(`>${page}`, true, () => {
  1992. const Slide = Slides.getAt(Controller.toIndex(page));
  1993. Slide && focus(Slide.slide);
  1994. });
  1995. }
  1996. function getAt(index) {
  1997. return items[Controller.toPage(index)];
  1998. }
  1999. function update() {
  2000. const prev = getAt(getIndex(true));
  2001. const curr = getAt(getIndex());
  2002. if (prev) {
  2003. removeClass(prev.button, CLASS_ACTIVE);
  2004. removeAttribute(prev.button, ARIA_CURRENT);
  2005. }
  2006. if (curr) {
  2007. addClass(curr.button, CLASS_ACTIVE);
  2008. setAttribute(curr.button, ARIA_CURRENT, true);
  2009. }
  2010. emit(EVENT_PAGINATION_UPDATED, { list, items }, prev, curr);
  2011. }
  2012. return {
  2013. items,
  2014. mount,
  2015. destroy,
  2016. getAt
  2017. };
  2018. }
  2019. const TRIGGER_KEYS = [" ", "Enter", "Spacebar"];
  2020. function Sync(Splide2, Components2, options) {
  2021. const { splides } = Splide2;
  2022. const { list } = Components2.Elements;
  2023. function mount() {
  2024. if (options.isNavigation) {
  2025. navigate();
  2026. } else {
  2027. sync();
  2028. }
  2029. }
  2030. function destroy() {
  2031. removeAttribute(list, ALL_ATTRIBUTES);
  2032. }
  2033. function sync() {
  2034. const processed = [];
  2035. splides.concat(Splide2).forEach((splide, index, instances) => {
  2036. EventInterface(splide).on(EVENT_MOVE, (index2, prev, dest) => {
  2037. instances.forEach((instance) => {
  2038. if (instance !== splide && !includes(processed, splide)) {
  2039. processed.push(instance);
  2040. instance.go(instance.is(LOOP) ? dest : index2);
  2041. }
  2042. });
  2043. empty(processed);
  2044. });
  2045. });
  2046. }
  2047. function navigate() {
  2048. const { on, emit } = EventInterface(Splide2);
  2049. on(EVENT_CLICK, onClick);
  2050. on(EVENT_SLIDE_KEYDOWN, onKeydown);
  2051. on([EVENT_MOUNTED, EVENT_UPDATED], update);
  2052. setAttribute(list, ROLE, "menu");
  2053. emit(EVENT_NAVIGATION_MOUNTED, Splide2.splides);
  2054. }
  2055. function update() {
  2056. setAttribute(list, ARIA_ORIENTATION, options.direction !== TTB ? "horizontal" : null);
  2057. }
  2058. function onClick(Slide) {
  2059. Splide2.go(Slide.index);
  2060. }
  2061. function onKeydown(Slide, e) {
  2062. if (includes(TRIGGER_KEYS, e.key)) {
  2063. onClick(Slide);
  2064. prevent(e);
  2065. }
  2066. }
  2067. return {
  2068. mount,
  2069. destroy
  2070. };
  2071. }
  2072. function Wheel(Splide2, Components2, options) {
  2073. const { bind } = EventInterface(Splide2);
  2074. function mount() {
  2075. if (options.wheel) {
  2076. bind(Components2.Elements.track, "wheel", onWheel, { passive: false, capture: true });
  2077. }
  2078. }
  2079. function onWheel(e) {
  2080. const { deltaY } = e;
  2081. if (deltaY) {
  2082. Splide2.go(deltaY < 0 ? "<" : ">");
  2083. prevent(e);
  2084. }
  2085. }
  2086. return {
  2087. mount
  2088. };
  2089. }
  2090. var ComponentConstructors = /*#__PURE__*/Object.freeze({
  2091. __proto__: null,
  2092. Options: Options,
  2093. Direction: Direction,
  2094. Elements: Elements,
  2095. Slides: Slides,
  2096. Layout: Layout,
  2097. Clones: Clones,
  2098. Move: Move,
  2099. Controller: Controller,
  2100. Arrows: Arrows,
  2101. Autoplay: Autoplay,
  2102. Cover: Cover,
  2103. Scroll: Scroll,
  2104. Drag: Drag,
  2105. Keyboard: Keyboard,
  2106. LazyLoad: LazyLoad,
  2107. Pagination: Pagination,
  2108. Sync: Sync,
  2109. Wheel: Wheel
  2110. });
  2111. const I18N = {
  2112. prev: "Previous slide",
  2113. next: "Next slide",
  2114. first: "Go to first slide",
  2115. last: "Go to last slide",
  2116. slideX: "Go to slide %s",
  2117. pageX: "Go to page %s",
  2118. play: "Start autoplay",
  2119. pause: "Pause autoplay"
  2120. };
  2121. const DEFAULTS = {
  2122. type: "slide",
  2123. speed: 400,
  2124. waitForTransition: true,
  2125. perPage: 1,
  2126. arrows: true,
  2127. pagination: true,
  2128. interval: 5e3,
  2129. pauseOnHover: true,
  2130. pauseOnFocus: true,
  2131. resetProgress: true,
  2132. easing: "cubic-bezier(0.25, 1, 0.5, 1)",
  2133. drag: true,
  2134. direction: "ltr",
  2135. slideFocus: true,
  2136. trimSpace: true,
  2137. focusableNodes: "a, button, textarea, input, select, iframe",
  2138. classes: CLASSES,
  2139. i18n: I18N
  2140. };
  2141. function Fade(Splide2, Components2, options) {
  2142. const { on } = EventInterface(Splide2);
  2143. function mount() {
  2144. on([EVENT_MOUNTED, EVENT_REFRESH], () => {
  2145. nextTick(() => {
  2146. Components2.Slides.style("transition", `opacity ${options.speed}ms ${options.easing}`);
  2147. });
  2148. });
  2149. }
  2150. function start(index, done) {
  2151. const { track } = Components2.Elements;
  2152. style(track, "height", unit(rect(track).height));
  2153. nextTick(() => {
  2154. done();
  2155. style(track, "height", "");
  2156. });
  2157. }
  2158. return {
  2159. mount,
  2160. start,
  2161. cancel: noop
  2162. };
  2163. }
  2164. function Slide(Splide2, Components2, options) {
  2165. const { bind } = EventInterface(Splide2);
  2166. const { Move, Controller } = Components2;
  2167. const { list } = Components2.Elements;
  2168. let endCallback;
  2169. function mount() {
  2170. bind(list, "transitionend", (e) => {
  2171. if (e.target === list && endCallback) {
  2172. cancel();
  2173. endCallback();
  2174. }
  2175. });
  2176. }
  2177. function start(index, done) {
  2178. const destination = Move.toPosition(index, true);
  2179. const position = Move.getPosition();
  2180. const speed = getSpeed(index);
  2181. if (abs(destination - position) >= 1 && speed >= 1) {
  2182. apply(`transform ${speed}ms ${options.easing}`);
  2183. Move.translate(destination, true);
  2184. endCallback = done;
  2185. } else {
  2186. Move.jump(index);
  2187. done();
  2188. }
  2189. }
  2190. function cancel() {
  2191. apply("");
  2192. }
  2193. function getSpeed(index) {
  2194. const { rewindSpeed } = options;
  2195. if (Splide2.is(SLIDE) && rewindSpeed) {
  2196. const prev = Controller.getIndex(true);
  2197. const end = Controller.getEnd();
  2198. if (prev === 0 && index >= end || prev >= end && index === 0) {
  2199. return rewindSpeed;
  2200. }
  2201. }
  2202. return options.speed;
  2203. }
  2204. function apply(transition) {
  2205. style(list, "transition", transition);
  2206. }
  2207. return {
  2208. mount,
  2209. start,
  2210. cancel
  2211. };
  2212. }
  2213. const _Splide = class {
  2214. constructor(target, options) {
  2215. this.event = EventBus();
  2216. this.Components = {};
  2217. this.state = State(CREATED);
  2218. this.splides = [];
  2219. this._options = {};
  2220. this._Extensions = {};
  2221. const root = isString(target) ? query(document, target) : target;
  2222. assert(root, `${root} is invalid.`);
  2223. this.root = root;
  2224. merge(DEFAULTS, _Splide.defaults);
  2225. merge(merge(this._options, DEFAULTS), options || {});
  2226. }
  2227. mount(Extensions, Transition) {
  2228. const { state, Components: Components2 } = this;
  2229. assert(state.is([CREATED, DESTROYED]), "Already mounted!");
  2230. state.set(CREATED);
  2231. this._Components = Components2;
  2232. this._Transition = Transition || this._Transition || (this.is(FADE) ? Fade : Slide);
  2233. this._Extensions = Extensions || this._Extensions;
  2234. const Constructors = assign({}, ComponentConstructors, this._Extensions, { Transition: this._Transition });
  2235. forOwn(Constructors, (Component, key) => {
  2236. const component = Component(this, Components2, this._options);
  2237. Components2[key] = component;
  2238. component.setup && component.setup();
  2239. });
  2240. forOwn(Components2, (component) => {
  2241. component.mount && component.mount();
  2242. });
  2243. this.emit(EVENT_MOUNTED);
  2244. addClass(this.root, CLASS_INITIALIZED);
  2245. state.set(IDLE);
  2246. this.emit(EVENT_READY);
  2247. return this;
  2248. }
  2249. sync(splide) {
  2250. this.splides.push(splide);
  2251. splide.splides.push(this);
  2252. return this;
  2253. }
  2254. go(control) {
  2255. this._Components.Controller.go(control);
  2256. return this;
  2257. }
  2258. on(events, callback) {
  2259. this.event.on(events, callback, null, DEFAULT_USER_EVENT_PRIORITY);
  2260. return this;
  2261. }
  2262. off(events) {
  2263. this.event.off(events);
  2264. return this;
  2265. }
  2266. emit(event) {
  2267. this.event.emit(event, ...slice(arguments, 1));
  2268. return this;
  2269. }
  2270. add(slides, index) {
  2271. this._Components.Slides.add(slides, index);
  2272. return this;
  2273. }
  2274. remove(matcher) {
  2275. this._Components.Slides.remove(matcher);
  2276. return this;
  2277. }
  2278. is(type) {
  2279. return this._options.type === type;
  2280. }
  2281. refresh() {
  2282. this.emit(EVENT_REFRESH);
  2283. return this;
  2284. }
  2285. destroy(completely = true) {
  2286. const { event, state } = this;
  2287. if (state.is(CREATED)) {
  2288. event.on(EVENT_READY, this.destroy.bind(this, completely), this);
  2289. } else {
  2290. forOwn(this._Components, (component) => {
  2291. component.destroy && component.destroy(completely);
  2292. }, true);
  2293. event.emit(EVENT_DESTROY);
  2294. event.destroy();
  2295. completely && empty(this.splides);
  2296. state.set(DESTROYED);
  2297. }
  2298. return this;
  2299. }
  2300. get options() {
  2301. return this._options;
  2302. }
  2303. set options(options) {
  2304. const { _options } = this;
  2305. merge(_options, options);
  2306. if (!this.state.is(CREATED)) {
  2307. this.emit(EVENT_UPDATED, _options);
  2308. }
  2309. }
  2310. get length() {
  2311. return this._Components.Slides.getLength(true);
  2312. }
  2313. get index() {
  2314. return this._Components.Controller.getIndex();
  2315. }
  2316. };
  2317. let Splide = _Splide;
  2318. Splide.defaults = {};
  2319. Splide.STATES = STATES;
  2320. const CLASS_RENDERED = "is-rendered";
  2321. const RENDERER_DEFAULT_CONFIG = {
  2322. listTag: "ul",
  2323. slideTag: "li"
  2324. };
  2325. class Style {
  2326. constructor(id, options) {
  2327. this.styles = {};
  2328. this.id = id;
  2329. this.options = options;
  2330. }
  2331. rule(selector, prop, value, breakpoint) {
  2332. breakpoint = breakpoint || "default";
  2333. const selectors = this.styles[breakpoint] = this.styles[breakpoint] || {};
  2334. const styles = selectors[selector] = selectors[selector] || {};
  2335. styles[prop] = value;
  2336. }
  2337. build() {
  2338. let css = "";
  2339. if (this.styles.default) {
  2340. css += this.buildSelectors(this.styles.default);
  2341. }
  2342. Object.keys(this.styles).sort((n, m) => this.options.mediaQuery === "min" ? +n - +m : +m - +n).forEach((breakpoint) => {
  2343. if (breakpoint !== "default") {
  2344. css += `@media screen and (max-width: ${breakpoint}px) {`;
  2345. css += this.buildSelectors(this.styles[breakpoint]);
  2346. css += `}`;
  2347. }
  2348. });
  2349. return css;
  2350. }
  2351. buildSelectors(selectors) {
  2352. let css = "";
  2353. forOwn(selectors, (styles, selector) => {
  2354. css += `#${this.id} ${selector} {`;
  2355. forOwn(styles, (value, prop) => {
  2356. if (value || value === 0) {
  2357. css += `${prop}: ${value};`;
  2358. }
  2359. });
  2360. css += "}";
  2361. });
  2362. return css;
  2363. }
  2364. }
  2365. class SplideRenderer {
  2366. constructor(contents, options, config, defaults) {
  2367. this.slides = [];
  2368. this.options = {};
  2369. this.breakpoints = [];
  2370. merge(DEFAULTS, defaults || {});
  2371. merge(merge(this.options, DEFAULTS), options || {});
  2372. this.contents = contents;
  2373. this.config = assign({}, RENDERER_DEFAULT_CONFIG, config || {});
  2374. this.id = this.config.id || uniqueId("splide");
  2375. this.Style = new Style(this.id, this.options);
  2376. this.Direction = Direction(null, null, this.options);
  2377. assert(this.contents.length, "Provide at least 1 content.");
  2378. this.init();
  2379. }
  2380. static clean(splide) {
  2381. const { on } = EventInterface(splide);
  2382. const { root } = splide;
  2383. const clones = queryAll(root, `.${CLASS_CLONE}`);
  2384. on(EVENT_MOUNTED, () => {
  2385. remove(child(root, "style"));
  2386. });
  2387. remove(clones);
  2388. }
  2389. init() {
  2390. this.parseBreakpoints();
  2391. this.initSlides();
  2392. this.registerRootStyles();
  2393. this.registerTrackStyles();
  2394. this.registerSlideStyles();
  2395. this.registerListStyles();
  2396. }
  2397. initSlides() {
  2398. push(this.slides, this.contents.map((content, index) => {
  2399. content = isString(content) ? { html: content } : content;
  2400. content.styles = content.styles || {};
  2401. content.attrs = content.attrs || {};
  2402. this.cover(content);
  2403. const classes = `${this.options.classes.slide} ${index === 0 ? CLASS_ACTIVE : ""}`;
  2404. assign(content.attrs, {
  2405. class: `${classes} ${content.attrs.class || ""}`.trim(),
  2406. style: this.buildStyles(content.styles)
  2407. });
  2408. return content;
  2409. }));
  2410. if (this.isLoop()) {
  2411. this.generateClones(this.slides);
  2412. }
  2413. }
  2414. registerRootStyles() {
  2415. this.breakpoints.forEach(([width, options]) => {
  2416. this.Style.rule(" ", "max-width", unit(options.width), width);
  2417. });
  2418. }
  2419. registerTrackStyles() {
  2420. const { Style: Style2 } = this;
  2421. const selector = `.${CLASS_TRACK}`;
  2422. this.breakpoints.forEach(([width, options]) => {
  2423. Style2.rule(selector, this.resolve("paddingLeft"), this.cssPadding(options, false), width);
  2424. Style2.rule(selector, this.resolve("paddingRight"), this.cssPadding(options, true), width);
  2425. Style2.rule(selector, "height", this.cssTrackHeight(options), width);
  2426. });
  2427. }
  2428. registerListStyles() {
  2429. const { Style: Style2 } = this;
  2430. const selector = `.${CLASS_LIST}`;
  2431. this.breakpoints.forEach(([width, options]) => {
  2432. Style2.rule(selector, "transform", this.buildTranslate(options), width);
  2433. });
  2434. }
  2435. registerSlideStyles() {
  2436. const { Style: Style2 } = this;
  2437. const selector = `.${CLASS_SLIDE}`;
  2438. this.breakpoints.forEach(([width, options]) => {
  2439. Style2.rule(selector, "width", this.cssSlideWidth(options), width);
  2440. Style2.rule(selector, this.resolve("marginRight"), unit(options.gap) || "0px", width);
  2441. const height = this.cssSlideHeight(options);
  2442. if (height) {
  2443. Style2.rule(selector, "height", height, width);
  2444. } else {
  2445. Style2.rule(selector, "padding-top", this.cssSlidePadding(options), width);
  2446. }
  2447. Style2.rule(`${selector} > img`, "display", options.cover ? "none" : "inline", width);
  2448. });
  2449. }
  2450. buildTranslate(options) {
  2451. const { resolve, orient } = this.Direction;
  2452. const values = [];
  2453. values.push(this.cssOffsetClones(options));
  2454. values.push(this.cssOffsetGaps(options));
  2455. if (this.isCenter(options)) {
  2456. values.push(this.buildCssValue(orient(-50), "%"));
  2457. values.push(...this.cssOffsetCenter(options));
  2458. }
  2459. return values.filter(Boolean).map((value) => `translate${resolve("X")}(${value})`).join(" ");
  2460. }
  2461. cssOffsetClones(options) {
  2462. const { resolve, orient } = this.Direction;
  2463. const cloneCount = this.getCloneCount();
  2464. if (this.isFixedWidth(options)) {
  2465. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2466. return this.buildCssValue(orient(value) * cloneCount, unit2);
  2467. }
  2468. const percent = 100 * cloneCount / options.perPage;
  2469. return `${orient(percent)}%`;
  2470. }
  2471. cssOffsetCenter(options) {
  2472. const { resolve, orient } = this.Direction;
  2473. if (this.isFixedWidth(options)) {
  2474. const { value, unit: unit2 } = this.parseCssValue(options[resolve("fixedWidth")]);
  2475. return [this.buildCssValue(orient(value / 2), unit2)];
  2476. }
  2477. const values = [];
  2478. const { perPage, gap } = options;
  2479. values.push(`${orient(50 / perPage)}%`);
  2480. if (gap) {
  2481. const { value, unit: unit2 } = this.parseCssValue(gap);
  2482. const gapOffset = (value / perPage - value) / 2;
  2483. values.push(this.buildCssValue(orient(gapOffset), unit2));
  2484. }
  2485. return values;
  2486. }
  2487. cssOffsetGaps(options) {
  2488. const cloneCount = this.getCloneCount();
  2489. if (cloneCount && options.gap) {
  2490. const { orient } = this.Direction;
  2491. const { value, unit: unit2 } = this.parseCssValue(options.gap);
  2492. if (this.isFixedWidth(options)) {
  2493. return this.buildCssValue(orient(value * cloneCount), unit2);
  2494. }
  2495. const { perPage } = options;
  2496. const gaps = cloneCount / perPage;
  2497. return this.buildCssValue(orient(gaps * value), unit2);
  2498. }
  2499. return "";
  2500. }
  2501. resolve(prop) {
  2502. return camelToKebab(this.Direction.resolve(prop));
  2503. }
  2504. cssPadding(options, right) {
  2505. const { padding } = options;
  2506. const prop = this.Direction.resolve(right ? "right" : "left", true);
  2507. return padding && unit(padding[prop] || (isObject(padding) ? 0 : padding)) || "0px";
  2508. }
  2509. cssTrackHeight(options) {
  2510. let height = "";
  2511. if (this.isVertical()) {
  2512. height = this.cssHeight(options);
  2513. assert(height, '"height" is missing.');
  2514. height = `calc(${height} - ${this.cssPadding(options, false)} - ${this.cssPadding(options, true)})`;
  2515. }
  2516. return height;
  2517. }
  2518. cssHeight(options) {
  2519. return unit(options.height);
  2520. }
  2521. cssSlideWidth(options) {
  2522. return options.autoWidth ? "" : unit(options.fixedWidth) || (this.isVertical() ? "" : this.cssSlideSize(options));
  2523. }
  2524. cssSlideHeight(options) {
  2525. return unit(options.fixedHeight) || (this.isVertical() ? options.autoHeight ? "" : this.cssSlideSize(options) : this.cssHeight(options));
  2526. }
  2527. cssSlideSize(options) {
  2528. const gap = unit(options.gap);
  2529. return `calc((100%${gap && ` + ${gap}`})/${options.perPage || 1}${gap && ` - ${gap}`})`;
  2530. }
  2531. cssSlidePadding(options) {
  2532. const { heightRatio } = options;
  2533. return heightRatio ? `${heightRatio * 100}%` : "";
  2534. }
  2535. buildCssValue(value, unit2) {
  2536. return `${value}${unit2}`;
  2537. }
  2538. parseCssValue(value) {
  2539. if (isString(value)) {
  2540. const number = parseFloat(value) || 0;
  2541. const unit2 = value.replace(/\d*(\.\d*)?/, "") || "px";
  2542. return { value: number, unit: unit2 };
  2543. }
  2544. return { value, unit: "px" };
  2545. }
  2546. parseBreakpoints() {
  2547. const { breakpoints } = this.options;
  2548. this.breakpoints.push(["default", this.options]);
  2549. if (breakpoints) {
  2550. forOwn(breakpoints, (options, width) => {
  2551. this.breakpoints.push([width, merge(merge({}, this.options), options)]);
  2552. });
  2553. }
  2554. }
  2555. isFixedWidth(options) {
  2556. return !!options[this.Direction.resolve("fixedWidth")];
  2557. }
  2558. isLoop() {
  2559. return this.options.type === LOOP;
  2560. }
  2561. isCenter(options) {
  2562. if (options.focus === "center") {
  2563. if (this.isLoop()) {
  2564. return true;
  2565. }
  2566. if (this.options.type === SLIDE) {
  2567. return !this.options.trimSpace;
  2568. }
  2569. }
  2570. return false;
  2571. }
  2572. isVertical() {
  2573. return this.options.direction === TTB;
  2574. }
  2575. buildClasses() {
  2576. const { options } = this;
  2577. return [
  2578. CLASS_ROOT,
  2579. `${CLASS_ROOT}--${options.type}`,
  2580. `${CLASS_ROOT}--${options.direction}`,
  2581. options.drag && `${CLASS_ROOT}--draggable`,
  2582. options.isNavigation && `${CLASS_ROOT}--nav`,
  2583. CLASS_ACTIVE,
  2584. !this.config.hidden && CLASS_RENDERED
  2585. ].filter(Boolean).join(" ");
  2586. }
  2587. buildAttrs(attrs) {
  2588. let attr = "";
  2589. forOwn(attrs, (value, key) => {
  2590. attr += value ? ` ${camelToKebab(key)}="${value}"` : "";
  2591. });
  2592. return attr.trim();
  2593. }
  2594. buildStyles(styles) {
  2595. let style = "";
  2596. forOwn(styles, (value, key) => {
  2597. style += ` ${camelToKebab(key)}:${value};`;
  2598. });
  2599. return style.trim();
  2600. }
  2601. renderSlides() {
  2602. const { slideTag: tag } = this.config;
  2603. return this.slides.map((content) => {
  2604. return `<${tag} ${this.buildAttrs(content.attrs)}>${content.html || ""}</${tag}>`;
  2605. }).join("");
  2606. }
  2607. cover(content) {
  2608. const { styles, html = "" } = content;
  2609. if (this.options.cover && !this.options.lazyLoad) {
  2610. const src = html.match(/<img.*?src\s*=\s*(['"])(.+?)\1.*?>/);
  2611. if (src && src[2]) {
  2612. styles.background = `center/cover no-repeat url('${src[2]}')`;
  2613. }
  2614. }
  2615. }
  2616. generateClones(contents) {
  2617. const { classes } = this.options;
  2618. const count = this.getCloneCount();
  2619. const slides = contents.slice();
  2620. while (slides.length < count) {
  2621. push(slides, slides);
  2622. }
  2623. push(slides.slice(-count).reverse(), slides.slice(0, count)).forEach((content, index) => {
  2624. const attrs = assign({}, content.attrs, { class: `${content.attrs.class} ${classes.clone}` });
  2625. const clone = assign({}, content, { attrs });
  2626. index < count ? contents.unshift(clone) : contents.push(clone);
  2627. });
  2628. }
  2629. getCloneCount() {
  2630. if (this.isLoop()) {
  2631. const { options } = this;
  2632. if (options.clones) {
  2633. return options.clones;
  2634. }
  2635. const perPage = max(...this.breakpoints.map(([, options2]) => options2.perPage));
  2636. return perPage * ((options.flickMaxPages || 1) + 1);
  2637. }
  2638. return 0;
  2639. }
  2640. renderArrows() {
  2641. let html = "";
  2642. html += `<div class="${this.options.classes.arrows}">`;
  2643. html += this.renderArrow(true);
  2644. html += this.renderArrow(false);
  2645. html += `</div>`;
  2646. return html;
  2647. }
  2648. renderArrow(prev) {
  2649. const { classes, i18n } = this.options;
  2650. const attrs = {
  2651. class: `${classes.arrow} ${prev ? classes.prev : classes.next}`,
  2652. type: "button",
  2653. ariaLabel: prev ? i18n.prev : i18n.next
  2654. };
  2655. 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>`;
  2656. }
  2657. html() {
  2658. const { rootClass, listTag, arrows, beforeTrack, afterTrack, slider, beforeSlider, afterSlider } = this.config;
  2659. let html = "";
  2660. html += `<div id="${this.id}" class="${this.buildClasses()} ${rootClass || ""}">`;
  2661. html += `<style>${this.Style.build()}</style>`;
  2662. if (slider) {
  2663. html += beforeSlider || "";
  2664. html += `<div class="splide__slider">`;
  2665. }
  2666. html += beforeTrack || "";
  2667. if (arrows) {
  2668. html += this.renderArrows();
  2669. }
  2670. html += `<div class="splide__track">`;
  2671. html += `<${listTag} class="splide__list">`;
  2672. html += this.renderSlides();
  2673. html += `</${listTag}>`;
  2674. html += `</div>`;
  2675. html += afterTrack || "";
  2676. if (slider) {
  2677. html += `</div>`;
  2678. html += afterSlider || "";
  2679. }
  2680. html += `</div>`;
  2681. return html;
  2682. }
  2683. }
  2684. 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 };