npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wentools/virtual-scroll

v0.1.0

Published

Headless virtual scrolling: binary search, offset calculation, and visible range algorithms

Readme

@wentools/virtual-scroll

Headless virtual scrolling primitives: binary search, offset calculation, and visible range algorithms.

Framework-agnostic core — use directly or pair with a framework adapter like @wentools/virtual-scroll-svelte.

Install

# npm
npm install @wentools/virtual-scroll

# Deno / JSR
import { calculateVisibleRange } from "jsr:@wentools/virtual-scroll"

Usage

Calculate Visible Range

Determine which items are visible in a scrollable container:

import { calculateVisibleRange } from '@wentools/virtual-scroll'

const result = calculateVisibleRange(
  1000,                    // total item count
  () => 48,                // estimated height per item
  new Map(),               // measured heights (index → px)
  scrollOffset,            // current scroll position
  containerHeight,         // viewport height
  3,                       // overscan (extra items above/below)
)

// result.items       — visible VirtualItems with { index, start, end, size }
// result.totalSize   — total scrollable height
// result.adjustedScrollOffset — clamped scroll offset

Scroll to Index

Calculate the scroll offset needed to bring a specific item into view:

import { calculateScrollToIndex } from '@wentools/virtual-scroll'

const offset = calculateScrollToIndex(
  42,                      // target index
  'center',                // alignment: 'start' | 'center' | 'end'
  1000,                    // total item count
  () => 48,                // estimated height per item
  measurements,            // measured heights
  containerHeight,         // viewport height
)

Binary Search

General-purpose binary search utilities used internally, also exported for convenience:

import { binarySearch, lowerBound, upperBound, numericCompare } from '@wentools/virtual-scroll'

const sorted = [1, 3, 5, 7, 9]

binarySearch(sorted, 5, numericCompare)  // 2 (exact match index, or -1)
lowerBound(sorted, 4, numericCompare)    // 2 (first index >= target)
upperBound(sorted, 5, numericCompare)    // 3 (first index > target)

API

Types

type VirtualItem = {
  index: number
  start: number
  end: number
  size: number
}

type VirtualizerOptions = {
  count: number
  estimateSize: (index: number) => number
  overscan?: number
}

type ScrollAlignment = 'start' | 'center' | 'end'

type VisibleRangeResult = {
  items: VirtualItem[]
  totalSize: number
  adjustedScrollOffset: number
}

Functions

| Function | Description | |---|---| | calculateVisibleRange | Compute which items fall within the viewport | | calculateScrollToIndex | Compute scroll offset to bring an item into view | | binarySearch | Exact-match binary search, returns index or -1 | | lowerBound | First index where array[i] >= target | | upperBound | First index where array[i] > target | | numericCompare | Standard numeric comparator |

License

MIT