w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.52k stars 673 forks source link

[css-color-4] Expand the concept of analogous components to analogous sets of components to minimize `none` → `0` conversions #10210

Open LeaVerou opened 7 months ago

LeaVerou commented 7 months ago

(This came out of my comment here: https://github.com/w3c/csswg-drafts/issues/10151#issuecomment-2052685363 )

Currently, css-color-4 defines that none values will be carried forward to analogous components. Basically, even when converting to different color spaces, if there are analogous components, they will become none.

Essentially what this does, is attempt to divide the components into rough sets of dependencies and try to preserve author intent as much as possible. Sure, they’re not entirely orthogonal, and e.g. tweaking hue in HSL does affect chroma and lightness in oklch, but it's the lesser of two evils, the other evil being converting none to 0.

To that goal, I can see a few improvements we can make to minimize none0 conversions even more:

  1. Instead of analogous components, word the prose around analogous sets of components. The current analogous components are just sets of size 1.
  2. If two color spaces have analogous components, the components remaining after you remove all analogous components, are an analogous set. Meaning, if Lab L is analogous to OKLch L, this means Lab a,b are analogous to OKLCh c, h., so converting e.g. oklch(50% none none) to lab yields lab(42 none none).
  3. The set of all components is analogous in every color space (basically #10203 )

Not sure if this can be considered editorial, or we'd need WG resolution. @svgeesus ?

LeaVerou commented 6 months ago

I actually just realized a pretty important reason to do this: it means the result can be consistent regardless of the conversion path.

For example, let’s take a conversion from sRGB to LCh. The conversion path using XYZ D65 as a connection space is as follows: sRGB → Linear sRGB → XYZ D65 → XYZ D50 → Lab → LCH

Suppose we’re converting white. white in XYZ D50 is color(xyz-d50 0.9643 1 0.8251) which is lab(100 none none). a and b have no analogous components, so when converted to LCh they are converted to lch(100 0 0). However, if we consider them an analogous set, then can be converted to lch(100 none none).

css-meeting-bot commented 5 months ago

The CSS Working Group just discussed [css-color-4] Expand the concept of analogous components to analogous sets of components to minimize `none` → `0` conversions, and agreed to the following:

The full IRC log of that discussion <fantasai> lea: mapping between components of analogous color spaces is well-defined in the spec
<fantasai> lea: e.g. mapping green to green, ligthness to lightness, etc.
<fantasai> lea: if analogous component exists in other color space, after conversion none is preserved
<fantasai> lea: we convert none to zero, and then convert, and then put none back
<fantasai> lea: want to expand the idea
<fantasai> lea: if lightness is none and convert from labl to oklch
<fantasai> lea: lightness is still none
<fantasai> lea: but if lightness is a specific number and a/b are none they would become zero
<fantasai> lea: what this concept defines is .. if you split the components into sets that correspond
<fantasai> lea: then what remains is also analogous
<fantasai> lea: so a+b is analogous to c+h
<fantasai> lea: this mainly makes a difference for lab to lch
<fantasai> lea: or colors where all are none
<fantasai> lea: that would be an analogous set
<fantasai> lea: that's logically consistent
<dbaron> makes sense
<fserb> q+
<lea> q?
<fantasai> fserb: will you describe in the spec in those terms, or actually list all the combinations?
<ChrisL> I think these analogous sets make sense
<dbaron> (it doesn't sound to me like there's much of an explosion... I think)
<fantasai> lea: combinatorial explosion. So anything that remains after subtracting the analogous components is (as a set) an analogous component
<lea> PROPOSED RESOLUTION: Expand concept of analogous components to analogous *sets* of components.
<fantasai> PROPOSED: The components that remain after removing the anlogous components are (as a set) an analogous component.
<dbaron> (including all components being none being analogous for all color spaces)
<fserb> +1
<fantasai> RESOLVED: Also any set of analogous components are