@@ -48,17 +48,43 @@ export function getColor(
48
48
)
49
49
50
50
// check that all of the values are valid colors
51
- if ( colors . some ( ( color ) => ! color . isValid ) ) {
51
+ if ( colors . some ( ( color ) => color !== 'transparent' && ! color . isValid ) ) {
52
52
return null
53
53
}
54
54
55
- // check that all of the values are the same color
56
- const colorStrings = colors . map ( ( color ) => color . toRgbString ( ) )
57
- if ( dedupe ( colorStrings ) . length !== 1 ) {
55
+ // check that all of the values are the same color, ignoring alpha
56
+ const colorStrings = dedupe (
57
+ colors . map ( ( color ) =>
58
+ color === 'transparent'
59
+ ? 'transparent'
60
+ : `${ color . r } -${ color . g } -${ color . b } `
61
+ )
62
+ )
63
+ if ( colorStrings . length !== 1 ) {
58
64
return null
59
65
}
60
66
61
- return { documentation : colorStrings [ 0 ] }
67
+ if ( colorStrings [ 0 ] === 'transparent' ) {
68
+ return {
69
+ documentation : 'rgba(0, 0, 0, 0.01)' ,
70
+ }
71
+ }
72
+
73
+ const nonTransparentColors = colors . filter (
74
+ ( color ) : color is TinyColor => color !== 'transparent'
75
+ )
76
+
77
+ const alphas = dedupe ( nonTransparentColors . map ( ( color ) => color . a ) )
78
+
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
+ }
85
+ }
86
+
87
+ return null
62
88
}
63
89
64
90
export function getColorFromValue ( value : unknown ) : string {
@@ -73,9 +99,9 @@ export function getColorFromValue(value: unknown): string {
73
99
return null
74
100
}
75
101
76
- function createColor ( str : string ) : TinyColor {
102
+ function createColor ( str : string ) : TinyColor | 'transparent' {
77
103
if ( str === 'transparent' ) {
78
- return new TinyColor ( { r : 0 , g : 0 , b : 0 , a : 0.01 } )
104
+ return 'transparent'
79
105
}
80
106
81
107
// matches: rgba(<r>, <g>, <b>, var(--bg-opacity))
0 commit comments