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-css-variables-theme

v0.0.1-beta.4

Published

Just like postcss-css-variables but support multiple theme class

Downloads

3

Readme

postcss-css-variables-theme

npm version Build Status codecov

Just like postcss-css-variables but support multiple theme class postcss-css-variables

Option

{
    /**
     * true: keep variables
     * false(default): not keep & remove variable defination
     * computed: not keep variables but keep variable defination
     * (decl: Node) => boolean | 'computed'
     */
    preserve: false,
    variables: {
        '--main-color': { // theme
            default: 'blue', // default
            light: '#fff', // theme: light
            dark: '#000', // theme: dark
        },
        '--secondary-color': '#aef', // default
    },
    /**
     * prifix of multiple theme selector
     * @param {*} selector
     * @param {*} theme
     * @returns `body.${theme} ${selector}`
     */
    themeSelector: (theme, selector) => `body.${theme} ${selector}`,
    /**
     * true: generate variables defination
     * false(default): do nothing
     */
    preserveInjectedVariables: false,
    /**
     * selector of variables defination
     * @param {*} selector
     * @param {*} theme
     * @returns
     */
    themeDefineSelector: (theme) => {
        if (theme === 'default') return 'body';
        return `body.${theme}`;
    },
};

Generate variables

you can generate variables just by *.css, there is util function can help you theme.css

/**
* write rule
* body.[name] {
*    --[var-name]: [value-name]; 
* }
*/
body {
    --primary-color: #fe3666;
    --primary-bgcolor: #fe366620;
}
body.light {
    --primary-color: #ff4906;
    --primary-bgcolor: #ff490620;
}
body.dark {
    --primary-color: #906000;
    --primary-bgcolor: #90600020;
}
const { readThemeConfig } = require('postcss-css-variables-theme/util');
readThemeConfig(require('path').resolve(__dirname, './theme.css'));
// {
//     '--primary-color': {
//         default: '#fe3666',
//         light: '#ff4906',
//         dark: '#906000',
//     },
//     '--primary-bgcolor': {
//         default: '#fe366620',
//         light: '#ff490620',
//         dark: '#90600020',
//     },
// }

examples

default

option

{
    variables: {
        '--primary-color': '#15c213'
    }
}

ps:

.a {
    color: var(--primary-color);
}
.a {
    color: #15c213;
}

mutiple themes

options

{
    variables: {
        '--primary-color': {
            default: '#15c213',
            light: '#9ae899',
            dark: '#2a562a',
        }
    }
}

ps:

.a {
    color: var(--primary-color);
}
.a {
    color: #15c213;
}
body.light .a {
    color: #9ae899;
}
body.dark .a {
    color: #2a562a;
}

preserve: true

option

{
    preserve: true,
    variables: {
        '--primary-color': '#15c213'
    }
)

ps:

:root {
    --primary-color: blue;
}
.a {
    color: var(--primary-color);
}
:root {
    --primary-color: blue;
}
.a {
    color: #15c213;
    color: var(--primary-color);
}

preserve: false

option

{
    preserve: false,
    variables: {
        '--primary-color': '#15c213'
    }
}

ps:

:root {
    --primary-color: blue;
}
.a {
    color: var(--primary-color);
}
.a {
    color: #15c213;
}

preserve: computed

option

{
    preserve: 'computed',
    variables: {
        '--primary-color': '#15c213'
    }
}

ps:

:root {
    --primary-color: blue;
}
.a {
    color: var(--primary-color);
}
:root {
    --primary-color: blue;
}
.a {
    color: #15c213;
}

preserve: function

option

{
    preserve: (node) =>
        node.prop === '--primary-color' ||
        node.value.includes('--primary-color')
        ? true
        : false,
    variables: {
        '--primary-color': '#15c213',
        '--secondary-color': '#15c'
    }
}

ps:

:root {
    --primary-color: blue;
    --secondary-color: red;
}
.a {
    color: var(--primary-color);
    background-color: var(--secondary-color);
}
:root {
    --primary-color: blue;
}
.a {
    color: #15c213;
    color: var(--primary-color);
    background-color: #15c;
}

themeSelector

option

{
    themeSelector: (theme, selector) => `.custom-${theme} ${selector}`,
    variables: {
        '--primary-color': {
            default: '#15c213',
            light: '#15c',
        }
    }
}

ps:

.a {
    color: var(--primary-color);
}
.a {
    color: #15c213;
}
.custom-light .a {
    color: #15c;
}

preserveInjectedVariables

option

{
    preserveInjectedVariables: true,
    variables: {
        '--primary-color': '#15c213'
    }
}

ps:

.a {
    color: var(--primary-color);
}
body {
    --primary-color: #15c213;
}
.a {
    color: #15c213;
}

themeDefineSelector (preserveInjectedVariables must be true)

option

{
    preserveInjectedVariables: true,
    themeDefineSelector: (theme) => {
        if (theme === 'default') return 'body';
        return `body[${theme}]`;
    },
    variables: {
        '--primary-color': {
            default: '#15c213',
            light: '#15c',
        },
    },
}

ps:

.a {
    color: var(--primary-color);
}
body[light] {
    --primary-color: #15c;
}
body {
    --primary-color: #15c213;
}
.a {
    color: #15c213;
}
body.light .a {
    color: #15c;
}