Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tuxado/postcss-color-transformer

Repository files navigation

PostCSS Color Converter

A PostCSS plugin for converting between different color formats.

Features

  • Explicit conversion between color formats with intuitive syntax
  • Supports RGB, RGBA, HSL, HSLA, OKLCH, LAB, LCH, HWB, HSV, HSI
  • Handles transparency (alpha) values
  • Robust API with error handling
  • Written in TypeScript for better reliability

Installation

npm install postcss-color-transformer --save-dev

Usage

// postcss.config.js
module.exports = {
  plugins: [
    require("postcss-color-transformer")({
      // Options (toutes sont optionnelles)
      verbose: false, // Activer les logs détaillés
      supportedFormats: [
        "rgb",
        "rgba",
        "hsl",
        "hsla",
        "oklch",
        "lab",
        "lch",
        "hwb",
        "hsv",
        "hsi",
      ],
    }),
  ],
};

CSS source :

.test {
  --color1: oklch(from hsl(x x x));
  --color2: rgb(from oklch(x x x));
  --color3: hsl(from rgb(x x x));
}

Compiled to :

.test {
  --color1: oklch(y y y);
  --color2: rgb(y y y);
  --color3: hsl(y y y);
}