source: trip-planner-front/node_modules/postcss-color-mod-function/README.md@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.7 KB
Line 
1# PostCSS color-mod() Function [<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-mod() Function] lets you modify colors using the `color-mod()`
9function in CSS, following the [CSS Color Module Level 4] specification.
10
11**`color-mod()` has been removed from the Color Module Level 4 specification.**
12
13```pcss
14:root {
15 --brand-red: color-mod(yellow blend(red 50%));
16 --brand-red-hsl: color-mod(yellow blend(red 50% hsl));
17 --brand-red-hwb: color-mod(yellow blend(red 50% hwb));
18 --brand-red-dark: color-mod(red blackness(20%));
19}
20
21/* becomes */
22
23:root {
24 --brand-red: rgb(255, 127.5, 0);
25 --brand-red-hsl: rgb(255, 127.5, 255);
26 --brand-red-hwb: rgb(255, 127.5, 0);
27 --brand-red-dark: rgb(204, 0, 0);
28}
29
30/* or, using stringifier(color) { return color.toString() } */
31
32:root {
33 --brand-red: rgb(100% 50% 0% / 100%);
34 --brand-red-hsl: hsl(30 100% 50% / 100%);
35 --brand-red-hwb: hwb(30 0% 0% / 100%);
36 --brand-red-dark: hwb(0 0% 20% / 100%);
37}
38```
39
40### Supported Colors
41
42The `color-mod()` function accepts `rgb()`, legacy comma-separated `rgb()`,
43`rgba()`, `hsl()`, legacy comma-separated `hsl()`, `hsla()`, `hwb()`, and
44`color-mod()` colors, as well as 3, 4, 6, and 8 digit hex colors, and named
45colors without the need for additional plugins.
46
47Implemention details are available in
48[the specification](https://drafts.csswg.org/css-color/#funcdef-color-mod).
49
50### Supported Color Adjusters
51
52The `color-mod()` function accepts `red()`, `green()`, `blue()`, `a()` /
53`alpha()`, `rgb()`, `h()` / `hue()`, `s()` / `saturation()`, `l()` /
54`lightness()`, `w()` / `whiteness()`, `b()` / `blackness()`, `tint()`,
55`shade()`, `blend()`, `blenda()`, and `contrast()` color adjusters.
56
57Implemention details are available in
58[the specification](https://drafts.csswg.org/css-color/#typedef-color-adjuster).
59
60### Supported Variables
61
62By default, `var()` variables will be used if their corresponding Custom
63Properties are found in a `:root` rule, or if a fallback value is specified.
64
65## Usage
66
67Add [PostCSS color-mod() Function] to your project:
68
69```bash
70npm install postcss-color-mod-function --save-dev
71```
72
73Use [PostCSS color-mod() Function] to process your CSS:
74
75```js
76const postcssColorMod = require('postcss-color-mod-function');
77
78postcssColorMod.process(YOUR_CSS /*, processOptions, pluginOptions */);
79```
80
81Or use it as a [PostCSS] plugin:
82
83```js
84const postcss = require('postcss');
85const postcssColorMod = require('postcss-color-mod-function');
86
87postcss([
88 postcssColorMod(/* pluginOptions */)
89]).process(YOUR_CSS /*, processOptions */);
90```
91
92[PostCSS color-mod() Function] runs in all Node environments, with special instructions for:
93
94| [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) |
95| --- | --- | --- | --- | --- | --- |
96
97## Options
98
99### stringifier
100
101The `stringifier` option defines how transformed colors will be produced in CSS.
102By default, legacy `rbg()` and `rgba()` colors are produced, but this can be
103easily updated to support [CSS Color Module Level 4 colors] colors.
104
105```js
106import postcssColorMod from 'postcss-color-mod-function';
107
108postcssColorMod({
109 stringifier(color) {
110 return color.toString(); // use CSS Color Module Level 4 colors (rgb, hsl, hwb)
111 }
112});
113```
114
115Future major releases of [PostCSS color-mod() Function] may reverse this
116functionality so that CSS Color Module Level 4 colors are produced by default.
117
118### unresolved
119
120The `unresolved` option defines how unresolved functions and arguments should
121be handled. The available options are `throw`, `warn`, and `ignore`. The
122default option is to `throw`.
123
124If `ignore` is used, the `color-mod()` function will remain unchanged.
125
126```js
127import postcssColorMod from 'postcss-color-mod-function';
128
129postcssColorMod({
130 unresolved: 'ignore' // ignore unresolved color-mod() functions
131});
132```
133
134### transformVars
135
136The `transformVars` option defines whether `var()` variables used within
137`color-mod()` should be transformed into their corresponding Custom Properties
138available in `:root`, or their fallback value if it is specified. By default,
139`var()` variables will be transformed.
140
141However, because these transformations occur at build time, they cannot be
142considered accurate. Accurately resolving cascading variables relies on
143knowledge of the living DOM tree.
144
145### importFrom
146
147The `importFrom` option allows you to import variables from other sources,
148which might be CSS, JS, and JSON files, and directly passed objects.
149
150```js
151postcssColorMod({
152 importFrom: 'path/to/file.css' // :root { --brand-dark: blue; --brand-main: var(--brand-dark); }
153});
154```
155
156```pcss
157.brand-faded {
158 color: color-mod(var(--brand-main) a(50%));
159}
160
161/* becomes */
162
163.brand-faded {
164 color: rgba(0, 0, 255, .5);
165}
166```
167
168Multiple files can be passed into this option, and they will be parsed in the
169order they were received. JavaScript files, JSON files, and objects will need
170to namespace custom properties under a `customProperties` or
171`custom-properties` key.
172
173```js
174postcssColorMod({
175 importFrom: [
176 'path/to/file.css', // :root { --brand-dark: blue; --brand-main: var(--brand-dark); }
177 'and/then/this.js', // module.exports = { customProperties: { '--brand-dark': 'blue', '--brand-main': 'var(--brand-dark)' } }
178 'and/then/that.json', // { "custom-properties": { "--brand-dark": "blue", "--brand-main": "var(--brand-dark)" } }
179 {
180 customProperties: {
181 '--brand-dark': 'blue',
182 '--brand-main': 'var(--brand-dark)'
183 }
184 }
185 ]
186});
187```
188
189Variables may reference other variables, and this plugin will attempt to
190resolve them. If `transformVars` is set to `false` then `importFrom` will not
191be used.
192
193[cli-img]: https://img.shields.io/travis/jonathantneal/postcss-color-mod-function.svg
194[cli-url]: https://travis-ci.org/jonathantneal/postcss-color-mod-function
195[css-img]: https://cssdb.org/badge/color-mod-function.svg
196[css-url]: https://preset-env.cssdb.org/features#color-mod-function
197[git-img]: https://img.shields.io/badge/support-chat-blue.svg
198[git-url]: https://gitter.im/postcss/postcss
199[npm-img]: https://img.shields.io/npm/v/postcss-color-mod-function.svg
200[npm-url]: https://www.npmjs.com/package/postcss-color-mod-function
201
202[CSS Color Module Level 4]: https://www.w3.org/TR/css-color-4/#funcdef-color-mod
203[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
204[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
205[PostCSS]: https://github.com/postcss/postcss
206[PostCSS color-mod() Function]: https://github.com/jonathantneal/postcss-color-mod-function
Note: See TracBrowser for help on using the repository browser.