Open cdoublev opened 1 year ago
Related: #5642. Because if you resolve <percentage>
to <number>
before/while serializing, I think you open the door to resolving other static values.
However a
<number>
has no canonical unit
Okay, technically I don't define that numbers have a canonical unit, because they don't have a unit at all (or they all use the null unit). But this is English, not C++; I think it's clear enough from context what "expressed in its canonical unit" means for numbers (aka, no-op).
<percentage>
and<number>
cannot be combined
While percentages and numbers cannot be combined, as in added/subtracted, you can absolutely have a percentage that resolves against a number.
I don't have a particular opinion on whether we should specify that %s are eagerly simplified at parse time when resolved against numbers. I'd be fine with that, or with trying to get impls to align on only simplifying at computed-value and used-value time (except for the color function exception we've already talked about).
Agenda+ to decide this.
The CSS Working Group just discussed [css-values-4] Resolve `<percentage>` representing `<number>` or `<angle>` at parse time
, and agreed to the following:
RESOLVED: % that are resolved against numbers do that at parse time
Can you please provide an answer for <percentage>
resolved to <angle>
? The question would also apply for any dimension that can be represented as a percentage, but there is no existing case.
For example, should the specified value of conic-gradient(blue 50%, yellow)
be conic-gradient(blue 180deg, yellow)
? Should the specified value of conic-gradient(blue calc(25% + 90deg), yellow)
be conic-gradient(blue calc(180deg), yellow)
?
Note: browsers do not seem to support combining <angle>
and <percentage>
in math functions at the moment.
Is it fine to assume that <percentage>
is resolved before simplifying a calculation tree? This would mean that its step 1.1 (resolve <percentage>
) is not required.
Fwiw, if they cannot be preserved within specified values, I would have preferred percentages to be resolved at serialization time vs. parse time wherever interop requires it, which I assume would imply that 25% + 90deg
would not be simplified, and omitting default number values resolved from percentages to be clarified wherever required.
Can you please provide an answer for
resolved to ?
The spec already defines how percentages relative to another value resolve (step 1.1 of the simplification algo). So, yes, if you used calc(50%)
in conic-gradient()
, it would simplify into calc(180deg)
at computed-value time.
Whether a naked (non-calc()-wrapped) percentage turns into an angle is defined by the context it's in (tho we often forget to explicitly define this stuff). Usually we absolutize values and resolve percentages if possible, at computed-value time. It does look like conic-gradient() doesn't define this, tho.
So <percentage>
representing <number>
is resolved at parse time, but <percentage>
representing <angle>
remains resolved at computed value time. Assuming 1%
is always equal to 3.6deg
, it seems inconsistent but... ok!
Context
There appears to be almost perfect browser interop and consistency between specs for serializing a
<percentage>
with a<number>
as a component of a specified value:opacity
,flood-opacity
,shape-image-threshold
, as an<alpha-value>
transform
as an argument of the<scale*()>
functionsscale
The exception is in
filter
as an argument of some<filter-function>
s, because Filter Effects does not require this.Problem 1
In
scale
, which is defined with[<number> | <percentage>]{1,3}
, the 3rd value must be omitted if it is1
, and the 2nd value if it is the same as the 1st value.However it is not clear whether
0% 0 100%
should serialize with0%
or something else, because it is not clearly defined when<percentage>
should be resolved.Serializing
0
requires to resolve the 1st and 3rd values before trying to omit the 2nd value. Serialization is not "atomic".Problem 2
CSS Values requires to try resolving a
<percentage>
in a math function (emphasize added):However a
<number>
has no canonical unit, and<percentage>
and<number>
cannot be combined, therefore a percentage will always be simplified down to a single value. It does not need to be resolved to a<number>
, except for sRGB color functions.<angle>
is the only other numeric type that can be mapped from a<percentage>
at parse time. The only context<angle-percentage>
values appear is<conic-gradient()>
and browsers do not resolve them.Suggestions
<percentage>
to<number>
at parse time (when there is enough information available) or status quo but provide clarifications/examples to serializescale
without optional values and serialize<percentage>
with<number>
in the related<filter-function>
s