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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@terrazzo/use-color

v0.0.2

Published

React hook for memoizing and transforming any web-compatible color. Uses Culori.

Downloads

9

Readme

@terrazzo/use-color

React hook for memoizing and transforming any web-compatible color. Only 12 kB (with full support for all web colorspaces!) thanks to Culori.

Setup

pnpm i @terrazzo/use-color
import useColor, { formatCSS } from "@terrazzo/use-color";

const [color, setColor] = useColor("color(srgb 0.0 0.3 1.0)");

// Reading

color.css; // color(srgb 0.0 0.3 1.0)
color.original; // { mode: "srgb", r: 0, g: 0.3, b: 1.0, alpha: 1 }
color.p3; // { mode: "p3", r: 0.1184, g: 0.2956, b: 0.9611 }
formatCSS(color.p3); // color(display-p3 0.1184 0.2956 0.9611)

// Setting color

setColor("color(display-p3 0.12 0.3 0.98)");
setColor({ mode: "p3", r: 0.12, g: 0.3, b: 0.98 });

// Adjusting color relatively (lighten by 10% via Oklab)

setColor({ ...color.original.oklab, l: color.oklab.l + 0.1 });

Reading color

The color is fully memoized, so it can be used in any useEffect() hooks. This uses Culori to convert colors, but only the CSS Color Module 4 colorspaces are loaded. Further, all the properties are getters that cache their output, so even if accessing a different format, work will never be redone. You have the following property available:

| Property | Type | Description | | :------------ | :------- | :---------------------------------------------------------------------------------------------------------- | | css | string | CSS-compatible color using Color Module 4 | | original | object | Culori color object using the original mode of the color (tip: use color.original.mode to see the format) | | a98 | object | Culori A98 color object | | hsl | object | Culori HSL color object | | hsv | object | Culori HSV color object | | lrgb | object | Culori LinearRGB color object | | lab | object | Culori CIELab color object (not to be confused with Oklab) | | lch | object | Culori CIELCh color object (not to be confused with Oklch) | | luv | object | Culori LUV color object | | okhsl | object | Culori Okhsl color object | | okhsv | object | Culori Okhsv color object | | oklab | object | Culori Oklab color object | | oklch | object | Culori Oklch color object | | p3 | object | Culori P3 color object | | prophotoRgb | object | Culori ProPhotoRGB color object | | rec2020 | object | Culori Rec2020 color object | | rgb | object | (sRGB) Culori RGB color object | | srgb | object | (alias of rgb) | | xyz | object | (alias of xyz65) | | xyz50 | object | Culori Xyz50 color object | | xyz65 | object | Culori Xyz65 color object |

Setting color

Setting color can be done by either passing in any valid CSS string:

const [color, setColor] = useColor();

setColor("color(display-p3 0.12 0.3 0.98)");

Or any Culori object:

const [color, setColor] = useColor();

setColor({ mode: "p3", r: 0.12, g: 0.3, b: 0.98 });

Or adjusting the color object relatively (tip: for most purposes, adjusting by oklab will yield the best results):

const [color, setColor] = useColor();

setColor({
  ...color.original.oklab,
  l: color.oklab.l + 0.1, // Lighten by 10% via Oklab
});

Note: if adjusting by a different colorspace, that will affect the color.original and color.css output, which pulls the most-recently-used colorspace.