Skip to content

[css-typed-om] What does lack of range restriction imply about serialization? #574

Closed
@dbaron

Description

@dbaron

The section on CSSNumericValue says:

CSSNumericValue objects are not range-restricted. Any valid numeric value can be represented by a CSSNumericValue, and that value will not be clamped, rounded, or rejected when set on a declared StylePropertyMap or inline StylePropertyMap. Instead, clamping and/or rounding will occur during computation of style.

(It then proceeds to give an example demonstrating this.)

What this doesn't seem to address is what implications this has for CSS's existing object model APIs that involve serialization. It's long been a principle of these APIs that they always give output that is valid CSS. This means that, for example, getting element.style.cssText, modifying it, and setting it back to element.style.cssText should change only the thing that was modified. Likewise for getPropertyValue and setProperty, or the element.style.propertyName that is equivalent to them. However, the rules for these setters require following the rules of CSS parsing and dropping any declarations that are not valid. This means that serializing things that don't round-trip correctly would break anything that depends on this round-tripping.

It seem like there are a bunch of bad options here (listed in the order that seems best to worst to me at first glance, although I'm sure I'm missing many considerations):

  • serialize CSSUnitValue that are out-of-range as calc() expressions
  • not do the thing quoted above, but instead do rejection of CSSNumericValues when they're set in some cases
  • serialize all CSSUnitValue as calc() expressions
  • break round-tripping as the spec currently does

I tried to look through the spec to see if one of these options was specified later, but I didn't see anything. If there is something I missed, it would be good to have a pointer to it from this section.

It's also entirely possible that the WG has discussed this and I've forgotten (or missed it).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions