Skip to content

[css-typed-om-1] Should css typed om support the same simplifications as css-values-4? #9451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
danielsakhapov opened this issue Oct 10, 2023 · 4 comments

Comments

@danielsakhapov
Copy link
Contributor

So, the question is should https://drafts.css-houdini.org/css-typed-om-1/ support the same simplifications (like distributing multiplication over sum and sorting the dimensions alphabetically) as css-values-4? Like https://drafts.csswg.org/css-values-4/#calc-simplification and https://drafts.csswg.org/css-values-4/#sort-a-calculations-children?

@andruud andruud added the css-values-4 Current Work label Oct 12, 2023
@andruud
Copy link
Member

andruud commented Oct 12, 2023

Reading the specs, this is what it looks like to me:

  • cssom/css-values simplifies during parsing. (E.g. distribution, but not sorting).
  • cssom/css-values sorts by unit during serialization.

However:

  • css-typed-om does not simplify during "create an internal representation".
  • css-typed-om does not sort by unit during reification.

So this means:

  • Any internal representation you create from a CSSMathValue is the same thing you get when it's reified back. It's not simplified nor sorted. (Specified values).
  • An internal representation produced from parsing, will be simplified (but not sorted), and so it will reify as the simplified structure (again, unsorted).
  • An internal representation produced from a CSSMathValue will be sorted when serialized (cssom/css-values), but not simplified.

This is a mess, but I think we can make it more sane if we do one of the following:

In any case, preserving CSSMathValue-produced values as-is seems like nice behavior worth maintaining.

cc @tabatkins

@tabatkins
Copy link
Member

The behavior is well-defined across the specs. Simplification occurs at parse-time, and when transitioning between some value stages (specified->computed, computed->used).

Typed OM represents a value at one of these stages; whatever the form is at that moment is what it should be reflected as in the Typed OM. If you build one yourself, no simplification happens on the object graph (but once you assign it to a property, the internal value will be simplified as normal).

(The "create an internal representation" algo in Typed OM is a bit too handwavey, and could use some editorial tweaking, tho. I'll untag this from Values and leave it as a Typed OM issue.)

@andruud
Copy link
Member

andruud commented Oct 24, 2023

but once you assign it to a property, the internal value will be simplified as normal

OK, it sounds like you're really expecting the creation of an internal value (whether that comes from parsing or typed-om or something else) to invoke simplify a calculation tree. Currently, only parsing invokes that, so we're bypassing it with typed-om (for specified values).

We can currently also bypass sorting if we reify via typed-om and serialize the CSSStyleValue. Is that intentional?

@Mstanic05
Copy link

Can you assign this to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants