-
Notifications
You must be signed in to change notification settings - Fork 142
[css-properties-values-api] Substituting registered properties with var() #321
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
Comments
(nit: as of TPAC, unregistered properties are substituted as strings, not lists of tokens). It's interesting that there are two truthy-feeling principles opposed here:
(1 means roughly that you shouldn't ever be able to have
and I don't really know what to do here. It does seem deeply weird for the variable to not resolve relative to the variable sheet when you know up-front that it is a url(). |
No, this is inaccurate. (It would be crazy wrong taken literally as you said.) Untyped properties have their values preserved as literal strings, such that their serialization is identical to their input. They're definitely substituted as token streams, tho; otherwise you get very quirky parsing things where a single token can span across two var() substitutions. Typed properties actually have typed values, tho, and get substituted as such. So your first and second examples should both be errors (height doesn't take numbers, animation-name doesn't take colors), your third should work as long as it's a correct number of lengths, and your fourth is fine. The problem of url() resolution changing when the custom property switches from untyped to typed has already been brought up, and there's no good solution. I think the naive answer (typed properties resolve based on the sheet they show up in, just like any other property taking a url) is obviously correct; anything else means that typed custom properties have subtle (read: likely to cause bugs) differences from built-in properties. There's some potential bugs if people switch from untyped to typed, but that should hopefully go away as usage becomes greater. |
I don't think the third example works without a lot of extra effort. Box shadow won't take a list of lengths in the typed OM, it'll take a special typed object. Is there a reason we decided that typed properties can't fallback to untyped substitution? For example I think typed properties should still substitute into untyped custom properties? I remember we had a discussion around this back in Sydney in January but I don't remember the details. |
Right, we're not talking about Typed OM here. What we've got instead is that, per the grammar of --length-list (presumably
I don't recall. They should be able to sub into untyped properties; I imagine they'd get down-converted back into some equivalent token representation. This isn't well-specced. |
We should maintain a correspondence between types in the Typed OM and the behavior of typed properties, anything else would be weird. |
I'm confused. The deal with Typed OM is that we're designing things such that every property takes exactly one value, or a list of values; when the "value" is complex, we have a custom JS type to express it. That's a good design on the JS side, but has nothing to do with the CSS side of things, where properties take several values of various types. In CSS, box-shadow takes a color, a keyword, and some lengths. |
It's fine to use typed custom properties to define part of a complex value, but I don't think we should do things like "let this generic list of lengths substitute into a place that needs a definite number of lengths". Instead we should have a type that represents that subcomponent, and use that. |
Just to clarify, is this thread discussing whether giving a type of a property does:
or
If that is the case: I remember my initial custom properties spec had something close to (b) to validate As such, I would lean towards (a) given the current design of |
Actually, that's an oversight; we just didn't think of that case. We should definitely validate the fallback against the registered grammar, and mark the var() as invalid when it fails (making the property invalid at parse-time). |
Ok, in that case I have no opinion on the matter. |
Is this intended for Level 1? In Gecko, it would be straightforward to implement this sort of typed substitution for properties like |
The original issue (should a property fail at parse-time if a typed custom property is used in a wrong way, per the property's grammar) is, I think, a no. I believe this falls out of our decision at the Seattle f2f (#354) that registering a custom property shouldn't require an immediate global re-parse. You can do wrong things to/with a typed custom property; it'll just cause a failure at computed-value time, like an untyped custom property with an incompatible value does. The later issue (should we validate the |
…ntax-checked at computed-value time, not parse time. Clarify that the `syntax` field is used during computed-value time, write in the section about calculation of computed values that declarations can be found invalid at computed-value time, and update the example which previously indicated syntax-checking at parse time. Per Seattle resolution, as expressed in the following comments: > The original issue (should a property fail at parse-time if a typed > custom property is used in a wrong way, per the property's grammar) is, > I think, a no. I believe this falls out of our decision at the Seattle > f2f (w3c#354) that registering a custom property shouldn't require an > immediate global re-parse. You can do wrong things to/with a typed > custom property; it'll just cause a failure at computed-value time, like > an untyped custom property with an incompatible value does. > > - w3c#321 (comment) > Further clarification: per Seattle resolution, when using a typed > property in a stylesheet, setting to an invalid value doesn't trigger > fallback ... > > - w3c#354 (comment)
…ntax-checked at computed-value time, not parse time. Clarify that the `syntax` field is used during computed-value time, write in the section about calculation of computed values that declarations can be found invalid at computed-value time, and update the example which previously indicated syntax-checking at parse time. Per Seattle resolution, as expressed in the following comments: > The original issue (should a property fail at parse-time if a typed > custom property is used in a wrong way, per the property's grammar) is, > I think, a no. I believe this falls out of our decision at the Seattle > f2f (w3c#354) that registering a custom property shouldn't require an > immediate global re-parse. You can do wrong things to/with a typed > custom property; it'll just cause a failure at computed-value time, like > an untyped custom property with an incompatible value does. > > - w3c#321 (comment) > Further clarification: per Seattle resolution, when using a typed > property in a stylesheet, setting to an invalid value doesn't trigger > fallback ... > > - w3c#354 (comment)
Are registered properties substituted as lists of tokens as per css-variables or as some sort of parsed representation? There are some cases where values can be parsed as different types so this affects whether the end value parses successfully, e.g.
--number: 0; height: var(--number);
--color: green; animation-name: var(--color);
--length-list: 5px 10px 20px; box-shadow: green var(--length-list);
--url: url(a.png); background-image: var(--url); /* <image> values can be <url> values so this should be valid */
For the last case, if the declarations are in separate files, do we resolve <url>/<image> types with a base URL from the sheet with variable declaration or the usage thereof? When these are not registered, it seems that we should use the "background-image" sheet (crbug.com/618165#c11) but doing this for a registered custom property means the custom property has a different computed value to where it's used.
The text was updated successfully, but these errors were encountered: