Color Spaces: Units in color channels
See original GitHub issueThe current definition of colors says that channel values are floating-point—that is, they’re stored without reference to a unit. However, there’s no explicit conversion from Sass numbers (which may have units) to floating-point numbers (which may not) either in Parsing Color Components or color()
.
This raises a few questions:
-
CSS Colors 5 only allows raw numbers or percentages for custom colors. Should we do the same for unknown color spaces? Or is the risk of forwards-incompatibility with potential new predefined polar color spaces too great?
-
If we do allow unknown color spaces to specify channels with circular units, do we have to store that fact? Can we just serialize those colors with a unitless value for that channel? Is there a risk of a new predefiend color space with a polar channel that defaults to turns instead of degrees?
-
If we allow unknown color spaces to specify channels with circular units, do we allow any units, or just unitless/percent/circular?
-
The existing channel-access functions
color.hue()
,color.saturation()
,color.lightness()
,color.whiteness()
, andcolor.blackness()
return values with units. However,color.channel()
is specified never to do so—socolor.channel($color, 'hue')
isn’t a drop-in replacement forcolor.hue($color)
. Is this a problem?
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Yes, that’s what I mean. The term “double” (in a Sass context) is defined in the Number spec and basically just means “a 64-bit floating point number”. We should try to use “double” in the spec rather than “floating-point number” because it’s more explicit about the size and gamut of the number in question.
I think generally it’s a good idea to try to avoid having logic in definitions, so if it’s feasible to keep that in processes that would be ideal. It shouldn’t require too much verbosity—just saying “
hue
’s value” is enough to make it clear that you mean the double it contains.channels()
and serialization