splide.esm.js 79 KB

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