W3C home > Mailing lists > Public > public-css-archive@w3.org > November 2019

Re: [csswg-drafts] [css-color] lch() function needs to use CSS types properly. (#278)

From: Christoph Päper via GitHub <sysbot+gh@w3.org>
Date: Sat, 02 Nov 2019 18:04:52 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-549067321-1572717892-sysbot+gh@w3.org>
[css-values](https://drafts.csswg.org/css-values/#mixed-percentages) says in a note that we can never have a `<number-percentage>` value type due to how `calc()` works, and probably no `<integer-percentage>` either. Color components cannot be used with `calc()` (yet), but if they ever shall be, it would make sense to allow standard, internal CSS value types (like `<percentage>`), even if conventional, external notation is also to be supported and needs to be expressed in another value type (like `<number>`). 

We have several relevant precedents:
+ [`<alpha-value>`](https://drafts.csswg.org/css-color/#typedef-alpha-value) = `<number [0.0, 1.0]> | <percentage>` = [`<cmyk-component>`](https://drafts.csswg.org/css-color/#typedef-cmyk-component)
+ [`<hue>`](https://drafts.csswg.org/css-color/#typedef-hue) = `<angle> | <number>`
+ [`rgb()`](https://drafts.csswg.org/css-color/#rgb-functions), wherein the 3-tuple is required  to be of a single type, i. e. either 8-bit `<integer [0, 255]>{3}` (currently simply `<number>{3}`, though) or `<percentage>{3}` and not a mix of both although the optional fourth parameter is `<hue>`, thus may but need not match `<percentage>` and cannot match `<integer>`. 

I see no reason, why `<lightness>` = `<percentage> | <number [0, 100]>` would pose an actual problem, even if `<alpha-value>` and `<cmyk-component>` work differently. For `Lab()`, the second and third parameter, _a_ and _b_, could be normalized as percentages (e. g. for a [0, 160] or [0, 255] range), but that would be more appropriate for _u_ and _v_ in `Luv()`, which is not specified by CSS. 
Anyway, at least for `LCH()`, we could, much as in `rgb()`, require authors to either use units for all components or for none: 

lch() = lch( <number>{3} | [<percentage> && <number> && <angle>] [ / <alpha-value> ]? )

This would also make it possible to use the alternate HLC order of components (like HSL). This is impossible with `<hue>`, although it would work with `<angle>` if chroma always follows lightness:

lch() = lch( <number>{3} | [<number>{2} && <angle>] [ / <alpha-value> ]? )

Chroma C could also be normalized to a percentage, e. g. with 0 = 0% and 255 = 100%, which is well above the actual encountered maximum chroma value of about 230, but this would be very unconventional. 

By the way, `lab()` and `lch()` do not link to their definitions in heading 8.1, whereas all other color functions do. Also, in [Lab to LCH conversion](https://drafts.csswg.org/css-color/#lab-to-lch) and in the informative [sample code](https://drafts.csswg.org/css-color/#color-conversion-code), one could use `C = hypot(a, b)`. 

GitHub Notification of comment by Crissov
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/278#issuecomment-549067321 using your GitHub account
Received on Saturday, 2 November 2019 18:04:54 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:56 UTC