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 | [![NPM Version][npm-img]][npm-url]
|
---|
4 | [![CSS Standard Status][css-img]][css-url]
|
---|
5 | [![Build Status][cli-img]][cli-url]
|
---|
6 | [![Support Chat][git-img]][git-url]
|
---|
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 postcssColorFunctionalNotation = require('postcss-color-functional-notation');
|
---|
41 |
|
---|
42 | postcssColorFunctionalNotation.process(YOUR_CSS /*, processOptions, pluginOptions */);
|
---|
43 | ```
|
---|
44 |
|
---|
45 | Or use it as a [PostCSS] plugin:
|
---|
46 |
|
---|
47 | ```js
|
---|
48 | const postcss = require('postcss');
|
---|
49 | const postcssColorFunctionalNotation = require('postcss-color-functional-notation');
|
---|
50 |
|
---|
51 | postcss([
|
---|
52 | postcssColorFunctionalNotation(/* pluginOptions */)
|
---|
53 | ]).process(YOUR_CSS /*, processOptions */);
|
---|
54 | ```
|
---|
55 |
|
---|
56 | [PostCSS Color Functional Notation] runs in all Node environments, with special instructions for:
|
---|
57 |
|
---|
58 | | [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) |
|
---|
59 | | --- | --- | --- | --- | --- | --- |
|
---|
60 |
|
---|
61 | ## Options
|
---|
62 |
|
---|
63 | ### preserve
|
---|
64 |
|
---|
65 | The `preserve` option determines whether the original functional color notation
|
---|
66 | is preserved. By default, it is not preserved.
|
---|
67 |
|
---|
68 | ```js
|
---|
69 | postcssImageSetFunction({ preserve: true })
|
---|
70 | ```
|
---|
71 |
|
---|
72 | ```pcss
|
---|
73 | :root {
|
---|
74 | --firebrick: rgb(178 34 34);
|
---|
75 | --firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
|
---|
76 | --firebrick-hsl: hsla(0 68% 42%);
|
---|
77 | --firebrick-hsl-a50: hsl(0 68% 42% / 50%);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /* becomes */
|
---|
81 |
|
---|
82 | :root {
|
---|
83 | --firebrick: rgb(178, 34, 34);
|
---|
84 | --firebrick: rgb(178 34 34);
|
---|
85 | --firebrick-a50: rgba(178, 34, 34, .5);
|
---|
86 | --firebrick-a50: rgb(70% 13.5% 13.5% / 50%);
|
---|
87 | --firebrick-hsl: hsl(0, 68%, 42%);
|
---|
88 | --firebrick-hsl: hsla(0 68% 42%);
|
---|
89 | --firebrick-hsl-a50: hsla(0, 68%, 42%, .5);
|
---|
90 | --firebrick-hsl-a50: hsl(0 68% 42% / 50%);
|
---|
91 | }
|
---|
92 | ```
|
---|
93 |
|
---|
94 | [cli-img]: https://img.shields.io/travis/jonathantneal/postcss-color-functional-notation.svg
|
---|
95 | [cli-url]: https://travis-ci.org/jonathantneal/postcss-color-functional-notation
|
---|
96 | [css-img]: https://cssdb.org/badge/color-functional-notation.svg
|
---|
97 | [css-url]: https://cssdb.org/#color-functional-notation
|
---|
98 | [git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
---|
99 | [git-url]: https://gitter.im/postcss/postcss
|
---|
100 | [npm-img]: https://img.shields.io/npm/v/postcss-color-functional-notation.svg
|
---|
101 | [npm-url]: https://www.npmjs.com/package/postcss-color-functional-notation
|
---|
102 |
|
---|
103 | [CSS Color]: https://drafts.csswg.org/css-color/#ref-for-funcdef-rgb%E2%91%A1%E2%91%A0
|
---|
104 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
---|
105 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
---|
106 | [PostCSS]: https://github.com/postcss/postcss
|
---|
107 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
---|
108 | [PostCSS Color Functional Notation]: https://github.com/jonathantneal/postcss-color-functional-notation
|
---|