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

@papit/table-of-content

v0.0.5

Published

A page-aware table of contents that builds a tree from the page's headings and highlights the ones currently in view. Clicking an item jumps to its section via the URL hash.

Readme

@papit/table-of-content

A page-aware table of contents that builds a tree from the page's headings and highlights the ones currently in view. Clicking an item jumps to its section via the URL hash.

Logo


Type Tests NPM version


Installation

npm install @papit/table-of-content

HTML

<script type="module" defer>
  import "@papit/table-of-content";
</script>

<pap-table-of-content></pap-table-of-content>

JavaScript / TypeScript

import "@papit/table-of-content";

Usage

Place <pap-table-of-content> anywhere on the page. By default it scans the root node (document or shadow root) for all heading elements and role="heading" elements, excluding those with aria-hidden or data-skipped.

<pap-table-of-content></pap-table-of-content>

<main>
  <h1>Introduction</h1>
  <h2>Getting started</h2>
  <h3>Prerequisites</h3>
  <h2>API reference</h2>
</main>

As the user scrolls, the items corresponding to visible headings receive the marked class and the host gains the :state(scrolling) custom state.

Custom query

Override which elements are observed by setting the query attribute or property:

<!-- Only observe h2 and h3 -->
<pap-table-of-content query="h2, h3"></pap-table-of-content>

Icons

Add a data-icon attribute to a heading to render a pap-icon beside its label in the tree:

<h2 data-icon="star">Highlights</h2>

Reading the active set

const toc = document.querySelector("pap-table-of-content");
toc.addEventListener("change", () => {
  console.log(toc.value); // [{ href: '#...', name: '...' }, ...]
});

Properties

| Property | Attribute | Type | Default | Description | | -------- | --------- | ---------------------------------- | --------------------- | --------------------------------------------------------------------- | | query | query | string | All heading selectors | CSS selector used to discover headings. Reflected from the attribute. | | links | — | Link[] | [] | Internal list of discovered links; not reflected. | | value | — | { href: string; name: string }[] | — | Read-only. Returns the subset of links currently marked as visible. |


Events

| Event | Detail | Description | | -------- | ------ | ---------------------------------------------------------------------------------------- | | change | — | Fired whenever the set of visible headings changes (throttled via IntersectionObserver). |


CSS Parts

| Part | Element | Description | | -------- | -------------------- | --------------------------------- | | tree | pap-treeview | The root tree element. | | item | pap-treeitem | Each individual tree item. | | anchor | <a> inside an item | The anchor link inside each item. |


Custom States

| State | Description | | ------------------- | --------------------------------------------------------------------------- | | :state(scrolling) | Present while the page is scrolling; removed ~500 ms after scrolling stops. | | :state(active) | Present while the inner pap-treeview is focused / active. |


License

Licensed under the @Papit License 1.0 — Copyright (c) 2024 Henry Pap (@onkelhoy)

Key points:

  • ✅ Free to use in commercial projects
  • ✅ Free to modify and distribute
  • ✅ Attribution required
  • ❌ Cannot resell the component itself as a standalone product

See the LICENSE file for full details.


Related packages