Skip to content

[css-values-4] Resolve <percentage> representing <number> or <angle> at parse time #9395

Open
@cdoublev

Description

@cdoublev

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:

  • in all color functions as any channel value
  • in opacity, flood-opacity, shape-image-threshold, as an <alpha-value>
  • in transform as an argument of the <scale*()> functions
  • in scale

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 is 1, and the 2nd value if it is the same as the 1st value.

However it is not clear whether 0% 0 100% should serialize with 0% 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):

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.

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

  1. either define explicitly to resolve <percentage> to <number> at parse time (when there is enough information available) or status quo but provide clarifications/examples to serialize scale without optional values and serialize <percentage> with <number> in the related <filter-function>s
  2. fix the above requirement to simplify a math function:
- 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.
+ If `root` is a percentage that will be resolved against another dimension value, and there is enough information available to resolve it, do so, and express the resulting numeric value in the appropriate canonical unit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions