@@ -7,11 +7,9 @@ import { getValueByPath } from '@src/helper/common.helper.js'
77 * Cache manager for theme resolution operations.
88 */
99class ThemeResolverCache {
10+ private static _instance : ThemeResolverCache | null = null
1011 private readonly CACHE_SIZE_LIMIT = 500
1112 private readonly CACHE_EVICTION_BATCH_SIZE = 50
12-
13- private static _instance : ThemeResolverCache | null = null
14-
1513 private readonly _resolutionCache = new Map < string , Record < string , unknown > > ( )
1614 private readonly _pathLookupCache = new Map < string , Record < string , unknown > | string | null > ( )
1715 private readonly _themeRegex = / t h e m e \. ( [ a - z A - Z 0 - 9 _ . - ] + ) / g
@@ -23,14 +21,6 @@ class ThemeResolverCache {
2321 return ThemeResolverCache . _instance
2422 }
2523
26- /**
27- * Generate a stable cache key from object and theme, including the theme mode.
28- */
29- private _generateCacheKey ( obj : Record < string , any > , theme : Theme ) : string {
30- // Including theme.mode is critical for cache correctness.
31- return `${ ObjHelper . stringify ( obj ) } _${ theme . mode } _${ ObjHelper . stringify ( theme . system ) } `
32- }
33-
3424 getResolution < O extends Record < string , unknown > > ( obj : O , theme : Theme ) {
3525 const key = this . _generateCacheKey ( obj , theme )
3626 const result = this . _resolutionCache . get ( key ) as O
@@ -69,18 +59,6 @@ class ThemeResolverCache {
6959 }
7060 }
7161
72- private _evict ( cache : Map < string , unknown > ) {
73- const keys = cache . keys ( )
74- for ( let i = 0 ; i < this . CACHE_EVICTION_BATCH_SIZE ; i ++ ) {
75- const key = keys . next ( ) . value
76- if ( key ) {
77- cache . delete ( key )
78- } else {
79- break
80- }
81- }
82- }
83-
8462 getThemeRegex ( ) : RegExp {
8563 this . _themeRegex . lastIndex = 0
8664 return this . _themeRegex
@@ -94,25 +72,39 @@ class ThemeResolverCache {
9472 this . _resolutionCache . clear ( )
9573 this . _pathLookupCache . clear ( )
9674 }
75+
76+ /**
77+ * Generate a stable cache key from object and theme, including the theme mode.
78+ */
79+ private _generateCacheKey ( obj : Record < string , any > , theme : Theme ) : string {
80+ // Including theme.mode is critical for cache correctness.
81+ return `${ ObjHelper . stringify ( obj ) } _${ theme . mode } _${ ObjHelper . stringify ( theme . system ) } `
82+ }
83+
84+ private _evict ( cache : Map < string , unknown > ) {
85+ const keys = cache . keys ( )
86+ for ( let i = 0 ; i < this . CACHE_EVICTION_BATCH_SIZE ; i ++ ) {
87+ const key = keys . next ( ) . value
88+ if ( key ) {
89+ cache . delete ( key )
90+ } else {
91+ break
92+ }
93+ }
94+ }
9795}
9896
99- /**
100- * Parsed flex shorthand components for CSS flex property
101- * @interface FlexComponents
102- * @property grow - The flex-grow value (how much the item should grow)
103- * @property shrink - The flex-shrink value (how much the item should shrink)
104- * @property basis - The flex-basis value (initial main size before free space is distributed)
105- */
10697interface FlexComponents {
10798 grow : number
10899 shrink : number
109100 basis : string | number
110101}
111- export class ThemeUtil {
112- private constructor ( ) { }
113102
103+ export class ThemeUtil {
114104 private static themeCache = ThemeResolverCache . getInstance ( )
115105
106+ private constructor ( ) { }
107+
116108 /**
117109 * Parses a CSS flex shorthand property into its individual components.
118110 *
0 commit comments