@@ -188,6 +188,7 @@ class Stylesheet {
188188 this . transformMedia ( root , root . rule [ '@media' ] ) ;
189189 this . transformSupports ( root , root . rule [ '@supports' ] ) ;
190190 this . transformContainer ( root , root . rule [ '@container' ] ) ;
191+ this . transformStartingStyle ( root , root . rule [ '@starting-style' ] ) ;
191192
192193 this . transformSimplePseudos ( root , root . rule ) ;
193194 this . transformSelectors ( root , root . rule ) ;
@@ -408,6 +409,11 @@ class Stylesheet {
408409 selectorRule [ '@container' ] ,
409410 conditions ,
410411 ) ;
412+ this . transformStartingStyle (
413+ root ,
414+ selectorRule ! [ '@starting-style' ] ,
415+ conditions ,
416+ ) ;
411417 } ) ;
412418 }
413419
@@ -445,6 +451,11 @@ class Stylesheet {
445451 this . transformLayer ( root , mediaRule ! [ '@layer' ] , conditions ) ;
446452 this . transformSupports ( root , mediaRule ! [ '@supports' ] , conditions ) ;
447453 this . transformContainer ( root , mediaRule ! [ '@container' ] , conditions ) ;
454+ this . transformStartingStyle (
455+ root ,
456+ mediaRule ! [ '@starting-style' ] ,
457+ conditions ,
458+ ) ;
448459 }
449460 }
450461 }
@@ -481,6 +492,11 @@ class Stylesheet {
481492 this . transformLayer ( root , containerRule ! [ '@layer' ] , conditions ) ;
482493 this . transformSupports ( root , containerRule ! [ '@supports' ] , conditions ) ;
483494 this . transformMedia ( root , containerRule ! [ '@media' ] , conditions ) ;
495+ this . transformStartingStyle (
496+ root ,
497+ containerRule ! [ '@starting-style' ] ,
498+ conditions ,
499+ ) ;
484500 } ) ;
485501 }
486502 }
@@ -516,6 +532,11 @@ class Stylesheet {
516532 this . transformMedia ( root , layerRule ! [ '@media' ] , conditions ) ;
517533 this . transformSupports ( root , layerRule ! [ '@supports' ] , conditions ) ;
518534 this . transformContainer ( root , layerRule ! [ '@container' ] , conditions ) ;
535+ this . transformStartingStyle (
536+ root ,
537+ layerRule ! [ '@starting-style' ] ,
538+ conditions ,
539+ ) ;
519540 } ) ;
520541 }
521542 }
@@ -550,6 +571,11 @@ class Stylesheet {
550571 this . transformLayer ( root , supportsRule ! [ '@layer' ] , conditions ) ;
551572 this . transformMedia ( root , supportsRule ! [ '@media' ] , conditions ) ;
552573 this . transformContainer ( root , supportsRule ! [ '@container' ] , conditions ) ;
574+ this . transformStartingStyle (
575+ root ,
576+ supportsRule ! [ '@starting-style' ] ,
577+ conditions ,
578+ ) ;
553579 } ) ;
554580 }
555581 }
@@ -589,6 +615,42 @@ class Stylesheet {
589615 }
590616 }
591617
618+ transformStartingStyle (
619+ root : CSSStyleBlock | CSSSelectorBlock ,
620+ rules : WithQueries < StyleWithSelectors > [ '@starting-style' ] ,
621+ parentConditions : Array < string > = [ ] ,
622+ ) {
623+ if ( rules ) {
624+ // Check if there are any nested at-rule keys inside this block.
625+ // The presence of any key starting with '@' indicates nested queries,
626+ // which are not allowed for @starting -style.
627+ const nestedAtRuleKey = Object . keys ( rules ) . find ( ( key ) =>
628+ key . startsWith ( '@' ) ,
629+ ) ;
630+ if ( nestedAtRuleKey ) {
631+ throw new Error (
632+ `Nested at-rules (e.g. "${ nestedAtRuleKey } ") are not allowed inside @starting-style.` ,
633+ ) ;
634+ }
635+
636+ const conditions = [ ...parentConditions , '@starting-style' ] ;
637+
638+ this . addConditionalRule (
639+ {
640+ selector : root . selector ,
641+ rule : omit ( rules , specialKeys ) ,
642+ } ,
643+ conditions ,
644+ ) ;
645+
646+ // Process any simple pseudos or selectors associated with this style.
647+ if ( root . type === 'local' ) {
648+ this . transformSimplePseudos ( root , rules , conditions ) ;
649+ this . transformSelectors ( root , rules , conditions ) ;
650+ }
651+ }
652+ }
653+
592654 toCss ( ) {
593655 const css : Array < string > = [ ] ;
594656
0 commit comments