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

swatchbook

v0.1.0

Published

A zero-dependency <swatch-book> web component that presents design variants one at a time as a carousel. Drop in a script, wrap your candidate designs, flip between them — perfect for reviewing block/section design options.

Downloads

119

Readme

swatchbook

npm license zero dependencies

A tiny (~2 kB, zero-dependency) <swatch-book> web component that presents design variants one at a time as a carousel, instead of stacking them down the page. Drop in one script, wrap your candidate designs, and flip between them with arrows, dots, or the keyboard.

It's built for reviewing block/section design options — put two or three candidate heroes (or pricing tables, or CTAs) side-by-side-in-time and click through them. Because it's a plain custom element, it works in any stack: Astro, React, Vue, Svelte, or hand-written HTML.

<swatch-book label="Hero">
  <section data-swatch="Bold">…candidate A…</section>
  <section data-swatch="Minimal" data-default>…candidate B…</section>
  <section data-swatch="Playful">…candidate C…</section>
</swatch-book>

<script type="module" src="https://unpkg.com/swatchbook"></script>

The whole idea in one line: the script's presence is the switch. Include it and you get a carousel to review options; omit it (e.g. in production) and the book collapses to your chosen default — no trace of the tool.

Install

npm

npm install swatchbook
import "swatchbook";              // registers <swatch-book>
import "swatchbook/css";          // optional script-less fallback (see below)

CDN — no build step, no install:

<script type="module" src="https://unpkg.com/swatchbook"></script>
<link rel="stylesheet" href="https://unpkg.com/swatchbook/swatchbook.css" />

Usage

Wrap your candidates in <swatch-book>. Each direct child with a data-swatch attribute is one swatch; the attribute's value is its display name.

<swatch-book label="Pricing section">
  <div data-swatch="Cards">…</div>
  <div data-swatch="Table" data-default>…</div>
  <div data-swatch="Slider">…</div>
</swatch-book>

That's it. The component renders a small floating control (previous / next, dots, and a Label · Name · 2 / 3 readout), shows one swatch at a time, and remembers your last pick per label.

The two-file model

| File | What it does | When you need it | | --- | --- | --- | | swatchbook.js | Defines <swatch-book> and turns it into a carousel. | Whenever you want the review UI. Its presence is the on/off switch. | | swatchbook.css | A :not(:defined) fallback that shows only the default swatch when the script is absent. | On any page that ships <swatch-book> markup but might load without the script (production, or pre-hydration). Recommended. |

To ship a page without the tool, just don't include the script. With the CSS present, the page renders your data-default swatch as a normal, finished design.

API

<swatch-book> attributes

| Attribute | Description | | --- | --- | | label | Optional heading shown in the control and used as the localStorage key for remembering the active swatch. |

Swatch attributes (on each direct child)

| Attribute | Description | | --- | --- | | data-swatch="Name" | Marks the element as a swatch; the value is its display name. Required on each swatch. | | data-default | Marks the swatch shown first (and the one the fallback CSS keeps). Falls back to the first swatch if omitted. |

Interaction

  • Arrows / dots in the floating control.
  • ← / → when focus is anywhere inside the book.
  • Wrap-around at both ends.
  • Persistence — the active swatch is remembered per label via localStorage.

Events

The element fires a swatchchange event whenever the active swatch changes:

document.querySelector("swatch-book").addEventListener("swatchchange", (e) => {
  console.log(e.detail); // { index: 1, name: "Table" }
});

Styling the control

The control lives in a shadow root, so page CSS can't accidentally break it. To restyle it intentionally, target its part or tweak the fade:

swatch-book::part(chrome) {
  /* your own pill styling */
}
swatch-book {
  --sb-fade: 400ms; /* crossfade duration; 0 to disable */
}

How it works

  • Swatches live in the light DOM, so your app's styles (Tailwind, global CSS, fonts) apply to them exactly as they would in the real page. Only the book's own control lives in a shadow root, so it neither leaks styles onto your page nor inherits them.
  • Only the active swatch is mounted at any moment; the others are detached from the DOM. This is deliberate: components frequently ship global CSS with shared class names, and mounting several candidates at once would let their rules collide. Detaching also fully pauses each inactive swatch's animations and removes it from the tab/focus order. The trade-off is that switching re-mounts a swatch, so its entry animations restart and the transition is a fade-in.

Browser support

Modern evergreen browsers (custom elements v1, shadow DOM, ::part, :has). No IE. No polyfills shipped.

License

MIT © omaro