@csstools/postcss-alpha-function
Use the alpha() function in CSS
Last updated 10 months ago by romainmenke .
MIT-0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @csstools/postcss-alpha-function 
SYNC missed versions from official npm registry.

PostCSS Alpha Function PostCSS Logo

npm install @csstools/postcss-alpha-function --save-dev

PostCSS Alpha Function lets you use the alpha function in CSS, following the CSS Color specification.

.color {
	color: alpha(from #dddd / calc(alpha / 2));
}

:root {
	--a-color: alpha(from rgb(2 1 0 / var(--a)) / calc(alpha / 2));
}

/* becomes */

.color {
	color: rgb(from #dddd r g b / calc(alpha / 2));
}

:root {
	--a-color: rgb(from rgb(2 1 0 / var(--a)) r g b / calc(alpha / 2));
}

Usage

Add PostCSS Alpha Function to your project:

npm install postcss @csstools/postcss-alpha-function --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssAlphaFunction = require('@csstools/postcss-alpha-function');

postcss([
	postcssAlphaFunction(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

Options

preserve

The preserve option determines whether the original notation is preserved. By default, it is not preserved.

postcssAlphaFunction({ preserve: true })
.color {
	color: alpha(from #dddd / calc(alpha / 2));
}

:root {
	--a-color: alpha(from rgb(2 1 0 / var(--a)) / calc(alpha / 2));
}

/* becomes */

.color {
	color: rgb(from #dddd r g b / calc(alpha / 2));
	color: alpha(from #dddd / calc(alpha / 2));
}

:root {
	--a-color: rgb(from rgb(2 1 0 / var(--a)) r g b / calc(alpha / 2));
}

@supports (color: alpha(from red / 1)) and (color: rgb(0 0 0 / 0)) {
:root {
	--a-color: alpha(from rgb(2 1 0 / var(--a)) / calc(alpha / 2));
}
}

enableProgressiveCustomProperties

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.

postcssAlphaFunction({ enableProgressiveCustomProperties: false })
.color {
	color: alpha(from #dddd / calc(alpha / 2));
}

:root {
	--a-color: alpha(from rgb(2 1 0 / var(--a)) / calc(alpha / 2));
}

/* becomes */

.color {
	color: rgb(from #dddd r g b / calc(alpha / 2));
	color: alpha(from #dddd / calc(alpha / 2));
}

:root {
	--a-color: rgb(from rgb(2 1 0 / var(--a)) r g b / calc(alpha / 2));
	--a-color: alpha(from rgb(2 1 0 / var(--a)) / calc(alpha / 2));
}

Custom properties do not fallback to the previous declaration

Copyright : color conversions

This software or document includes material copied from or derived from https://github.com/w3c/csswg-drafts/tree/main/css-color-4. Copyright © 2022 W3C® (MIT, ERCIM, Keio, Beihang).

Current Tags

  • 2.0.18                                ...           latest (10 days ago)

21 Versions

  • 2.0.18                                ...           10 days ago
  • 2.0.17                                ...           a month ago
  • 2.0.16                                ...           2 months ago
  • 2.0.15                                ...           2 months ago
  • 2.0.14                                ...           2 months ago
  • 2.0.13                                ...           2 months ago
  • 2.0.12                                ...           3 months ago
  • 2.0.11                                ...           3 months ago
  • 2.0.10                                ...           3 months ago
  • 2.0.9                                ...           3 months ago
  • 2.0.8                                ...           4 months ago
  • 2.0.7                                ...           5 months ago
  • 2.0.6                                ...           5 months ago
  • 2.0.5                                ...           6 months ago
  • 2.0.4                                ...           7 months ago
  • 2.0.3                                ...           9 months ago
  • 2.0.2                                ...           10 months ago
  • 2.0.1                                ...           10 months ago
  • 2.0.0                                ...           10 months ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Downloads
Total 52
Today 0
This Week 1
This Month 51
Last Day 0
Last Week 3
Last Month 0
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE