splide.cjs.js 80 KB

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