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

@huekit/contrast

v1.0.0

Published

WCAG & APCA contrast ratios for hex and OKLCH colors, plus readableOn, isReadable and score helpers. Part of huekit, the OKLCH toolkit for designers.

Readme

@huekit/contrast

WCAG & APCA contrast for hex and OKLCH colors, with readability helpers. Zero dependencies. Part of huekit, the OKLCH toolkit for designers.

import { contrast, readableOn, isReadable, score } from '@huekit/contrast'

contrast('#ffffff', '#3b82f6')              // → 3.68   (WCAG ratio)
contrast('#ffffff', '#3b82f6', { algorithm: 'apca' }) // → -66.4 (APCA Lc)
readableOn('#1e40af')                       // → '#ffffff'
isReadable('#ffffff', '#1e40af')            // → true
score('#ffffff', '#3b82f6')                 // → 'AA Large'

Why a contrast tool that speaks OKLCH?

Accessibility checks are usually bolted onto hex workflows as an afterthought. But if you're building palettes in OKLCH — where lightness is an explicit, controllable channel — contrast becomes something you can reason about and adjust directly.

@huekit/contrast accepts both hex strings and OKLCH objects, so it drops into either workflow. It ships the classic WCAG 2.x ratio everyone knows, plus the newer APCA algorithm for when you need perceptually accurate results, plus the helpers you actually reach for: pick a readable text color, check pass/fail, or grade a pair.

Install

npm install @huekit/contrast

API

contrast(a, b, options?)

Returns the contrast between two colors. Inputs can be hex strings or { l, c, h } objects.

  • WCAG (default): a ratio from 1 (none) to 21 (black on white). 4.5:1 is the AA threshold for normal text.
  • APCA ({ algorithm: 'apca' }): a signed Lc value (roughly -108 to 106). Positive = dark text on light background; negative = light on dark. Use Math.abs() for thresholding.
contrast('#000000', '#ffffff')                          // → 21
contrast({ l: 0.2, c: 0.1, h: 260 }, '#ffffff')         // → 12.4
contrast('#ffffff', '#000000', { algorithm: 'apca' })   // → -107.9

readableOn(bg)

Returns '#000000' or '#ffffff' — whichever has better contrast on the given background.

readableOn('#1e40af')  // → '#ffffff'  (black wins on lighter blues like #3b82f6)
readableOn('#fde047')  // → '#000000'

isReadable(a, b, options?)

Boolean pass/fail against a WCAG level. Options: level ('AA' default, or 'AAA') and large (true for large-text thresholds).

isReadable('#ffffff', '#3b82f6')                  // → false (3.68 < 4.5)
isReadable('#ffffff', '#3b82f6', { large: true }) // → true  (3.68 ≥ 3)
isReadable('#ffffff', '#1e40af', { level: 'AAA' })// → true

| Level | Normal text | Large text | |-------|-------------|------------| | AA | 4.5:1 | 3:1 | | AAA | 7:1 | 4.5:1 |

score(a, b)

Grades a pair for normal-text use: 'AAA', 'AA', 'AA Large', or 'Fail'.

score('#ffffff', '#1e40af')  // → 'AAA'
score('#ffffff', '#3b82f6')  // → 'AA Large'
score('#ffffff', '#fde047')  // → 'Fail'

Pairs with the rest of huekit

import { scale } from '@huekit/scale'
import { readableOn } from '@huekit/contrast'

// Generate a scale, then auto-pick readable text for each step
const palette = scale('#3b82f6')
const labels = Object.fromEntries(
  Object.entries(palette).map(([stop, color]) => [stop, readableOn(color)])
)

The huekit suite

| Package | What it does | |---------|--------------| | @huekit/hex | hex → oklch() conversion | | @huekit/scale | perceptual lightness scale from one color | | @huekit/contrast ← you are here | WCAG & APCA contrast + readability helpers | | @huekit/mix | blend OKLCH colors, no muddy midpoint (soon) | | @huekit/tailwind | brand hex → Tailwind v4 @theme block (soon) | | @huekit/tokens | design tokens → CSS custom properties (soon) |

Note on APCA

APCA is the candidate contrast method for WCAG 3. This package implements the core APCA-W3 0.1.9 lightness-contrast formula for convenience. For formal conformance testing, refer to the official APCA tooling.

License

MIT