UNPKG

@indielayer/ui

Version:

Indielayer UI Components with Tailwind CSS build for Vue 3

56 lines (55 loc) 1.13 kB
import { assert as f } from "../utils/assert.js"; function d({ itemCount: u, itemProps: a, itemSize: r }) { const e = /* @__PURE__ */ new Map(); return { get(s) { for (f(s < u, `Invalid index ${s}`); e.size - 1 < s; ) { const t = e.size; let c; switch (typeof r) { case "function": { c = r(t, a); break; } case "number": { c = r; break; } } if (t === 0) e.set(t, { size: c, scrollOffset: 0 }); else { const n = e.get(t - 1); f( n !== void 0, `Unexpected bounds cache miss for index ${s}` ), e.set(t, { scrollOffset: n.scrollOffset + n.size, size: c }); } } const o = e.get(s); return f( o !== void 0, `Unexpected bounds cache miss for index ${s}` ), o; }, set(s, o) { e.set(s, o); }, get size() { return e.size; } }; } export { d as createCachedBounds };