@@ -8,6 +8,19 @@ import type { ComponentAnatomy, StyleModuleEvaluateParameters, StyleRules } from
8
8
import { stylePropertyToCssProperty } from "./css.js" ;
9
9
import { convertStylesToFocusState , Styles } from "./styles.js" ;
10
10
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
+
11
24
/**
12
25
* The properties and values of a css declaration.
13
26
*/
@@ -160,7 +173,7 @@ export class ElementStylesRenderer {
160
173
*/
161
174
public render ( target : StyleModuleTarget , interactivity ?: InteractivityDefinition ) : ElementStyles {
162
175
// Construct the evaluation params, not including interactivity if requested
163
- const effectiveInteractivity = interactivity || { } ;
176
+ const effectiveInteractivity = { ... ( interactivity || { } ) } ;
164
177
if ( target . ignoreInteractivity === true ) {
165
178
Object . assign ( effectiveInteractivity , Interactivity . always ) ;
166
179
}
@@ -240,6 +253,7 @@ export class ElementStylesRenderer {
240
253
public static renderStyleRules ( baseStyles : ComposableStyles [ ] = [ ] , styleRules : StyleRules , anatomy ?: ComponentAnatomy < any , any > ) {
241
254
const globalStyleRules : StyleRules = [ ] ;
242
255
if ( anatomy ) {
256
+ anatomy = deepFreeze ( anatomy ) ;
243
257
// If this component can be disabled, apply the style to all children.
244
258
if ( ElementStylesRenderer . disabledStyles && anatomy . interactivity ?. disabled !== undefined ) {
245
259
// Focus and disabled are related in the way that they define the footprint of an indicator:
@@ -292,7 +306,7 @@ export class ElementStylesRenderer {
292
306
const styles = Styles . fromDeclaration ( rule ) ;
293
307
294
308
// Transform the target selector if necessary
295
- const target = rule . target || { } as StyleModuleTarget ;
309
+ const target = { ... ( rule . target || { } ) } as StyleModuleTarget ;
296
310
if ( anatomy ?. context && target . context === undefined ) {
297
311
target . context = anatomy . context ;
298
312
if ( anatomy . context === target . part ) {
0 commit comments