@@ -9,7 +9,7 @@ import properties from '../properties/definitions.js'
99/**
1010 * @see {@link https://drafts.csswg.org/css-conditional-3/#conditional-group-rule }
1111 */
12- const conditionalGroupRuleNames = [
12+ const conditionalRuleNames = [
1313 '@container' ,
1414 '@media' ,
1515 '@supports' ,
@@ -18,24 +18,43 @@ const conditionalGroupRuleNames = [
1818/**
1919 * @see {@link https://drafts.csswg.org/css-nesting-1/#nested-group-rules }
2020 */
21- const nestedGroupRuleNames = [
22- '@container' ,
21+ const groupRuleNames = [
22+ ... conditionalRuleNames ,
2323 '@layer' ,
24- '@media' ,
2524 '@scope' ,
2625 '@starting-style' ,
2726 '@style' ,
28- '@supports' ,
2927]
3028
31- // Populated at the bottom of this file
32- const conditionalGroupRules = [ ]
33- const nestedConditionalRulesInsideFunction = [ ]
34- const nestedGroupRules = [ ]
29+ /**
30+ * @see {@link https://drafts.csswg.org/css-mixins-1/#at-ruledef-function }
31+ */
32+ const functionRule = {
33+ cssom : 'CSSFunctionRule' ,
34+ elemental : true ,
35+ name : '@function' ,
36+ prelude : '<custom-function-definition>' ,
37+ type : 'rule' ,
38+ value : {
39+ descriptors : descriptors [ '@function' ] ,
40+ name : '<declaration-rule-list>' ,
41+ rules : [ {
42+ cssom : 'CSSFunctionDeclarations' ,
43+ elemental : true ,
44+ name : '@declarations' ,
45+ type : 'rule' ,
46+ value : {
47+ descriptors : descriptors [ '@function' ] ,
48+ name : '<declaration-list>' ,
49+ type : 'arbitrary' ,
50+ } ,
51+ } ] ,
52+ type : 'arbitrary' ,
53+ } ,
54+ }
3555
3656/**
3757 * @see {@link https://drafts.csswg.org/css-syntax-3/#style-rule }
38- * @see {@link https://drafts.csswg.org/css-nesting-1/#nesting }
3958 */
4059const styleRule = {
4160 cascading : true ,
@@ -48,28 +67,26 @@ const styleRule = {
4867 value : {
4968 name : '<declaration-rule-list>' ,
5069 properties,
51- rules : nestedGroupRules ,
70+ rules : [ {
71+ cascading : true ,
72+ cssom : 'CSSNestedDeclarations' ,
73+ elemental : true ,
74+ name : '@declarations' ,
75+ type : 'rule' ,
76+ value : {
77+ name : '<declaration-list>' ,
78+ properties,
79+ type : 'arbitrary' ,
80+ } ,
81+ } ] ,
5282 type : 'arbitrary' ,
5383 } ,
5484}
55- const nestedStyle = { ...styleRule , prelude : '<relative-selector-list>' }
5685
5786/**
58- * @see {@link https://drafts.csswg.org/css-mixins -1/#at-ruledef-function }
87+ * @see {@link https://drafts.csswg.org/css-nesting -1/#nested-style-rule }
5988 */
60- const functionRule = {
61- cssom : 'CSSFunctionRule' ,
62- elemental : true ,
63- name : '@function' ,
64- prelude : '<custom-function-definition>' ,
65- type : 'rule' ,
66- value : {
67- descriptors : descriptors [ '@function' ] ,
68- name : '<declaration-rule-list>' ,
69- rules : nestedConditionalRulesInsideFunction ,
70- type : 'arbitrary' ,
71- } ,
72- }
89+ const nestedStyle = { ...styleRule , prelude : '<relative-selector-list>' }
7390
7491const topLevelRules = [
7592 /**
@@ -312,36 +329,51 @@ const topLevelRules = [
312329 descriptors : descriptors [ '@page' ] ,
313330 name : '<declaration-rule-list>' ,
314331 properties : pageProperties ,
315- rules : [ {
316- cascading : true ,
317- cssom : 'CSSMarginRule' ,
318- elemental : true ,
319- name : '@margin' ,
320- names : [
321- '@bottom-center' ,
322- '@bottom-left' ,
323- '@bottom-left-corner' ,
324- '@bottom-right' ,
325- '@bottom-right-corner' ,
326- '@left-bottom' ,
327- '@left-middle' ,
328- '@left-top' ,
329- '@right-bottom' ,
330- '@right-middle' ,
331- '@right-top' ,
332- '@top-center' ,
333- '@top-left' ,
334- '@top-left-corner' ,
335- '@top-right' ,
336- '@top-right-corner' ,
337- ] ,
338- type : 'rule' ,
339- value : {
340- name : '<declaration-list>' ,
341- properties : pageMarginProperties ,
342- type : 'arbitrary' ,
332+ rules : [
333+ {
334+ cascading : true ,
335+ cssom : 'CSSMarginRule' ,
336+ elemental : true ,
337+ name : '@margin' ,
338+ names : [
339+ '@bottom-center' ,
340+ '@bottom-left' ,
341+ '@bottom-left-corner' ,
342+ '@bottom-right' ,
343+ '@bottom-right-corner' ,
344+ '@left-bottom' ,
345+ '@left-middle' ,
346+ '@left-top' ,
347+ '@right-bottom' ,
348+ '@right-middle' ,
349+ '@right-top' ,
350+ '@top-center' ,
351+ '@top-left' ,
352+ '@top-left-corner' ,
353+ '@top-right' ,
354+ '@top-right-corner' ,
355+ ] ,
356+ type : 'rule' ,
357+ value : {
358+ name : '<declaration-list>' ,
359+ properties : pageMarginProperties ,
360+ type : 'arbitrary' ,
361+ } ,
343362 } ,
344- } ] ,
363+ {
364+ cascading : true ,
365+ cssom : 'CSSPageDeclarations' ,
366+ elemental : true ,
367+ name : '@declarations' ,
368+ type : 'rule' ,
369+ value : {
370+ descriptors : descriptors [ '@page' ] ,
371+ name : '<declaration-list>' ,
372+ properties : pageProperties ,
373+ type : 'arbitrary' ,
374+ } ,
375+ } ,
376+ ] ,
345377 type : 'arbitrary' ,
346378 } ,
347379 } ,
@@ -361,7 +393,7 @@ const topLevelRules = [
361393 } ,
362394 } ,
363395 /**
364- * @see {@link https://drafts.css-houdini.org/css-properties-values-api/#at-property-rule }
396+ * @see {@link https://drafts.css-houdini.org/css-properties-values-api/#at-ruledef-property }
365397 */
366398 {
367399 cssom : 'CSSPropertyRule' ,
@@ -437,25 +469,28 @@ const topLevelRules = [
437469
438470const styleSheetRules = topLevelRules . filter ( ( { name } ) => name !== '@import' && name !== '@namespace' )
439471
440- // Define conditional group rules
441- conditionalGroupRuleNames . forEach ( name =>
442- conditionalGroupRules . push ( styleSheetRules . find ( rule => rule . name === name ) ) )
443-
444- // Define nested conditional rules inside @function
445- conditionalGroupRules . forEach ( rule =>
446- nestedConditionalRulesInsideFunction . push ( { ... rule , elemental : true , value : functionRule . value } ) )
472+ // Define conditional rules inside @function
473+ conditionalRuleNames . forEach ( name =>
474+ functionRule . value . rules . push ( {
475+ ... styleSheetRules . find ( rule => rule . name === name ) ,
476+ elemental : true ,
477+ value : functionRule . value ,
478+ } ) )
447479
448- // Define nested group rules inside style rules
449- nestedGroupRuleNames . forEach ( name => {
480+ // Define group rules inside style rules and at the top-level
481+ groupRuleNames . forEach ( name => {
450482 const rule = styleSheetRules . find ( rule => rule . name === name )
483+ // Skip @layer statement
451484 if ( name === '@layer' && ! rule . value ) {
452485 return
453486 }
487+ // Nested in style rules
454488 if ( name === '@style' ) {
455- nestedGroupRules . push ( nestedStyle )
489+ styleRule . value . rules . push ( nestedStyle )
456490 return
457491 }
458- nestedGroupRules . push ( { ...rule , cascading : true , elemental : true , value : styleRule . value } )
492+ styleRule . value . rules . push ( { ...rule , cascading : true , elemental : true , value : styleRule . value } )
493+ // At the top-level
459494 if ( name === '@scope' ) {
460495 rule . value . rules . push ( ...styleSheetRules . filter ( rule => rule !== styleRule ) , nestedStyle )
461496 } else {
0 commit comments