[csswg-drafts] [css-values-4][css-color-4] Resolve `<percentage>` to `<number>` as a color component in math functions (#8485)

cdoublev has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values-4][css-color-4] Resolve `<percentage>` to `<number>` as a color component in math functions ==
The definitions of `rgb()`, `rgba()`, `hsl()`, `hsla()`, has recently received [two](https://github.com/w3c/csswg-drafts/commit/8a7728f0fd26cd4c849a18f1e000a85e975f2adf) [modifications](https://github.com/w3c/csswg-drafts/commit/3e7df1c6cbfa1f97b2b323bc2dc6a30273ab0f5e) in CSS Color 4 (not yet visible online at this time), which allow to mix `<number>` and `<percentage>` arguments. Basically:

```
rgb() = rgb(<number>{3}) | rgb(<percentage>{3}) # Before
rgb() = rgb([<number> | <percentage>]{3})       # After
```

With the new syntax, my problem is that `calc(100%)` now resolves to `1`.

CSS Values 4 defines the [simplification](https://drafts.csswg.org/css-values-4/#simplify-a-calculation-tree) of a mathematical function representing `<percentage>`:

  > 1. If `root` is a numeric value:
  >    - If `root` is a percentage that will be resolved against another value, and there is enough information available to resolve it, do so, and express the resulting numeric value in the appropriate canonical unit. Return the value.
  >    - [...]
  >    - Otherwise, return `root`.
  >
  > [...] However, "raw" percentages—ones which do not resolve against another value, such as in `opacity`—might not block simplification.

To find out if I can resolve a `root` percentage, I am currently looking for `<number> | <percentage>` or `<integer> | <percentage>` (in any order) as contexts, therefore `calc(100%)` is not resolved in `rgb()` defined with the syntax that does not mix `<number>` and `<percentage>`.

CSS Color 4 does not require to resolve `<percentage>` in `rgb()` and `rgba()` (aside: it is required for non-sRGB color functions), but requires to serialize it as a base 10 `<number>` in the range [0-255].

  > For compatibility, the sRGB component values are serialized in `<number>` form, not `<percentage>`. Also for compatibility, the component values are serialized in base 10, with a range of [0-255], regardless of the bit depth with which they are stored.

In Chrome/FF, `rgb(calc(100%) 0% 0%)` serializes to `rgb(255, 0, 0)` as a specified value.

I am not sure if the right way to solve my problem is to consider that there is not enough information to resolve a percentage in a math function as an argument of `rgb()` and `rgba()`, regardless of their syntax (separated/mixed `<number>` and `<percentage>`). This would mean that determining if *there is enough information to resolve it* as a `<number>` cannot be simply based on if the context is `<number> | <percentage>` or `<integer> | <percentage>`.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8485 using your GitHub account


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

Received on Wednesday, 22 February 2023 09:26:35 UTC