Re: [csswg-drafts] [css-color] Support all existing (non-legacy?) formats in color()? (#6741)

We were actually discussing this last night with @svgeesus. That even without OKLab and friends,  currently our use of percentages is inconsistent because in Lab `0-100%` maps to `0-100` (1x) whereas in RGB spaces `0-100%` maps to `0-1` (1/100). I see 5 possible solutions, from worst to (IMO) better:

1. Ditch `<percentage>` in `color()` altogether. I'd rather we didn't, it can be quite convenient.
2. Define that `<percentage>` always maps to a specific range (e.g. `0-1`), which will either give us weird numbers for Lab (where `10000%` would be needed to specify 100) or weird numbers for RGB spaces (where `1%` would specify 1). Let's not, this is awful.
3. Adjust the numerical coordinates of spaces so that we can specify percentages with a fixed multiplier. E.g. either make L 0-1 or make RGB coordinates 0-100. Nope nope nope, this is hugely inconsistent with anything else. We need people to be able to copy/paste coordinates from other tools.
4. Make the multiplier a property of the color space, so that percentages in Lab map to 0-100 (for all coordinates) and percentages in RGB spaces to 0-1. This means that for custom color spaces either we pick a multiplier and that's it, or we need to provide a descriptor.
5. Each coordinate of each color space has a reference range, and percentages map to that range. For bounded coordinates, the range is obvious, for unbounded ones like in Lab or OKLCH etc we pick a reasonable one. Perhaps an algorithm for picking the reference range for coord X in color space S could be to calculate the range of S.X for all display-p3 colors, then expand it to the closest round-ish number.

The advantage of 5 is that it makes color formats portable. For example, people can experiment in OKLCH without knowing intimate details about OKLCH because there is already a range they can tap into. It also means they can use `@supports` to provide fallbacks for browsers that don't support color formats, and still get something semi-reasonable. It also gives percentages a distinct advantage over numbers, instead of being slightly weird syntactic sugar. And since the actual numerical coordinates don't change, people can still copy and paste from other tools. It's the best of both worlds.

It would also make it easier to develop meta tools, like color pickers if there's a reference range for every coordinate, so that's useful in its own right.

-- 
GitHub Notification of comment by LeaVerou
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/6741#issuecomment-951785666 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 26 October 2021 10:09:02 UTC