UNPKG

@anoki/fse-ui

Version:

FSE UI components library

129 lines (128 loc) • 4.46 kB
import { c as w } from "./index.es466.js"; import { m as l } from "./index.es467.js"; function N(x) { let { swiper: a, extendParams: C, on: c, emit: g } = x; C({ navigation: { nextEl: null, prevEl: null, hideOnClick: !1, disabledClass: "swiper-button-disabled", hiddenClass: "swiper-button-hidden", lockClass: "swiper-button-lock", navigationDisabledClass: "swiper-navigation-disabled" } }), a.navigation = { nextEl: null, prevEl: null }; function u(i) { let n; return i && typeof i == "string" && a.isElement && (n = a.el.querySelector(i) || a.hostEl.querySelector(i), n) ? n : (i && (typeof i == "string" && (n = [...document.querySelectorAll(i)]), a.params.uniqueNavElements && typeof i == "string" && n && n.length > 1 && a.el.querySelectorAll(i).length === 1 ? n = a.el.querySelector(i) : n && n.length === 1 && (n = n[0])), i && !n ? i : n); } function f(i, n) { const t = a.params.navigation; i = l(i), i.forEach((e) => { e && (e.classList[n ? "add" : "remove"](...t.disabledClass.split(" ")), e.tagName === "BUTTON" && (e.disabled = n), a.params.watchOverflow && a.enabled && e.classList[a.isLocked ? "add" : "remove"](t.lockClass)); }); } function d() { const { nextEl: i, prevEl: n } = a.navigation; if (a.params.loop) { f(n, !1), f(i, !1); return; } f(n, a.isBeginning && !a.params.rewind), f(i, a.isEnd && !a.params.rewind); } function E(i) { i.preventDefault(), !(a.isBeginning && !a.params.loop && !a.params.rewind) && (a.slidePrev(), g("navigationPrev")); } function h(i) { i.preventDefault(), !(a.isEnd && !a.params.loop && !a.params.rewind) && (a.slideNext(), g("navigationNext")); } function v() { const i = a.params.navigation; if (a.params.navigation = w(a, a.originalParams.navigation, a.params.navigation, { nextEl: "swiper-button-next", prevEl: "swiper-button-prev" }), !(i.nextEl || i.prevEl)) return; let n = u(i.nextEl), t = u(i.prevEl); Object.assign(a.navigation, { nextEl: n, prevEl: t }), n = l(n), t = l(t); const e = (s, p) => { s && s.addEventListener("click", p === "next" ? h : E), !a.enabled && s && s.classList.add(...i.lockClass.split(" ")); }; n.forEach((s) => e(s, "next")), t.forEach((s) => e(s, "prev")); } function m() { let { nextEl: i, prevEl: n } = a.navigation; i = l(i), n = l(n); const t = (e, s) => { e.removeEventListener("click", s === "next" ? h : E), e.classList.remove(...a.params.navigation.disabledClass.split(" ")); }; i.forEach((e) => t(e, "next")), n.forEach((e) => t(e, "prev")); } c("init", () => { a.params.navigation.enabled === !1 ? b() : (v(), d()); }), c("toEdge fromEdge lock unlock", () => { d(); }), c("destroy", () => { m(); }), c("enable disable", () => { let { nextEl: i, prevEl: n } = a.navigation; if (i = l(i), n = l(n), a.enabled) { d(); return; } [...i, ...n].filter((t) => !!t).forEach((t) => t.classList.add(a.params.navigation.lockClass)); }), c("click", (i, n) => { let { nextEl: t, prevEl: e } = a.navigation; t = l(t), e = l(e); const s = n.target; let p = e.includes(s) || t.includes(s); if (a.isElement && !p) { const o = n.path || n.composedPath && n.composedPath(); o && (p = o.find((r) => t.includes(r) || e.includes(r))); } if (a.params.navigation.hideOnClick && !p) { if (a.pagination && a.params.pagination && a.params.pagination.clickable && (a.pagination.el === s || a.pagination.el.contains(s))) return; let o; t.length ? o = t[0].classList.contains(a.params.navigation.hiddenClass) : e.length && (o = e[0].classList.contains(a.params.navigation.hiddenClass)), g(o === !0 ? "navigationShow" : "navigationHide"), [...t, ...e].filter((r) => !!r).forEach((r) => r.classList.toggle(a.params.navigation.hiddenClass)); } }); const k = () => { a.el.classList.remove(...a.params.navigation.navigationDisabledClass.split(" ")), v(), d(); }, b = () => { a.el.classList.add(...a.params.navigation.navigationDisabledClass.split(" ")), m(); }; Object.assign(a.navigation, { enable: k, disable: b, update: d, init: v, destroy: m }); } export { N as default }; //# sourceMappingURL=index.es262.js.map