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

wc-infinite-scroller

v0.0.12

Published

A native web-component implementation of an infinite scroller

Downloads

72

Readme

wc-infinite-scroller

A native Web Component implementation of an infinite scroller with page-based data fetching, LRU caching, and virtual placeholder support.

Installation

npm install wc-infinite-scroller

Usage

As an ES module (recommended)

import { register } from 'wc-infinite-scroller'

register() // registers <infinite-scroller> custom element

Side-effect import (auto-registers on load)

import 'wc-infinite-scroller'

Via <script> tag (UMD)

<script src="node_modules/wc-infinite-scroller/dist/infinite-scroller.umd.cjs"></script>

HTML

<infinite-scroller id="scroller"></infinite-scroller>

JavaScript

const scroller = document.getElementById('scroller')

scroller.fetchPage = async (page) => {
  const res = await fetch(`/api/items?page=${page}`)
  const data = await res.json()
  return {
    items: data.items,
    currentPage: page,
    totalPages: data.totalPages,
  }
}

scroller.renderItem = (item) => {
  const el = document.createElement('div')
  el.textContent = item.name
  return el
}

scroller.loadInitialPage()

Custom element template

You can provide your own container element instead of the default <ul> list by placing HTML inside the component. The first child element will be used as the scroll container:

<infinite-scroller id="scroller">
  <div class="my-list"></div>
</infinite-scroller>

API

Properties

| Property | Type | Description | | --------------------------- | -------------------------------------------------- | ------------------------------------------------------------------ | | fetchPage | (page: number) => Promise<PageResult<T>> | Required. Called to fetch a page of data. | | renderItem | (item: T) => HTMLElement \| Promise<HTMLElement> | Required. Called to render each data item. | | currentPage | number | Gets or sets the current page (triggers load). | | createPageElement | () => HTMLElement | Optional. Factory for the wrapper element of each page. | | createPlaceholderElements | () => HTMLElement[] | Optional. Factory for placeholder elements shown while loading. | | createErrorElement | (estimatedHeight: number) => HTMLElement | Optional. Factory for the element shown when a page fails to load. |

Methods

| Method | Description | | ------------------- | ----------------------------------------- | | loadInitialPage() | Loads the initial page. Call after setup. |

Attributes

| Attribute | Default | Description | | --------------- | -------------------- | --------------------------------------------------- | | current-page | 1 | Initial page to load. | | preload-pages | 2 | Number of pages to preload around the current page. | | cache-size | preload-pages * 10 | Minimum LRU cache size. |

Events

| Event | Detail | Description | | ---------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | page-changed | { page: number, previousPage: number } | Fired when the visible page changes during scrolling. | | pages-fetched | { pages: { pageNum: number, pageResult: PageResult<T> \| null }[], mainPage: number } | Fired after a batch of pages is fetched. | | item-element-removed | Element | Fired when a rendered item element is removed from the DOM. |

TypeScript

Types are bundled. The InfiniteScroller class is generic:

import {
  InfiniteScroller,
  register,
  type PageResult,
  type PageChangedEvent,
  type PagesFetchedEvent,
  type ItemElementRemovedEvent,
} from 'wc-infinite-scroller'

interface MyItem {
  id: number
  name: string
}

const scroller = document.querySelector(
  'infinite-scroller'
) as InfiniteScroller<MyItem>

scroller.addEventListener('pages-fetched', (e) => {
  const event = e as PagesFetchedEvent<MyItem>
  console.log('fetched pages', event.detail?.pages)
})

License

MIT