Opening this as requested by @astearns
In #8738 we resolved to stop hoisting interleaved declarations and introduce an @nest
rule that means "exactly the same thing as the parent" instead of wrapping in :is()
, which is how interleaved declarations will be represented in the CSS OM. Since we were not able to get consensus on the specifics, but we had consensus that any solution along these lines is better than the status quo, we agreed that Tab would spec whatever (commit here), and we'd discuss the details later, since fixing the specifics is more web compatible than changing the current behavior after even longer.
Note
An interleaved declaration is a declaration that comes after one or more nested rules.
The issues around which we could not reach consensus were:
@nest
and it’s only introduced to represent interleaved declarations and rules, should they even be able to?@nest
rules are magically added around interleaved declarations should they also be removed during serialization?
.cssText
)?@nest
rule? What if we simply use the existing CSSStyleDeclaration
object to represent interleaved rules? (proposed by @mdubet)setProperty()
work if we go with one of the designs that involve more magic?rule.style
?These are not orthogonal decisions: it seems clear that if @nest
serializes to include an actual @nest {}
rule, that @nest
rule needs to also be valid author code. So essentially there are three possible designs:
@nest
(proposed by @tabatkins, supported by @emilio @andruud @Loirooriol): The rule is automatically added around interleaved declarations, but there is no more magic besides that.@nest
(proposed by @LeaVerou, supported by @fantasai @astearns): The rule becomes a CSS OM detail, with no corresponding CSS syntax, and is removed on serialization (regardless of how serialization happens).@nest
, just CSSStyleDeclaration
in the CSSOM (proposed by @mdubet, supported by @LeaVerou @fantasai).
.cssRules
will also return non-rules? Would .insertRule()
also accept CSSStyleDeclaration
?For 2 and 3, there are also design variations based on the answer to 4 and 5 above.
My position:
@nest
or make it an internal detail. That said, there could conceivably be use cases for it. E.g. one of the problems with IACVT is that fallbacks are thrown away by the time the declaration becomes invalid. What if this was a way to preserve fallbacks?@nest
is functionally equivalent to CSSStyleDeclaration
and we should not be introducing new interfaces with philosophical purity being the only motivation (i.e. "but otherwise .cssRules
would be returning a non-rule?!?")setProperty()
on the base rule should just work, without them having to do tree walking to find the last nested rule. Like, setProperty()
is an incredibly common operation, and an API where calls to setProperty()
have no effect are exactly the kind of dreadful APIs that make utility libraries proliferate.So I would propose a design that would minimize author exposure to all of this, and would just try to do what's reasonable when reading and modifying the CSS OM:
.cssRules
would contain CSSStyleDeclaration
objects with interleaved declarationsinsertRule()
would accept CSSStyleDeclaration
objectsCSSStyleDeclaration
objects would be merged.CSSStyleDeclaration
object cannot be at the start of cssRules
. Inserting one should simply merge the declarations with rule.style
.rule.style
be magic?
One thing I'm ambivalent about is whether rule.style
should be magic too.
This would mean:
rule.style
returns the union of all interleaved declarations (we can introduce another property to only get the non-interleaved ones)rule.style.setProperty()
(and accessors) adds to the last interleaved CSSStyleDeclaration
(if any are present). The third argument is turned into a dictionary with a priority
property and another property (name TBD) to reverse this behavior and actually add it to the first block of declarations.Pros & Cons:
If we decide to avoid magic here, we can make the API more palatable by:
rule
property that returns a CSSStyleDeclaration
for the union of rule.style
and interleaved declarationsrule.setProperty()
method that would add the property at the end of the last interleaved declaration. rule.style.setProperty()
would continue to do what it currently does. Same for removeProperty()
, getPropertyValue()
etc.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3