const ROW_HEIGHT = 32;
const VIEWPORT = 480;
const OVERSCAN = 5;
function naiveRange(count, scrollTop) {
const start = Math.max(0, Math.floor(scrollTop / ROW_HEIGHT) - OVERSCAN);
const end = Math.min(count, Math.ceil((scrollTop + VIEWPORT) / ROW_HEIGHT) + OVERSCAN);
return [start, end];
}
function clampedRange(count, scrollTop) {
const maxScrollTop = Math.max(0, count * ROW_HEIGHT - VIEWPORT);
return naiveRange(count, Math.min(scrollTop, maxScrollTop));
}
const scrollTop = 64000;
const [a, b] = naiveRange(20000, scrollTop);
console.log(a, b, b - a);
const [c, d] = naiveRange(30, scrollTop);
console.log(c, d, Math.max(0, d - c), c * ROW_HEIGHT);
const [e, f] = clampedRange(30, scrollTop);
console.log(e, f, f - e, e * ROW_HEIGHT);