@@ -172,14 +172,35 @@ const COLOR_NAMES = {
172
172
yellowgreen : '#9acd32' ,
173
173
}
174
174
175
- export function getColor ( state : State , keys : string [ ] ) : string {
175
+ export function getColor (
176
+ state : State ,
177
+ keys : string [ ]
178
+ ) : { documentation ?: string } {
176
179
const item = dlv ( state . classNames . classNames , keys )
177
180
if ( ! item . __rule ) return null
178
181
const props = Object . keys ( removeMeta ( item ) )
179
- if ( props . length === 0 || props . length > 1 ) return null
180
- const prop = props [ 0 ]
182
+ const nonCustomProps = props . filter ( ( prop ) => ! prop . startsWith ( '--' ) )
183
+ if ( nonCustomProps . length !== 1 ) return null
184
+ const prop = nonCustomProps [ 0 ]
181
185
if ( COLOR_PROPS . indexOf ( prop ) === - 1 ) return null
182
- return COLOR_NAMES [ item [ prop ] . toLowerCase ( ) ] || item [ prop ]
186
+
187
+ const namedColor = COLOR_NAMES [ item [ prop ] . toLowerCase ( ) ]
188
+ if ( namedColor ) {
189
+ return { documentation : namedColor }
190
+ }
191
+
192
+ // matches: rgba(<r>, <g>, <b>, var(--bg-opacity))
193
+ // TODO: support other formats? e.g. hsla, css level 4
194
+ const match = item [ prop ] . match (
195
+ / ^ \s * r g b a \( \s * (?< r > [ 0 - 9 ] { 1 , 3 } ) \s * , \s * (?< g > [ 0 - 9 ] { 1 , 3 } ) \s * , \s * (?< b > [ 0 - 9 ] { 1 , 3 } ) \s * , \s * v a r /
196
+ )
197
+ if ( match ) {
198
+ return {
199
+ documentation : `rgb(${ match . groups . r } , ${ match . groups . g } , ${ match . groups . b } )` ,
200
+ }
201
+ }
202
+
203
+ return { }
183
204
}
184
205
185
206
export function isColor ( str : any ) : boolean {
0 commit comments