@indielayer/ui
Version:
Indielayer UI Components with Tailwind CSS build for Vue 3
41 lines (40 loc) • 979 B
JavaScript
import { getEstimatedSize as o } from "./getEstimatedSize.js";
function p({
align: u,
cachedBounds: l,
index: r,
itemCount: a,
itemSize: d,
containerScrollOffset: e,
containerSize: t
}) {
if (r < 0 || r >= a)
throw new RangeError(
`Invalid index specified: ${r}. Index ${r} is not within the range of 0 - ${a - 1}`
);
const h = o({
cachedBounds: l,
itemCount: a,
itemSize: d
}), s = l.get(r), m = Math.max(
0,
Math.min(h - t, s.scrollOffset)
), f = Math.max(
0,
s.scrollOffset - t + s.size
);
switch (u === "smart" && (e >= f && e <= m ? u = "auto" : u = "center"), u) {
case "start":
return m;
case "end":
return f;
case "center":
return s.scrollOffset <= t / 2 ? 0 : s.scrollOffset + s.size / 2 >= h - t / 2 ? h - t : s.scrollOffset + s.size / 2 - t / 2;
case "auto":
default:
return e >= f && e <= m ? e : e < f ? f : m;
}
}
export {
p as getOffsetForIndex
};