| 1 | # PostCSS Color Functional Notation [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS Logo" width="90" height="90" align="right">][postcss]
|
|---|
| 2 |
|
|---|
| 3 | [<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-color-functional-notation.svg" height="20">][npm-url]
|
|---|
| 4 | [<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/lab-function.svg" height="20">][css-url]
|
|---|
| 5 | [<img alt="Build Status" src="https://github.com/csstools/postcss-plugins/workflows/test/badge.svg" height="20">][cli-url]
|
|---|
| 6 | [<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
|
|---|
| 7 |
|
|---|
| 8 | [PostCSS Color Functional Notation] lets you use space and slash separated
|
|---|
| 9 | color notation in CSS, following the [CSS Color] specification.
|
|---|
| 10 |
|
|---|
| 11 | ```pcss
|
|---|
| 12 | :root {
|
|---|
| 13 | --firebrick: rgb(178 34 34);
|
|---|
| 14 | --firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
|
|---|
| 15 | --firebrick-hsl: hsla(0 68% 42%);
|
|---|
| 16 | --firebrick-hsl-a50: hsl(0 68% 42% / 50%);
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /* becomes */
|
|---|
| 20 |
|
|---|
| 21 | :root {
|
|---|
| 22 | --firebrick: rgb(178, 34, 34);
|
|---|
| 23 | --firebrick-a50: rgba(178, 34, 34, .5);
|
|---|
| 24 | --firebrick-hsl: hsl(0, 68%, 42%);
|
|---|
| 25 | --firebrick-hsl-a50: hsla(0, 68%, 42%, .5);
|
|---|
| 26 | }
|
|---|
| 27 | ```
|
|---|
| 28 |
|
|---|
| 29 | ## Usage
|
|---|
| 30 |
|
|---|
| 31 | Add [PostCSS Color Functional Notation] to your project:
|
|---|
| 32 |
|
|---|
| 33 | ```bash
|
|---|
| 34 | npm install postcss-color-functional-notation --save-dev
|
|---|
| 35 | ```
|
|---|
| 36 |
|
|---|
| 37 | Use [PostCSS Color Functional Notation] to process your CSS:
|
|---|
| 38 |
|
|---|
| 39 | ```js
|
|---|
| 40 | const postcss = require('postcss');
|
|---|
| 41 | const postcssColorFunctionalNotation = require('postcss-color-functional-notation');
|
|---|
| 42 |
|
|---|
| 43 | postcss([
|
|---|
| 44 | postcssColorFunctionalNotation(/* pluginOptions */)
|
|---|
| 45 | ]).process(YOUR_CSS /*, processOptions */);
|
|---|
| 46 | ```
|
|---|
| 47 |
|
|---|
| 48 | [PostCSS Color Functional Notation] runs in all Node environments, with special instructions for:
|
|---|
| 49 |
|
|---|
| 50 | | [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
|
|---|
| 51 | | --- | --- | --- | --- | --- | --- |
|
|---|
| 52 |
|
|---|
| 53 | ## Options
|
|---|
| 54 |
|
|---|
| 55 | ### preserve
|
|---|
| 56 |
|
|---|
| 57 | The `preserve` option determines whether the original functional color notation
|
|---|
| 58 | is preserved. By default, it is not preserved.
|
|---|
| 59 |
|
|---|
| 60 | ```js
|
|---|
| 61 | postcssImageSetFunction({ preserve: true })
|
|---|
| 62 | ```
|
|---|
| 63 |
|
|---|
| 64 | ```pcss
|
|---|
| 65 | :root {
|
|---|
| 66 | --firebrick: rgb(178 34 34);
|
|---|
| 67 | --firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
|
|---|
| 68 | --firebrick-hsl: hsla(0 68% 42%);
|
|---|
| 69 | --firebrick-hsl-a50: hsl(0 68% 42% / 50%);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | /* becomes */
|
|---|
| 73 |
|
|---|
| 74 | :root {
|
|---|
| 75 | --firebrick: rgb(178, 34, 34);
|
|---|
| 76 | --firebrick: rgb(178 34 34);
|
|---|
| 77 | --firebrick-a50: rgba(178, 34, 34, .5);
|
|---|
| 78 | --firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
|
|---|
| 79 | --firebrick-hsl: hsl(0, 68%, 42%);
|
|---|
| 80 | --firebrick-hsl: hsla(0 68% 42%);
|
|---|
| 81 | --firebrick-hsl-a50: hsla(0, 68%, 42%, .5);
|
|---|
| 82 | --firebrick-hsl-a50: hsl(0 68% 42% / 50%);
|
|---|
| 83 | }
|
|---|
| 84 | ```
|
|---|
| 85 |
|
|---|
| 86 | [cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test
|
|---|
| 87 | [css-url]: https://cssdb.org/#color-functional-notation
|
|---|
| 88 | [discord]: https://discord.gg/bUadyRwkJS
|
|---|
| 89 | [npm-url]: https://www.npmjs.com/package/postcss-color-functional-notation
|
|---|
| 90 |
|
|---|
| 91 | [CSS Color]: https://drafts.csswg.org/css-color/#ref-for-funcdef-rgb%E2%91%A1%E2%91%A0
|
|---|
| 92 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
|---|
| 93 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
|---|
| 94 | [PostCSS]: https://github.com/postcss/postcss
|
|---|
| 95 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
|---|
| 96 | [PostCSS Color Functional Notation]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-color-functional-notation
|
|---|