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

@amplib/color

v0.1.0

Published

Color analysis utilities

Readme

@amplib/color

Color analysis utilities.

import { toPerceptual, fromPerceptual } from "@amplib/color";

toPerceptual(210); // 256.22 — display blue is much further round than it looks
fromPerceptual(180); // 172.88 — the display hue that reads as halfway to cyan

Divide a hue wheel into six equal slices in HSV and the slices do not look equal. Divide it in oklch and they do. That is the entire purpose of this package: a bijection between the hue you write down and the hue people see.

// Six hues that actually look evenly spaced.
const spaced = Array.from({ length: 6 }, (_, i) => fromPerceptual(i * 60));
// 328.0, 33.8, 68.9, 172.9, 198.9, 274.6 — not 0, 60, 120, 180, 240, 300

Note where that list starts. Perceptual 0° is display 328°, not 0° — the angle vision reads as the origin of the wheel sits in magenta, some way before display red. The two wheels do not share a zero, so there is no offset you could apply instead of the mapping.

Modules

| Module | Description | | ---------------------- | ---------------------------------------------------- | | toPerceptual | Display (HSV) hue → perceptual (oklch) hue | | fromPerceptual | Perceptual (oklch) hue → display (HSV) hue | | worstRoundTripError | Measured disagreement between the two directions |

Design

The wheel is severely non-linear, and not in the direction most descriptions suggest. Measured as perceptual degrees per display degree:

| red | orange | yellow | green | cyan | blue | deep blue | magenta | | ----- | ------ | ------ | ----- | ----- | ----- | --------- | ------- | | 0.21× | 1.76× | 1.29× | 0.05× | 2.23× | 0.14× | 0.01× | 0.94× |

Green and deep blue barely move — a wide sweep of display hue is almost one perceptual color — while cyan and orange stretch. Over two hundredfold between the extremes.

The round-trip is measured, not assumed. The forward table samples oklch once per display degree; the inverse searches it backwards at twenty times that resolution, because the deep-blue zone squeezes roughly 16 display degrees into half a perceptual degree and would otherwise collapse to a single bin. The two are built by different methods and only approximately invert each other, so worstRoundTripError() measures the disagreement and npm test fails the build above 1.5°.

Raw oklch hue also steps backwards by a fraction of a degree around display 231–240°, which would make the mapping non-invertible exactly there. Every backward run is replaced with a straight interpolation across it.

The error check is exported, not run on import. A library that asserts at load time charges every consumer for the check whether they want it or not, and still cannot fail a build when it matters.

Hue only, saturation and lightness untouched. Full-saturation, full-value HSV is the sampling line, so this answers "which angle" and says nothing about how light or vivid the result is. Anything needing the other two axes wants a full color-space conversion, not this.

Matrix constants from Björn Ottosson's oklab reference implementation (2020).