This repository was archived by the owner on Dec 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
This repository was archived by the owner on Dec 21, 2021. It is now read-only.
White and black are out of gamut #14
Copy link
Copy link
Closed
Description
I was trying this out to create a color range, like so:
--color-primary-100: lch(100% 10 230);
--color-primary-90: lch( 90% 10 230);
--color-primary-80: lch( 80% 10 230);
--color-primary-70: lch( 70% 10 230);
--color-primary-60: lch( 60% 10 230);
--color-primary-50: lch( 50% 10 230);
--color-primary-40: lch( 40% 10 230);
--color-primary-30: lch( 30% 10 230);
--color-primary-20: lch( 20% 10 230);
--color-primary-10: lch( 10% 10 230);
--color-primary-0: lch( 0% 10 230);
However, I quickly found that it's not possible to represent white or black! For example:
$ node
> const postcssLabFunction = require('postcss-lab-function');
> const postcss = require('postcss')([ postcssLabFunction() ]);
> postcss.process('body { background: lch(100% 10 230); }').css;
'body { background: rgb(236, 255, 255); }'
> postcss.process('body { background: lch( 0% 10 230); }').css;
'body { background: rgb( 0, 6, 17); }'
I was strongly expecting these to come out as RGB white and black, i.e. rgb(255, 255, 255)
and rgb(0, 0, 0)
. This expectation was due to:
- The spec, which says "The first argument specifies the CIE Lightness. This is typically a number between 0% (representing black) and 100% (representing white)." Since my first argument is
100%
, the output should be "white". - This LCH color picker, which outputs white (i.e.
rgb(255, 255, 255)
) for the same arguments.
The difference between your implementation and the LCH color picker seems to be the clamping function. Your clamping function clamps each channel to the range 0...255. But the LCH color picker's clamping function turns down the c
channel until the output is within the sRGB gamut. This, IMO, gives much better results.
Metadata
Metadata
Assignees
Labels
No labels