Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryelle/postcss-palettize-colors

PostCSS plugin to replace colors in a stylesheet with colors from a given palette.
https://github.com/ryelle/postcss-palettize-colors

Last synced: about 2 months ago
JSON representation

PostCSS plugin to replace colors in a stylesheet with colors from a given palette.

Awesome Lists containing this project

README

        

# PostCSS Palettize Colors

This is a postCSS plugin used to reduce the colors used in a CSS file down to a set of "valid" colors - a color palette. It uses a basic [color difference algorithm](https://en.wikipedia.org/wiki/Color_difference) to convert any color to the closest color in the palette.

Files with the comment `/* @no-color-match */` as the first item in the file will be skipped. In WordPress, we want this for the about.css file, since those colors are intentionally unique per release.

---------------------------------

## Options

### `colors`

- Type: `Object`
- Default: `{}`

A list of colors in key -> value pairs. The keys are not used currently, but are required by the `getClosestColor` matching function. Example:

```json
{
"white": "#fff",
"black": "#000",
"red": "#8c1717",
"blue": "#0ebfe9"
}
```

## Usage

```js
const options = {
colors: {
"white": "#fff",
"black": "#000",
"red": "#8c1717",
"blue": "#0ebfe9"
},
};
postcss( [ require( 'postcss-palettize-colors' )( options ) ] )
```

## Example

```css
.foo {
/* Input example */
color: #f00;
background-image: linear-gradient(to bottom right, #eee, #111);
}
```

```css
.foo {
/* Output example */
color: #8c1717;
background-image: linear-gradient(to bottom right, #fff, #000);
}
```