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

tailwind-hsluv

v0.1.7

Published

HSLuv/HPLuv color space for TailwindCSS

Downloads

24

Readme

HSLuv/HPLuv color space for TailwindCSS

npm downloads Conventional Commitscoverage MIT License

This package is made to experiment with the HSLuv/HPLuv color space which should be better for UI design. It's technically just a helper function which using the hsluv library to generate the color variants for TailwindCSS.

NEW: From 0.1.4 this package is usable as Tailwind CSS plugin.

Why?

Steve Schoger made a beautiful color palette in Tailwind CSS, but:

  • you can't trust in the lightness variations. Even if the colors are hand-picked, if you use bg-blue-300 and bg-yellow-300 the perceived lightness will be different.
  • the steps between the lightness variations sometimes not even

How then?

The difference between HSL and HSLuv/HPLuv/CIELUV color spaces is the lightness value based on the human eye instead of how the monitor mixing the colors. With HSLuv we can generate the color variations based on the perceived lightness.

You can read about these here:

Credits

The HSLuv library made by Alexei Boronine

The Color name list came from the Name that color library

Installation

npm i tailwind-hsluv
# or
yarn add tailwind-hsluv

Color names

The generateColors function accepts colors as string or array:

  • hex color like "#RRGGBB" or "#CCC"
  • named color like "Eastern Blue" or "Seaweed", etc. (1)
  • RGB color array like: [255, 0, 0]

(1) The color name lookup is case-insensitive. You can find the color names in the source or you can pick one via the Name that color website.

Plugin usage

// tailwind.config.js
const { hsluv } = require('tailwind-hsluv');

module.exports = {
    // ...your other config...
    plugins: [
        hsluv({
            superred: '#ff0000', // 6 digit hex color
            grayscale: '#ccc', // / 3 digit hex color
            blue: [ 0, 0, 255 ], // rgb array
            green: 'green', // simple named color
            mypurple: 'Jacksons Purple' // specific named color
        }, {
            step: 50, // default 100
            hpluv: false, // use the HPLuv color space, default: false
        }),
        // ...your other plugins...
    ]
};

Generate colors directly

generateColors(colorMap, options): generates the colors for TailwindCSS.

Options:

| name | default | description | | ----- | ------- | ------------------------------------------ | | step | 100 | steps between the lightness values | | hpluv | false | use the HPLuv color space (less saturated) |

Full example:

// tailwind.config.js
const { generateColors } = require('tailwind-hsluv');

module.exports = {
    theme: {
        extend: {
            colors: generateColors({
                superred: '#ff0000', // 6 digit hex color
                grayscale: '#ccc', /// 3 digit hex color
                blue: [0, 0, 255], // rgb array
                green: 'green', // simple named color
                mypurple: 'Jacksons Purple' // specific named color
            }, {
                step: 100, // steps between lightness variants, default: 100
                hpluv: false // use the HPLuv color space, default: false
            })
        }
    }
};

It will generate an object which usable for tailwind config, like this:

{
    "red": {
        "100": "#FFDADA",
        "200": "#FFB3B3",
        "300": "#FF8888",
        "400": "#FF5353",
        "500": "#EF0000",
        "600": "#C00000",
        "700": "#930000",
        "800": "#690000",
        "900": "#410000",
        "default": "#FF0000"
	},
    "blue": {
        // ...
    },
    // another colors...
}

Comparison between the color palettes

The "text" texts are colored with grayscale hsl(0, 0%, 10%-90%) and each of the boxes have a background color lightness variant from 100 to 900.

If the text lightness is closer to the background color lightness you less likely can see the difference between them.

image-20200925214453451

Changelog

See CHANGELOG.md (since 0.1.4), and CHANGELOG-old.md (before 0.1.4)

License

Copyright © 2020 Kövesdi György

Licensed under the MIT License.