splide.cjs.js 79 KB

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