@@ -56,7 +56,7 @@ const colorRegex = new RegExp(
56
56
'gi' ,
57
57
)
58
58
59
- function getColorsInString ( str : string ) : ( culori . Color | KeywordColor ) [ ] {
59
+ function getColorsInString ( state : State , str : string ) : ( culori . Color | KeywordColor ) [ ] {
60
60
if ( / (?: b o x | d r o p ) - s h a d o w / . test ( str ) ) return [ ]
61
61
62
62
function toColor ( match : RegExpMatchArray ) {
@@ -73,6 +73,7 @@ function getColorsInString(str: string): (culori.Color | KeywordColor)[] {
73
73
}
74
74
75
75
function getColorFromDecls (
76
+ state : State ,
76
77
decls : Record < string , string | string [ ] > ,
77
78
) : culori . Color | KeywordColor | null {
78
79
let props = Object . keys ( decls ) . filter ( ( prop ) => {
@@ -99,7 +100,9 @@ function getColorFromDecls(
99
100
100
101
const propsToCheck = areAllCustom ? props : nonCustomProps
101
102
102
- const colors = propsToCheck . flatMap ( ( prop ) => ensureArray ( decls [ prop ] ) . flatMap ( getColorsInString ) )
103
+ const colors = propsToCheck . flatMap ( ( prop ) => ensureArray ( decls [ prop ] ) . flatMap ( ( str ) => {
104
+ return getColorsInString ( state , str )
105
+ } ) )
103
106
104
107
// check that all of the values are valid colors
105
108
// if (colors.some((color) => color instanceof TinyColor && !color.isValid)) {
@@ -170,7 +173,7 @@ function getColorFromRoot(state: State, css: postcss.Root): culori.Color | Keywo
170
173
decls [ decl . prop ] . push ( decl . value )
171
174
} )
172
175
173
- return getColorFromDecls ( decls )
176
+ return getColorFromDecls ( state , decls )
174
177
}
175
178
176
179
export function getColor ( state : State , className : string ) : culori . Color | KeywordColor | null {
@@ -186,7 +189,7 @@ export function getColor(state: State, className: string): culori.Color | Keywor
186
189
if ( state . classNames ) {
187
190
const item = dlv ( state . classNames . classNames , [ className , '__info' ] )
188
191
if ( item && item . __rule ) {
189
- return getColorFromDecls ( removeMeta ( item ) )
192
+ return getColorFromDecls ( state , removeMeta ( item ) )
190
193
}
191
194
}
192
195
@@ -215,7 +218,7 @@ export function getColor(state: State, className: string): culori.Color | Keywor
215
218
decls [ decl . prop ] = decl . value
216
219
}
217
220
} )
218
- return getColorFromDecls ( decls )
221
+ return getColorFromDecls ( state , decls )
219
222
}
220
223
221
224
let parts = getClassNameParts ( state , className )
@@ -224,7 +227,7 @@ export function getColor(state: State, className: string): culori.Color | Keywor
224
227
const item = dlv ( state . classNames . classNames , [ ...parts , '__info' ] )
225
228
if ( ! item . __rule ) return null
226
229
227
- return getColorFromDecls ( removeMeta ( item ) )
230
+ return getColorFromDecls ( state , removeMeta ( item ) )
228
231
}
229
232
230
233
export function getColorFromValue ( value : unknown ) : culori . Color | KeywordColor | null {
0 commit comments