@csstools/postcss-gamut-mapping
TypeScript icon, indicating that this package has built-in type declarations

2.0.10 • Public • Published

PostCSS Gamut Mapping PostCSS Logo

npm install @csstools/postcss-gamut-mapping --save-dev

PostCSS Gamut Mapping lets you use wide gamut colors with gamut mapping for specific displays following the CSS Color 4 Specification.

When out of gamut colors are naively clipped the result can be radically different.
A saturated and bright color will be much darker after clipping.

To correctly adjust colors for a narrow gamut display, the colors must be mapped.
This is done by lowering the chroma in oklch until the color is in gamut.

Using the @media (color-gamut) media feature makes it possible to only use the wide gamut colors on displays that support them.

p {
	background-color: oklch(80% 0.05 0.39 / 0.5);
	color: oklch(20% 0.234 0.39 / 0.5);
	border-color: color(display-p3 0 1 0);
}

/* becomes */

p {
	background-color: oklch(80% 0.05 0.39 / 0.5);
	color: rgba(48, 0, 20, 0.5);
	border-color: rgb(0, 247, 79);
}

@media (color-gamut: rec2020) {
p {
	color: oklch(20% 0.234 0.39 / 0.5);
}
}

@media (color-gamut: p3) {
p {
	border-color: color(display-p3 0 1 0);
}
}

Usage

Add PostCSS Gamut Mapping to your project:

npm install postcss @csstools/postcss-gamut-mapping --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssGamutMapping = require('@csstools/postcss-gamut-mapping');

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.1072,764latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.1072,764
2.0.9281,115
2.0.8183,111
2.0.7103,445
2.0.689,771
2.0.58,110
2.0.45,308
2.0.36,142
2.0.265,229
2.0.11,763
2.0.02,018
1.0.11248,866
1.0.106,277
1.0.959,026
1.0.81
1.0.78,683
1.0.611,008
1.0.54,244
1.0.4545
1.0.321,854
1.0.230,574
1.0.12,522
1.0.043,108

Package Sidebar

Install

npm i @csstools/postcss-gamut-mapping

Weekly Downloads

1,255,484

Version

2.0.10

License

MIT-0

Unpacked Size

10.6 kB

Total Files

7

Last publish

Collaborators

  • jonathantneal
  • alaguna
  • romainmenke