@@ -9,7 +9,13 @@ ED: https://drafts.csswg.org/css-nesting/
99Editor : Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199
1010Editor : Adam Argyle, Google, https://nerdy.dev, w3cid 112669
1111Abstract : This module introduces the ability to nest one style rule inside another, with the selector of the child rule relative to the selector of the parent rule. This increases the modularity and maintainability of CSS stylesheets.
12- Link Defaults : css-color-4 (property) color
12+ </pre>
13+
14+ <pre class=link-defaults>
15+ spec:css-color-4; type:property; text:color
16+ spec:cssom-1; type:dfn;
17+ text:child css rules
18+ text:specified order
1319</pre>
1420
1521<h2 id="intro">
@@ -28,17 +34,6 @@ Module Interactions</h3>
2834 This module introduces new parser rules that extend the [[!CSS21]] parser model.
2935 This module introduces selectors that extend the [[SELECTORS4]] module.
3036
31- <pre class=idl>
32- [Exposed=Window]
33- interface CSSNestingRule : CSSRule {
34- attribute CSSOMString selectorText;
35- [SameObject] readonly attribute CSSRuleList cssRules;
36- [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
37- unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
38- undefined deleteRule(unsigned long index);
39- };
40- </pre>
41-
4237<h3 id="values">
4338Values</h3>
4439
@@ -256,8 +251,8 @@ Direct Nesting {#direct}
256251
257252 // and
258253
259- .foo {
260- color: blue;
254+ .foo {
255+ color: blue;
261256 padding: 2ch;
262257 }
263258 */
@@ -328,7 +323,7 @@ Direct Nesting {#direct}
328323 color: red;
329324 &&.bar { color: blue; }
330325 }
331- /* Invalid because the second & is no longer
326+ /* Invalid because the second & is no longer
332327 at the start of a compound selector */
333328
334329 .foo {
@@ -449,9 +444,9 @@ Nesting Conditional Rules {#conditionals}
449444 A style rule can have any number of <a>conditional rules</a> inside of it, of any type,
450445 intermixed with any number of declarations, in any order.
451446
452- The presence of a nested conditional engages the same logic as if ''@nest'' was present.
453- The nested conditional rules must contain a <a>nesting selector</a> and follow the same
454- rules as outlined in <a href="#direct">direct nesting</a> .
447+ The presence of a nested conditional engages the same logic as if ''@nest'' was present.
448+ The nested conditional rules must contain a <a>nesting selector</a> and follow the same
449+ rules as outlined in <a href="#direct">direct nesting</a> .
455450
456451 <div class="example">
457452 For example, the following conditional nestings are valid:
@@ -461,17 +456,17 @@ Nesting Conditional Rules {#conditionals}
461456 display: grid;
462457
463458 @media (orientation: landscape) {
464- & {
465- grid-auto-flow: column;
459+ & {
460+ grid-auto-flow: column;
466461 }
467462 }
468463 }
469464 /* equivalent to
470465 .foo { display: grid; }
471466
472467 @media (orientation: landscape) {
473- .foo {
474- grid-auto-flow: column;
468+ .foo {
469+ grid-auto-flow: column;
475470 }
476471 }
477472 */
@@ -480,8 +475,8 @@ Nesting Conditional Rules {#conditionals}
480475 display: grid;
481476
482477 @media (orientation: landscape) {
483- & {
484- grid-auto-flow: column;
478+ & {
479+ grid-auto-flow: column;
485480 }
486481
487482 @media (min-inline-size > 1024px) {
@@ -496,13 +491,13 @@ Nesting Conditional Rules {#conditionals}
496491 .foo { display: grid; }
497492
498493 @media (orientation: landscape) {
499- .foo {
500- grid-auto-flow: column;
494+ .foo {
495+ grid-auto-flow: column;
501496 }
502497 }
503498
504499 @media (orientation: landscape) and (min-inline-size > 1024px) {
505- .foo {
500+ .foo {
506501 max-inline-size: 1024px;
507502 }
508503 }
@@ -513,7 +508,7 @@ Nesting Conditional Rules {#conditionals}
513508
514509 @media (min-width: 480px) {
515510 & > .bar,
516- & > .baz {
511+ & > .baz {
517512 color: blue;
518513 }
519514 }
@@ -522,7 +517,7 @@ Nesting Conditional Rules {#conditionals}
522517 .foo { color: red; }
523518
524519 @media (min-width: 480px) {
525- .foo > :is(.bar, .baz) {
520+ .foo > :is(.bar, .baz) {
526521 color: blue;
527522 }
528523 }
@@ -543,7 +538,7 @@ Nesting Conditional Rules {#conditionals}
543538
544539 .foo {
545540 color: red;
546-
541+
547542 @media (min-width: 480px) {
548543 & h1, h2 { color: blue; }
549544 }
@@ -553,12 +548,12 @@ Nesting Conditional Rules {#conditionals}
553548
554549 .foo {
555550 color: red;
556-
551+
557552 @nest @media (min-width: 480px) {
558553 & { color: blue; }
559554 }
560555 }
561- /* Invalid because @nest expects a selector prelude,
556+ /* Invalid because @nest expects a selector prelude,
562557 instead a conditional rule was provided */
563558 </pre>
564559 </div>
@@ -571,15 +566,15 @@ Mixing Nesting Rules and Declarations {#mixing}
571566 intermixed with any number of declarations,
572567 in any order.
573568
574- The relative ordering of <a>nested style rules</a> , <a>nested conditional rules</a> and
569+ The relative ordering of <a>nested style rules</a> , <a>nested conditional rules</a> and
575570 other declarations <strong> is</strong> important;
576571 it's possible for a given style rule and a <a>nested style rule</a> within it to match the same element,
577572 and if the specificity of the two rules is otherwise equivalent,
578573 the relative order in the stylesheet of the applicable declarations
579574 determines which declaration "wins" the <a>cascade</a> .
580575
581576 <div class="example">
582- For example, consider the following where the specificity is the same and the
577+ For example, consider the following where the specificity is the same and the
583578 cascade is used for value resolution:
584579
585580 <pre class="lang-css">
@@ -626,9 +621,9 @@ Mixing Nesting Rules and Declarations {#mixing}
626621 <!-- div text color is blue -->
627622 </pre>
628623
629- ''article :is(.blue, #gotcha)'' now has a specificity score of (1,1,1).
630- Nesting uses '':is()'' which assumes the specificity of it's highest selector.
631-
624+ ''article :is(.blue, #gotcha)'' now has a specificity score of (1,1,1).
625+ Nesting uses '':is()'' which assumes the specificity of it's highest selector.
626+
632627
633628 To work around it, the following could be written instead:
634629
@@ -657,10 +652,92 @@ Mixing Nesting Rules and Declarations {#mixing}
657652 </div>
658653
659654
660- CSS Object Model Modifications {#cssom}
661- =======================================
655+ <!--
656+ ██████ ██████ ██████ ███████ ██ ██
657+ ██ ██ ██ ██ ██ ██ ██ ██ ███ ███
658+ ██ ██ ██ ██ ██ ████ ████
659+ ██ ██████ ██████ ██ ██ ██ ███ ██
660+ ██ ██ ██ ██ ██ ██ ██
661+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
662+ ██████ ██████ ██████ ███████ ██ ██
663+ -->
662664
663- <div class=issue>
664- 1. Add an interface for the @nest rule.
665- 2. Tie into the general work needed to let rules be nested into style rules.
666- </div>
665+ CSSOM {#cssom}
666+ ==============
667+
668+ Modifications to {{CSSStyleRule}} {#cssom-style}
669+ ---------------------------------------------
670+
671+ CSS style rules gain the ability to have nested rules:
672+
673+ <pre class=idl>
674+ partial interface CSSStyleRule {
675+ [SameObject] readonly attribute CSSRuleList cssRules;
676+ unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
677+ undefined deleteRule(unsigned long index);
678+ };
679+ </pre>
680+
681+ The <dfn attribute for=CSSStyleRule>cssRules</dfn> attribute
682+ must return a {{CSSRuleList}} object for the [=CSSRule/child CSS rules=] .
683+
684+ The <dfn method for=CSSStyleRule>insertRule(<var>rule</var>, <var>index</var>)</dfn> method
685+ must return the result of
686+ invoking [=insert a CSS rule=] <var> rule</var>
687+ into the [=CSSRule/child CSS rules=] at <var> index</var> .
688+
689+ The <dfn method for=CSSStyleRule>deleteRule(<var>index</var>)</dfn> method
690+ must [=remove a CSS rule=] from the [=CSSRule/child CSS rules=] at <var> index</var> .
691+
692+
693+ The {{CSSNestingRule}} Interface {#cssom-nesting}
694+ -------------------------------------------------
695+
696+ The {{CSSNestingRule}} interfaces represents a ''@nest'' rule:
697+
698+ <pre class=idl>
699+ [Exposed=Window]
700+ interface CSSNestingRule : CSSRule {
701+ attribute CSSOMString selectorText;
702+ [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
703+ [SameObject] readonly attribute CSSRuleList cssRules;
704+ unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
705+ undefined deleteRule(unsigned long index);
706+ };
707+ </pre>
708+
709+ The <dfn attribute for=CSSNestingRule>selectorText</dfn> attribute,
710+ on getting,
711+ must return the result of [=serialize a group of selectors|serializing=]
712+ the associated [=selector list=] .
713+ On setting the {{CSSStyleRule/selectorText}} attribute these steps must be run:
714+
715+ 1. Run the <a>parse a group of selectors</a> algorithm on the given value.
716+ 2. If the algorithm returns a non-null value replace the associated [=selector list=] with the returned value.
717+ 3. Otherwise, if the algorithm returns a null value, do nothing.
718+
719+ The <dfn attribute for=CSSNestingRule>style</dfn> attribute
720+ must return a {{CSSStyleDeclaration}} object for the style rule,
721+ with the following properties:
722+
723+ <dl>
724+ : [=CSSStyleDeclaration/computed flag=]
725+ :: Unset.
726+ : [=CSSStyleDeclaration/declarations=]
727+ :: The declared declarations in the rule, in <a>specified order</a> .
728+ : [=CSSStyleDeclaration/parent CSS rule=]
729+ :: The <a>context object</a> .
730+ : [=CSSStyleDeclaration/owner node=]
731+ :: Null.
732+ </dl>
733+
734+ The <dfn attribute for=CSSNestingRule>cssRules</dfn> attribute
735+ must return a {{CSSRuleList}} object for the [=CSSRule/child CSS rules=] .
736+
737+ The <dfn method for=CSSNestingRule>insertRule(<var>rule</var>, <var>index</var>)</dfn> method
738+ must return the result of
739+ invoking [=insert a CSS rule=] <var> rule</var>
740+ into the [=CSSRule/child CSS rules=] at <var> index</var> .
741+
742+ The <dfn method for=CSSNestingRule>deleteRule(<var>index</var>)</dfn> method
743+ must [=remove a CSS rule=] from the [=CSSRule/child CSS rules=] at <var> index</var> .
0 commit comments