UNPKG

@anoki/fse-ui

Version:

FSE UI components library

244 lines (243 loc) • 7.55 kB
import a, { forwardRef as W, useState as P, useRef as u, useEffect as _, createContext as q, useLayoutEffect as Q } from "react"; import { S as X } from "./index.es464.js"; import { g as Y, m as Z, a as ee, u as re } from "./index.es465.js"; import { d as D, w as te, n as ne, b as se, a as ae, e as V, u as ie } from "./index.es466.js"; function k() { return k = Object.assign ? Object.assign.bind() : function(n) { for (var r = 1; r < arguments.length; r++) { var s = arguments[r]; for (var t in s) Object.prototype.hasOwnProperty.call(s, t) && (n[t] = s[t]); } return n; }, k.apply(this, arguments); } function H(n) { return n.type && n.type.displayName && n.type.displayName.includes("SwiperSlide"); } function U(n) { const r = []; return a.Children.toArray(n).forEach((s) => { H(s) ? r.push(s) : s.props && s.props.children && U(s.props.children).forEach((t) => r.push(t)); }), r; } function oe(n) { const r = [], s = { "container-start": [], "container-end": [], "wrapper-start": [], "wrapper-end": [] }; return a.Children.toArray(n).forEach((t) => { if (H(t)) r.push(t); else if (t.props && t.props.slot && s[t.props.slot]) s[t.props.slot].push(t); else if (t.props && t.props.children) { const p = U(t.props.children); p.length > 0 ? p.forEach((l) => r.push(l)) : s["container-end"].push(t); } else s["container-end"].push(t); }), { slides: r, slots: s }; } function le(n, r, s) { if (!s) return null; const t = (o) => { let i = o; return o < 0 ? i = r.length + o : i >= r.length && (i = i - r.length), i; }, p = n.isHorizontal() ? { [n.rtlTranslate ? "right" : "left"]: `${s.offset}px` } : { top: `${s.offset}px` }, { from: l, to: d } = s, S = n.params.loop ? -r.length : 0, h = n.params.loop ? r.length * 2 : r.length, g = []; for (let o = S; o < h; o += 1) o >= l && o <= d && g.push(r[t(o)]); return g.map((o, i) => /* @__PURE__ */ a.cloneElement(o, { swiper: n, style: p, key: o.props.virtualIndex || o.key || `slide-${i}` })); } function O(n, r) { return typeof window > "u" ? _(n, r) : Q(n, r); } const F = /* @__PURE__ */ q(null), ce = /* @__PURE__ */ q(null), ue = /* @__PURE__ */ W(function(n, r) { let { className: s, tag: t = "div", wrapperTag: p = "div", children: l, onSwiper: d, ...S } = n === void 0 ? {} : n, h = !1; const [g, o] = P("swiper"), [i, m] = P(null), [C, R] = P(!1), z = u(!1), w = u(null), e = u(null), x = u(null), $ = u(null), I = u(null), b = u(null), N = u(null), L = u(null), { params: f, passedParams: T, rest: G, events: v } = Y(S), { slides: y, slots: j } = oe(l), B = () => { R(!C); }; Object.assign(f.on, { _containerClasses(c, E) { o(E); } }); const A = () => { Object.assign(f.on, v), h = !0; const c = { ...f }; if (delete c.wrapperClass, e.current = new X(c), e.current.virtual && e.current.params.virtual.enabled) { e.current.virtual.slides = y; const E = { cache: !1, slides: y, renderExternal: m, renderExternalUpdate: !1 }; V(e.current.params.virtual, E), V(e.current.originalParams.virtual, E); } }; w.current || A(), e.current && e.current.on("_beforeBreakpoint", B); const J = () => { h || !v || !e.current || Object.keys(v).forEach((c) => { e.current.on(c, v[c]); }); }, K = () => { !v || !e.current || Object.keys(v).forEach((c) => { e.current.off(c, v[c]); }); }; _(() => () => { e.current && e.current.off("_beforeBreakpoint", B); }), _(() => { !z.current && e.current && (e.current.emitSlidesClasses(), z.current = !0); }), O(() => { if (r && (r.current = w.current), !!w.current) return e.current.destroyed && A(), Z({ el: w.current, nextEl: I.current, prevEl: b.current, paginationEl: N.current, scrollbarEl: L.current, swiper: e.current }, f), d && !e.current.destroyed && d(e.current), () => { e.current && !e.current.destroyed && e.current.destroy(!0, !1); }; }, []), O(() => { J(); const c = ee(T, x.current, y, $.current, (E) => E.key); return x.current = T, $.current = y, c.length && e.current && !e.current.destroyed && ie({ swiper: e.current, slides: y, passedParams: T, changedParams: c, nextEl: I.current, prevEl: b.current, scrollbarEl: L.current, paginationEl: N.current }), () => { K(); }; }), O(() => { re(e.current); }, [i]); function M() { return f.virtual ? le(e.current, y, i) : y.map((c, E) => /* @__PURE__ */ a.cloneElement(c, { swiper: e.current, swiperSlideIndex: E })); } return /* @__PURE__ */ a.createElement(t, k({ ref: w, className: D(`${g}${s ? ` ${s}` : ""}`) }, G), /* @__PURE__ */ a.createElement(ce.Provider, { value: e.current }, j["container-start"], /* @__PURE__ */ a.createElement(p, { className: te(f.wrapperClass) }, j["wrapper-start"], M(), j["wrapper-end"]), ne(f) && /* @__PURE__ */ a.createElement(a.Fragment, null, /* @__PURE__ */ a.createElement("div", { ref: b, className: "swiper-button-prev" }), /* @__PURE__ */ a.createElement("div", { ref: I, className: "swiper-button-next" })), se(f) && /* @__PURE__ */ a.createElement("div", { ref: L, className: "swiper-scrollbar" }), ae(f) && /* @__PURE__ */ a.createElement("div", { ref: N, className: "swiper-pagination" }), j["container-end"])); }); ue.displayName = "Swiper"; const pe = /* @__PURE__ */ W(function(n, r) { let { tag: s = "div", children: t, className: p = "", swiper: l, zoom: d, lazy: S, virtualIndex: h, swiperSlideIndex: g, ...o } = n === void 0 ? {} : n; const i = u(null), [m, C] = P("swiper-slide"), [R, z] = P(!1); function w(I, b, N) { b === i.current && C(N); } O(() => { if (typeof g < "u" && (i.current.swiperSlideIndex = g), r && (r.current = i.current), !(!i.current || !l)) { if (l.destroyed) { m !== "swiper-slide" && C("swiper-slide"); return; } return l.on("_slideClass", w), () => { l && l.off("_slideClass", w); }; } }), O(() => { l && i.current && !l.destroyed && C(l.getSlideClasses(i.current)); }, [l]); const e = { isActive: m.indexOf("swiper-slide-active") >= 0, isVisible: m.indexOf("swiper-slide-visible") >= 0, isPrev: m.indexOf("swiper-slide-prev") >= 0, isNext: m.indexOf("swiper-slide-next") >= 0 }, x = () => typeof t == "function" ? t(e) : t, $ = () => { z(!0); }; return /* @__PURE__ */ a.createElement(s, k({ ref: i, className: D(`${m}${p ? ` ${p}` : ""}`), "data-swiper-slide-index": h, onLoad: $ }, o), d && /* @__PURE__ */ a.createElement(F.Provider, { value: e }, /* @__PURE__ */ a.createElement("div", { className: "swiper-zoom-container", "data-swiper-zoom": typeof d == "number" ? d : void 0 }, x(), S && !R && /* @__PURE__ */ a.createElement("div", { className: "swiper-lazy-preloader" }))), !d && /* @__PURE__ */ a.createElement(F.Provider, { value: e }, x(), S && !R && /* @__PURE__ */ a.createElement("div", { className: "swiper-lazy-preloader" }))); }); pe.displayName = "SwiperSlide"; export { ue as Swiper, pe as SwiperSlide }; //# sourceMappingURL=index.es262.js.map