0.2.3 • Published 8 months ago

@wesgro/postcss-migrate-colors-to-vars v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

postcss-migrate-colors-to-vars

Will:

  • find all colors inside of a css file
  • compare them to a Object of css vars, and their values
  • replace the color with the css-var of your choosing based on the nearest delta

Usage

import postcss from "postcss";
import migrateColorsPlugin from "@wesgro/postcss-migrate-colors-to-vars";
import fs from "node:fs";

const COLORS = {
    "--color__selection__base": "#1a1918",
    "--color__selection__base--state-1": "#393633",
    "--color__selection__base--state-2": "#44403d",
}
const input = `
h1{
    color:#1a1914; 
    background-color:#393633; 
    outline: var(--not-me-bro__other__color, #44403d);
}`;

const output = postcss(
  migrateColorsPlugin({
    ignoreRule: (node) => {
      return (
        node.type === "function" &&
        node.nodes.some((node) => node.value.startsWith("--not-me-bro"))
      );
    },

    replacementColors: COLORS,
  })
).process(input).css;
console.log(output)
// 
0.2.3

8 months ago

0.2.3-beta.0

8 months ago

0.2.0

8 months ago

0.1.2

8 months ago

0.1.2-beta.0

8 months ago

0.1.1

8 months ago

0.1.0

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago