UNPKG

@indielayer/ui

Version:

Indielayer UI Components with Tailwind CSS build for Vue 3

172 lines (171 loc) 5.01 kB
import { computed as t, isRef as w, ref as b, watch as N } from "vue"; import { useResizeObserver as q, useEventListener as A } from "../../node_modules/.pnpm/@vueuse_core@11.1.0_vue@3.5.10_typescript@5.2.2_/node_modules/@vueuse/core/index.js"; import { parseNumericStyleValue as $ } from "../utils/parseNumericStyleValue.js"; import { adjustScrollOffsetForRtl as V } from "../utils/adjustScrollOffsetForRtl.js"; import { shallowCompare as j } from "../utils/shallowCompare.js"; import { getEstimatedSize as G } from "./getEstimatedSize.js"; import { getOffsetForIndex as J } from "./getOffsetForIndex.js"; import { getStartStopIndices as B } from "./getStartStopIndices.js"; import { useCachedBounds as K } from "./useCachedBounds.js"; import { useItemSize as Q } from "./useItemSize.js"; function ie({ containerElement: u, containerStyle: n, defaultContainerSize: d = 0, direction: i, isRtl: p = !1, itemCount: g, itemProps: x, itemSize: I, onResize: T, overscanCount: z }) { const l = t(() => w(g) ? g.value : g), D = t(() => w(x) ? x.value : x), H = t(() => w(I) ? I.value : I), C = t(() => $(n == null ? void 0 : n.height)), M = t(() => $(n == null ? void 0 : n.width)), f = b({ height: i === "vertical" ? d : void 0, width: i === "horizontal" ? d : void 0 }), R = t( () => i === "vertical" && C.value !== void 0 || i === "horizontal" && M.value !== void 0 ); q( u, (e) => { if (!R.value) for (const s of e) { const { contentRect: a } = s, o = f.value; if (o.height === a.height && o.width === a.width) return; f.value = { height: a.height, width: a.width }; } } ); const O = t(() => ({ height: C.value ?? f.value.height, width: M.value ?? f.value.width })), L = b({ height: 0, width: 0 }); N( O, (e) => { if (typeof T == "function") { const s = L.value, a = e.height ?? 0, o = e.width ?? 0; (s.height !== a || s.width !== o) && (T({ height: a, width: o }, { ...s }), L.value = { height: a, width: o }); } }, { immediate: !0 } ); const h = t( () => i === "vertical" ? O.value.height ?? d : O.value.width ?? d ), S = t( () => Q({ containerSize: h.value, itemSize: H.value }) ), r = t( () => K({ itemCount: l.value, itemProps: D.value, itemSize: S.value }).value ), W = (e) => r.value.get(e), v = b( B({ cachedBounds: r.value, containerScrollOffset: 0, containerSize: h.value, itemCount: l.value, overscanCount: z }) ), m = t(() => { const e = v.value; return { startIndexVisible: Math.min(l.value - 1, e.startIndexVisible), startIndexOverscan: Math.min(l.value - 1, e.startIndexOverscan), stopIndexVisible: Math.min(l.value - 1, e.stopIndexVisible), stopIndexOverscan: Math.min(l.value - 1, e.stopIndexOverscan) }; }), k = t( () => G({ cachedBounds: r.value, itemCount: l.value, itemSize: S.value }) ), E = (e) => { const s = V({ containerElement: u.value, direction: i, isRtl: p, scrollOffset: e }); return B({ cachedBounds: r.value, containerScrollOffset: s, containerSize: h.value, itemCount: l.value, overscanCount: z }); }; return N( [u, () => i, () => r.value], ([e]) => { const s = (i === "vertical" ? e == null ? void 0 : e.scrollTop : e == null ? void 0 : e.scrollLeft) ?? 0; v.value = E(s); }, { immediate: !0 } ), A(u, "scroll", () => { const e = u.value; if (!e) return; const { scrollLeft: s, scrollTop: a } = e, o = V({ containerElement: e, direction: i, isRtl: p, scrollOffset: i === "vertical" ? a : s }), c = B({ cachedBounds: r.value, containerScrollOffset: o, containerSize: h.value, itemCount: l.value, overscanCount: z }); j(c, v.value) || (v.value = c); }), { getCellBounds: W, getEstimatedSize: k, scrollToIndex: ({ align: e = "auto", containerScrollOffset: s, index: a }) => { let o = J({ align: e, cachedBounds: r.value, containerScrollOffset: s, containerSize: h.value, index: a, itemCount: l.value, itemSize: S.value }); const c = u.value; if (c) { if (o = V({ containerElement: c, direction: i, isRtl: p, scrollOffset: o }), typeof c.scrollTo != "function") { const F = E(o); j(v.value, F) || (v.value = F); } return o; } }, startIndexOverscan: t(() => m.value.startIndexOverscan), startIndexVisible: t(() => m.value.startIndexVisible), stopIndexOverscan: t(() => m.value.stopIndexOverscan), stopIndexVisible: t(() => m.value.stopIndexVisible) }; } export { ie as useVirtualizer };