@@ -310,9 +310,9 @@ export class StyledProcessor extends BaseProcessor {
310310 * which we can use to generate our styles.
311311 * Order of processing styles -
312312 * 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
316316 */
317317 build ( values : ValueCache ) : void {
318318 if ( this . isTemplateTag ) {
@@ -449,6 +449,7 @@ export class StyledProcessor extends BaseProcessor {
449449 variantsAccumulator ,
450450 themeImportIdentifier ,
451451 ) ;
452+
452453 const className = this . getClassName ( ) ;
453454 this . baseClasses . push ( className ) ;
454455 this . collectedStyles . push ( [ className , finalStyle , styleArg ] ) ;
@@ -523,8 +524,8 @@ export class StyledProcessor extends BaseProcessor {
523524 styleArg : ExpressionValue | null ,
524525 variantsAccumulator ?: VariantData [ ] ,
525526 themeImportIdentifier ?: string ,
526- ) {
527- const { themeArgs = { } } = this . options as IOptions ;
527+ ) : string {
528+ const { themeArgs = { } , experiments = { } } = this . options as IOptions ;
528529 const styleObj = typeof styleObjOrFn === 'function' ? styleObjOrFn ( themeArgs ) : styleObjOrFn ;
529530 if ( ! styleObj ) {
530531 return '' ;
@@ -551,7 +552,15 @@ export class StyledProcessor extends BaseProcessor {
551552 if ( res . length ) {
552553 this . collectedVariables . push ( ...res ) ;
553554 }
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 ;
555564 }
556565
557566 public override get asSelector ( ) : string {
0 commit comments