Skip to content

[css-properties-values-api] Computed value substitution #792

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

Closed
andruud opened this issue Aug 13, 2018 · 2 comments
Closed

[css-properties-values-api] Computed value substitution #792

andruud opened this issue Aug 13, 2018 · 2 comments

Comments

@andruud
Copy link
Member

andruud commented Aug 13, 2018

The spec does currently not describe any change to the var() substitution behavior. Hence I have been operating under the assumption that it works like in css-variables, except that instead of always substituting the specified value, you substitute a "synthetic" token stream equivalent to the computed value described in 2.4.

However, after reading issue #321, I think the spec definitely needs to deal with this explicitly.

<!-- --x is registered as <length> (inherited) -->
<div style="font-size: 10px; --x: 2em;">
  <div style="font-size: 1px; height: var(--x);" id=inner></div>
</div>

What is the computed value of height on #inner in the example above? If we follow the current spec without reading between the lines, it's 2px. Probably, what we want is 20px. In any case, the spec should mention the correct behavior.

@tabatkins
Copy link
Member

I really want the typed value to be grammar-checked when subbed into real (or registered custom) properties, but I don't think I can reasonably do that without a ton of complexity. Combined with the resolution that registering a property must not cause a reparse of the stylesheet (any custom properties whose values violate the now-registered grammar just trigger invalid-at-computed-value-time), I think this is literally impossible to do.

I think I need to go back on my intent from #321 and just say that all custom properties substitute via token streams, regardless of registration status. The grammar just gives you a lot of useful abilities since we know the value's type (IDE/styleMap.set() error checking, computed value absolutization, animation, TypedOM representation...), but otherwise doesn't alter the behavior of variables.

However! I don't want to say that they retain their original token streams - that's an additional storage cost that's rather annoying, not to mention confusing in cases like what you provided. I need to instead define how to token-stream-ize a registered value, so it can be substituted in a reasonable manner.

Your example, then, would compute --x to a 20px value, which would then token-stream as a 20px dimension token, making the child's height 20px.

@andruud
Copy link
Member Author

andruud commented Jun 13, 2019

Now described by 4.5. Substitution, closing.

@andruud andruud closed this as completed Jun 13, 2019
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

2 participants