@@ -310,9 +310,9 @@ export class StyledProcessor extends BaseProcessor {
310
310
* which we can use to generate our styles.
311
311
* Order of processing styles -
312
312
* 1. CSS directly declared in styled call
313
- * 3 . Variants declared in styled call
314
- * 2 . CSS declared in theme object's styledOverrides
315
- * 3 . Variants declared in theme object
313
+ * 2 . Variants declared in styled call
314
+ * 3 . CSS declared in theme object's styledOverrides
315
+ * 4 . Variants declared in theme object
316
316
*/
317
317
build ( values : ValueCache ) : void {
318
318
if ( this . isTemplateTag ) {
@@ -449,6 +449,7 @@ export class StyledProcessor extends BaseProcessor {
449
449
variantsAccumulator ,
450
450
themeImportIdentifier ,
451
451
) ;
452
+
452
453
const className = this . getClassName ( ) ;
453
454
this . baseClasses . push ( className ) ;
454
455
this . collectedStyles . push ( [ className , finalStyle , styleArg ] ) ;
@@ -523,8 +524,8 @@ export class StyledProcessor extends BaseProcessor {
523
524
styleArg : ExpressionValue | null ,
524
525
variantsAccumulator ?: VariantData [ ] ,
525
526
themeImportIdentifier ?: string ,
526
- ) {
527
- const { themeArgs = { } } = this . options as IOptions ;
527
+ ) : string {
528
+ const { themeArgs = { } , experiments = { } } = this . options as IOptions ;
528
529
const styleObj = typeof styleObjOrFn === 'function' ? styleObjOrFn ( themeArgs ) : styleObjOrFn ;
529
530
if ( ! styleObj ) {
530
531
return '' ;
@@ -551,7 +552,15 @@ export class StyledProcessor extends BaseProcessor {
551
552
if ( res . length ) {
552
553
this . collectedVariables . push ( ...res ) ;
553
554
}
554
- return processCssObject ( styleObj , themeArgs ) ;
555
+ const cssText = processCssObject ( styleObj , themeArgs ) ;
556
+
557
+ if ( experiments . styleLayers ) {
558
+ if ( variantsAccumulator ) {
559
+ return `@layer pigment-base {${ cssText } }` ;
560
+ }
561
+ return `@layer pigment-variant {${ cssText } }` ;
562
+ }
563
+ return cssText ;
555
564
}
556
565
557
566
public override get asSelector ( ) : string {
0 commit comments