[6a3a178] | 1 | # PostCSS Lab 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 Lab Function] lets you use `lab`, `lch`, and `gray` color functions in
|
---|
| 9 | CSS, following the [CSS Color] specification.
|
---|
| 10 |
|
---|
| 11 | ```pcss
|
---|
| 12 | :root {
|
---|
| 13 | --firebrick: lab(40 56.6 39);
|
---|
| 14 | --firebrick-a50: lch(40 68.8 34.5 / 50%);
|
---|
| 15 | --gray-40: gray(40);
|
---|
| 16 | --gray-40a50: gray(40 / .5);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | /* becomes */
|
---|
| 20 |
|
---|
| 21 | :root {
|
---|
| 22 | --firebrick: rgb(178, 34, 34);
|
---|
| 23 | --firebrick-a50: rgba(178, 34, 34, .5);
|
---|
| 24 | --gray-40: rgb(94,94,94);
|
---|
| 25 | --gray-40a50: rgba(94,94,94, .5);
|
---|
| 26 | }
|
---|
| 27 | ```
|
---|
| 28 |
|
---|
| 29 | ## Usage
|
---|
| 30 |
|
---|
| 31 | Add [PostCSS Lab Function] to your project:
|
---|
| 32 |
|
---|
| 33 | ```bash
|
---|
| 34 | npm install postcss-lab-function --save-dev
|
---|
| 35 | ```
|
---|
| 36 |
|
---|
| 37 | Use [PostCSS Lab Function] to process your CSS:
|
---|
| 38 |
|
---|
| 39 | ```js
|
---|
| 40 | const postcssLabFunction = require('postcss-lab-function');
|
---|
| 41 |
|
---|
| 42 | postcssLabFunction.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 postcssLabFunction = require('postcss-lab-function');
|
---|
| 50 |
|
---|
| 51 | postcss([
|
---|
| 52 | postcssLabFunction(/* pluginOptions */)
|
---|
| 53 | ]).process(YOUR_CSS /*, processOptions */);
|
---|
| 54 | ```
|
---|
| 55 |
|
---|
| 56 | [PostCSS Lab Function] runs in all Node environments, with special
|
---|
| 57 | instructions for:
|
---|
| 58 |
|
---|
| 59 | | [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) |
|
---|
| 60 | | --- | --- | --- | --- | --- | --- |
|
---|
| 61 |
|
---|
| 62 | ## Options
|
---|
| 63 |
|
---|
| 64 | ### preserve
|
---|
| 65 |
|
---|
| 66 | The `preserve` option determines whether the original functional color notation
|
---|
| 67 | is preserved. By default, it is not preserved.
|
---|
| 68 |
|
---|
| 69 | ```js
|
---|
| 70 | postcssLabFunction({ preserve: true })
|
---|
| 71 | ```
|
---|
| 72 |
|
---|
| 73 | ```pcss
|
---|
| 74 | :root {
|
---|
| 75 | --firebrick: lab(40 56.6 39);
|
---|
| 76 | --firebrick-a50: lch(40 68.8 34.5 / 50%);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | /* becomes */
|
---|
| 80 |
|
---|
| 81 | :root {
|
---|
| 82 | --firebrick: rgb(178, 34, 34);
|
---|
| 83 | --firebrick: lab(40 56.6 39);
|
---|
| 84 | --firebrick-a50: rgba(178, 34, 34, .5);
|
---|
| 85 | --firebrick-a50: lch(40 68.8 34.5 / 50%);
|
---|
| 86 | }
|
---|
| 87 | ```
|
---|
| 88 |
|
---|
| 89 | [cli-img]: https://img.shields.io/travis/jonathantneal/postcss-lab-function.svg
|
---|
| 90 | [cli-url]: https://travis-ci.org/jonathantneal/postcss-lab-function
|
---|
| 91 | [css-img]: https://cssdb.org/badge/lab-function.svg
|
---|
| 92 | [css-url]: https://cssdb.org/#lab-function
|
---|
| 93 | [git-img]: https://img.shields.io/badge/support-chat-blue.svg
|
---|
| 94 | [git-url]: https://gitter.im/postcss/postcss
|
---|
| 95 | [npm-img]: https://img.shields.io/npm/v/postcss-lab-function.svg
|
---|
| 96 | [npm-url]: https://www.npmjs.com/package/postcss-lab-function
|
---|
| 97 |
|
---|
| 98 | [CSS Color]: https://drafts.csswg.org/css-color/#specifying-lab-lch
|
---|
| 99 | [Gulp PostCSS]: https://github.com/postcss/gulp-postcss
|
---|
| 100 | [Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
|
---|
| 101 | [PostCSS]: https://github.com/postcss/postcss
|
---|
| 102 | [PostCSS Loader]: https://github.com/postcss/postcss-loader
|
---|
| 103 | [PostCSS Lab Function]: https://github.com/jonathantneal/postcss-lab-function
|
---|