splide.cjs.js 83 KB

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