splide.esm.js 77 KB

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