postcss-double-position-gradients
Version:
Use double-position gradients in CSS
130 lines (93 loc) • 4.36 kB
Markdown
[<img alt="NPM Version" src="https://img.shields.io/npm/v/postcss-double-position-gradients.svg" height="20">][npm-url]
[<img alt="Discord" src="https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white">][discord]
<br><br>
[<img alt="Baseline Status" src="https://cssdb.org/images/badges-baseline/double-position-gradients.svg" height="20">][css-url]
[<img alt="CSS Standard Status" src="https://cssdb.org/images/badges/double-position-gradients.svg" height="20">][css-url]
[] lets you use double-position gradients in
CSS, following the [CSS Image Values and Replaced Content] specification.
```css
.linear-gradient {
background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
}
.conic-gradient {
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%,
}
/* becomes */
.linear-gradient {
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
}
.conic-gradient {
background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%,
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%,
}
```
Add [PostCSS Double Position Gradients] to your project:
```bash
npm install postcss-double-position-gradients --save-dev
```
Use [PostCSS Double Position Gradients] to process your CSS:
```js
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
postcssDoublePositionGradients.process(YOUR_CSS /*, processOptions, pluginOptions */);
```
Or use it as a [PostCSS] plugin:
```js
const postcss = require('postcss');
const postcssDoublePositionGradients = require('postcss-double-position-gradients');
postcss([
postcssDoublePositionGradients(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```
[] runs in all Node environments, with special instructions for:
| [Node](INSTALL.md
| --- | --- | --- | --- | --- |
The `preserve` option determines whether the original double-position gradients
should be preserved. By default, double-position gradients are preserved.
```js
postcssDoublePositionGradients({ preserve: false })
```
```css
.linear-gradient {
background-image: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
}
.conic-gradient {
background-image: conic-gradient(yellowgreen 40%, gold 0deg 75%,
}
/* becomes */
.linear-gradient {
background-image: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%);
}
.conic-gradient {
background-image: conic-gradient(yellowgreen 40%, gold 0deg, gold 75%,
}
```
The `enableProgressiveCustomProperties` option determines whether the original notation
is wrapped with `@supports` when used in Custom Properties. By default, it is enabled.
> [!NOTE]
> We only recommend disabling this when you set `preserve` to `false` or if you bring your own fix for Custom Properties.
> See what the plugin does in its [README](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-progressive-custom-properties#readme).
```js
postcssDoublePositionGradients({ enableProgressiveCustomProperties: false })
```
```css
:root {
--a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
}
/* becomes */
:root {
--a-gradient: linear-gradient(90deg, black 25%, black 50%, blue 50%, blue 75%); /* will never be used, not even in older browser */
--a-gradient: linear-gradient(90deg, black 25% 50%, blue 50% 75%);
}
```
[]: https://cssdb.org/#double-position-gradients
[]: https://discord.gg/bUadyRwkJS
[]: https://www.npmjs.com/package/postcss-double-position-gradients
[]: https://www.w3.org/TR/css-images-4/#color-stop-syntax
[]: https://github.com/postcss/postcss
[]: https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients