@@ -21,10 +21,14 @@ const COLOR_PROPS = [
21
21
'text-decoration-color' ,
22
22
]
23
23
24
+ function isKeyword ( value : string ) : boolean {
25
+ return [ 'transparent' , 'currentcolor' ] . includes ( value . toLowerCase ( ) )
26
+ }
27
+
24
28
export function getColor (
25
29
state : State ,
26
30
keys : string [ ]
27
- ) : { documentation ?: string } {
31
+ ) : TinyColor | string | null {
28
32
const item = dlv ( state . classNames . classNames , keys )
29
33
if ( ! item . __rule ) return null
30
34
const props = Object . keys ( removeMeta ( item ) )
@@ -48,40 +52,36 @@ export function getColor(
48
52
)
49
53
50
54
// check that all of the values are valid colors
51
- if ( colors . some ( ( color ) => color !== 'transparent ' && ! color . isValid ) ) {
55
+ if ( colors . some ( ( color ) => typeof color !== 'string ' && ! color . isValid ) ) {
52
56
return null
53
57
}
54
58
55
59
// check that all of the values are the same color, ignoring alpha
56
60
const colorStrings = dedupe (
57
61
colors . map ( ( color ) =>
58
- color === 'transparent'
59
- ? 'transparent'
60
- : `${ color . r } -${ color . g } -${ color . b } `
62
+ typeof color === 'string' ? color : `${ color . r } -${ color . g } -${ color . b } `
61
63
)
62
64
)
63
65
if ( colorStrings . length !== 1 ) {
64
66
return null
65
67
}
66
68
67
- if ( colorStrings [ 0 ] === 'transparent' ) {
68
- return {
69
- documentation : 'rgba(0, 0, 0, 0.01)' ,
70
- }
69
+ if ( isKeyword ( colorStrings [ 0 ] ) ) {
70
+ return colorStrings [ 0 ]
71
71
}
72
72
73
- const nonTransparentColors = colors . filter (
74
- ( color ) : color is TinyColor => color !== 'transparent '
73
+ const nonKeywordColors = colors . filter (
74
+ ( color ) : color is TinyColor => typeof color !== 'string '
75
75
)
76
76
77
- const alphas = dedupe ( nonTransparentColors . map ( ( color ) => color . a ) )
77
+ const alphas = dedupe ( nonKeywordColors . map ( ( color ) => color . a ) )
78
+
79
+ if ( alphas . length === 1 ) {
80
+ return nonKeywordColors [ 0 ]
81
+ }
78
82
79
- if ( alphas . length === 1 || ( alphas . length === 2 && alphas . includes ( 0 ) ) ) {
80
- return {
81
- documentation : nonTransparentColors
82
- . find ( ( color ) => color . a !== 0 )
83
- . toRgbString ( ) ,
84
- }
83
+ if ( alphas . length === 2 && alphas . includes ( 0 ) ) {
84
+ return nonKeywordColors . find ( ( color ) => color . a !== 0 )
85
85
}
86
86
87
87
return null
@@ -99,9 +99,9 @@ export function getColorFromValue(value: unknown): string {
99
99
return null
100
100
}
101
101
102
- function createColor ( str : string ) : TinyColor | 'transparent' {
103
- if ( str === 'transparent' ) {
104
- return 'transparent'
102
+ function createColor ( str : string ) : TinyColor | string {
103
+ if ( isKeyword ( str ) ) {
104
+ return str
105
105
}
106
106
107
107
// matches: rgba(<r>, <g>, <b>, var(--bg-opacity))
0 commit comments