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

postcss-color-variable-shorthand

v0.1.0

Published

Expand color variables

Downloads

3

Readme

PostCSS color variable shorthand

Introduction

PostCSS plugin that expands color variables to make it quicker to define reusable CSS color variables.

By adding a --hsl or --rgb suffix (See example usage below) to the variable name, this plugin will automatically expand one line of CSS into two. This is useful in case you want to use the same color for hsla().

Usecase

You have defined a bunch of colors in your existig stylesheet, but then later on you want to use the same colors with alpha, or you have just gotten tired of HEX and RGB and want to use HSL instead.

/* Starting point */
--bakground-color: rgb(240, 240, 240);
--text-color: #446677;

/* To get this working _without_ this plugin, you would have to delete most
 * of what you already have, write six new lines of CSS and also figure out
 * what #446677 is in RGB.
 */
--background-color-vars: 240, 240, 240;
--bakground-color: rgb(--background-color-vars);
--bakground-color-alpha: rgba(--background-color-vars, 0.9);
--text-color-vars: 68, 102, 183;
--text-color: rgb(--text-color-vars);
--text-color-alpha: rgba(--text-color-vars, 0.7);

/* To get this working _with_ this plugin, you only need to add "--hsl" at the
 * end of the existing variable names and define the two new "-alpha" colors.
 */
--bakground-color--hsl: rgb(240, 240, 240);
--text-color--hsl: #446677;
--bakground-color-alpha: hsla(--background-color--hsl, 0.9);
--text-color-alpha: hsla(--text-color--hsl, 0.7);

Example

Example input

:root {
  --grey-hue: 205;
  --text-color--hsl: hsl(var(--grey-hue), 20%, 94%);
  --black--hsl: #040404;
}

Example output

:root {
  --grey-hue: 205;
  --text-color--hsl: var(--grey-hue), 20%, 94%;
  --text-color: hsl(var(--text-color--hsl));
  --black--hsl: 0, 0%, 1.569%;
  --black: hsl(var(--black--hsl));
}

Usage

The example usage below will produce the "hsl" output above, but colorSpace can also be "rgb" if you prefer that over "hsl".

import postcssColorVariableShorthand from 'postcss-color-variable-shorthand';

const config = {
  plugins: [
    postcssColorVariableShorthand({colorSpace: 'hsl'}),
  ],
};

export default config;

See PostCSS docs for examples for your environment.


MIT © Jan Henning Thorsen