@@ -8,6 +8,19 @@ import type { ComponentAnatomy, StyleModuleEvaluateParameters, StyleRules } from
88import { stylePropertyToCssProperty } from "./css.js" ;
99import { convertStylesToFocusState , Styles } from "./styles.js" ;
1010
11+ const deepFreeze = < T > ( obj : T ) : T => {
12+ if ( obj && typeof obj === "object" && ! Object . isFrozen ( obj ) ) {
13+ Object . getOwnPropertyNames ( obj ) . forEach ( ( prop ) => {
14+ const value = ( obj as any ) [ prop ] ;
15+ if ( value && typeof value === "object" ) {
16+ deepFreeze ( value ) ;
17+ }
18+ } ) ;
19+ Object . freeze ( obj ) ;
20+ }
21+ return obj ;
22+ }
23+
1124/**
1225 * The properties and values of a css declaration.
1326 */
@@ -160,7 +173,7 @@ export class ElementStylesRenderer {
160173 */
161174 public render ( target : StyleModuleTarget , interactivity ?: InteractivityDefinition ) : ElementStyles {
162175 // Construct the evaluation params, not including interactivity if requested
163- const effectiveInteractivity = interactivity || { } ;
176+ const effectiveInteractivity = { ... ( interactivity || { } ) } ;
164177 if ( target . ignoreInteractivity === true ) {
165178 Object . assign ( effectiveInteractivity , Interactivity . always ) ;
166179 }
@@ -240,6 +253,7 @@ export class ElementStylesRenderer {
240253 public static renderStyleRules ( baseStyles : ComposableStyles [ ] = [ ] , styleRules : StyleRules , anatomy ?: ComponentAnatomy < any , any > ) {
241254 const globalStyleRules : StyleRules = [ ] ;
242255 if ( anatomy ) {
256+ anatomy = deepFreeze ( anatomy ) ;
243257 // If this component can be disabled, apply the style to all children.
244258 if ( ElementStylesRenderer . disabledStyles && anatomy . interactivity ?. disabled !== undefined ) {
245259 // Focus and disabled are related in the way that they define the footprint of an indicator:
@@ -292,7 +306,7 @@ export class ElementStylesRenderer {
292306 const styles = Styles . fromDeclaration ( rule ) ;
293307
294308 // Transform the target selector if necessary
295- const target = rule . target || { } as StyleModuleTarget ;
309+ const target = { ... ( rule . target || { } ) } as StyleModuleTarget ;
296310 if ( anatomy ?. context && target . context === undefined ) {
297311 target . context = anatomy . context ;
298312 if ( anatomy . context === target . part ) {
0 commit comments