Gathering detailed insights and metrics for postcss-color-mod-function
Gathering detailed insights and metrics for postcss-color-mod-function
Gathering detailed insights and metrics for postcss-color-mod-function
Gathering detailed insights and metrics for postcss-color-mod-function
postcss-color-function
PostCSS plugin to transform W3C CSS color function to more compatible CSS.
@csstools/postcss-color-function
Use the color() function in CSS
postcss-lab-function
Use lab() and lch() color functions in CSS
@csstools/postcss-oklab-function
Use oklab() and oklch() color functions in CSS
Modify colors using the color-mod() function in CSS
npm install postcss-color-mod-function
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
96 Stars
35 Commits
14 Forks
5 Watching
1 Branches
11 Contributors
Updated on 08 Nov 2024
Minified
Minified + Gzipped
JavaScript (86.77%)
CSS (13.23%)
Cumulative downloads
Total Downloads
Last day
-5.8%
290,913
Compared to previous day
Last week
1.7%
1,571,219
Compared to previous week
Last month
4.7%
6,706,423
Compared to previous month
Last year
-35.9%
88,610,404
Compared to previous year
2
1
3
PostCSS color-mod() Function lets you modify colors using the color-mod()
function in CSS, following the outdated version of CSS Color Module Level 4 specification (05 July 2016).
⚠️ color-mod()
has been removed from Color Module Level 4 specification. (Here's why)
1:root { 2 --brand-red: color-mod(yellow blend(red 50%)); 3 --brand-red-hsl: color-mod(yellow blend(red 50% hsl)); 4 --brand-red-hwb: color-mod(yellow blend(red 50% hwb)); 5 --brand-red-dark: color-mod(red blackness(20%)); 6} 7 8/* becomes */ 9 10:root { 11 --brand-red: rgb(255, 127.5, 0); 12 --brand-red-hsl: rgb(255, 127.5, 255); 13 --brand-red-hwb: rgb(255, 127.5, 0); 14 --brand-red-dark: rgb(204, 0, 0); 15} 16 17/* or, using stringifier(color) { return color.toString() } */ 18 19:root { 20 --brand-red: rgb(100% 50% 0% / 100%); 21 --brand-red-hsl: hsl(30 100% 50% / 100%); 22 --brand-red-hwb: hwb(30 0% 0% / 100%); 23 --brand-red-dark: hwb(0 0% 20% / 100%); 24}
The color-mod()
function accepts rgb()
, legacy comma-separated rgb()
,
rgba()
, hsl()
, legacy comma-separated hsl()
, hsla()
, hwb()
, and
color-mod()
colors, as well as 3, 4, 6, and 8 digit hex colors, and named
colors without the need for additional plugins.
Implemention details are available in the specification.
The color-mod()
function accepts red()
, green()
, blue()
, a()
/
alpha()
, rgb()
, h()
/ hue()
, s()
/ saturation()
, l()
/
lightness()
, w()
/ whiteness()
, b()
/ blackness()
, tint()
,
shade()
, blend()
, blenda()
, and contrast()
color adjusters.
Implemention details are available in the specification.
By default, var()
variables will be used if their corresponding Custom
Properties are found in a :root
rule, or if a fallback value is specified.
Add PostCSS color-mod() Function to your project:
1npm install postcss postcss-color-mod-function --save-dev
Use PostCSS color-mod() Function to process your CSS:
1const postcssColorMod = require('postcss-color-mod-function'); 2 3postcssColorMod.process(YOUR_CSS /*, processOptions, pluginOptions */);
Or use it as a PostCSS plugin:
1const postcss = require('postcss'); 2const postcssColorMod = require('postcss-color-mod-function'); 3 4postcss([ 5 postcssColorMod(/* pluginOptions */) 6]).process(YOUR_CSS /*, processOptions */);
PostCSS color-mod() Function runs in all Node environments, with special instructions for:
Node | PostCSS CLI | Webpack | Create React App | Gulp | Grunt |
---|
The stringifier
option defines how transformed colors will be produced in CSS.
By default, legacy rgb()
and rgba()
colors are produced, but this can be
easily updated to support [CSS Color Module Level 4 colors] colors.
1import postcssColorMod from 'postcss-color-mod-function';
2
3postcssColorMod({
4 stringifier(color) {
5 return color.toString(); // use CSS Color Module Level 4 colors (rgb, hsl, hwb)
6 }
7});
Future major releases of PostCSS color-mod() Function may reverse this functionality so that CSS Color Module Level 4 colors are produced by default.
The unresolved
option defines how unresolved functions and arguments should
be handled. The available options are throw
, warn
, and ignore
. The
default option is to throw
.
If ignore
is used, the color-mod()
function will remain unchanged.
1import postcssColorMod from 'postcss-color-mod-function';
2
3postcssColorMod({
4 unresolved: 'ignore' // ignore unresolved color-mod() functions
5});
The transformVars
option defines whether var()
variables used within
color-mod()
should be transformed into their corresponding Custom Properties
available in :root
, or their fallback value if it is specified. By default,
var()
variables will be transformed.
However, because these transformations occur at build time, they cannot be considered accurate. Accurately resolving cascading variables relies on knowledge of the living DOM tree.
The importFrom
option allows you to import variables from other sources,
which might be CSS, JS, and JSON files, and directly passed objects.
1postcssColorMod({
2 importFrom: 'path/to/file.css' // :root { --brand-dark: blue; --brand-main: var(--brand-dark); }
3});
1.brand-faded { 2 color: color-mod(var(--brand-main) a(50%)); 3} 4 5/* becomes */ 6 7.brand-faded { 8 color: rgba(0, 0, 255, .5); 9}
Multiple files can be passed into this option, and they will be parsed in the
order they were received. JavaScript files, JSON files, and objects will need
to namespace custom properties under a customProperties
or
custom-properties
key.
1postcssColorMod({ 2 importFrom: [ 3 'path/to/file.css', // :root { --brand-dark: blue; --brand-main: var(--brand-dark); } 4 'and/then/this.js', // module.exports = { customProperties: { '--brand-dark': 'blue', '--brand-main': 'var(--brand-dark)' } } 5 'and/then/that.json', // { "custom-properties": { "--brand-dark": "blue", "--brand-main": "var(--brand-dark)" } } 6 { 7 customProperties: { 8 '--brand-dark': 'blue', 9 '--brand-main': 'var(--brand-dark)' 10 } 11 } 12 ] 13});
Variables may reference other variables, and this plugin will attempt to
resolve them. If transformVars
is set to false
then importFrom
will not
be used.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
6 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 7
Reason
Found 7/28 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More