@@ -21,10 +21,14 @@ const COLOR_PROPS = [
2121 'text-decoration-color' ,
2222]
2323
24+ function isKeyword ( value : string ) : boolean {
25+ return [ 'transparent' , 'currentcolor' ] . includes ( value . toLowerCase ( ) )
26+ }
27+
2428export function getColor (
2529 state : State ,
2630 keys : string [ ]
27- ) : { documentation ?: string } {
31+ ) : TinyColor | string | null {
2832 const item = dlv ( state . classNames . classNames , keys )
2933 if ( ! item . __rule ) return null
3034 const props = Object . keys ( removeMeta ( item ) )
@@ -48,40 +52,36 @@ export function getColor(
4852 )
4953
5054 // 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 ) ) {
5256 return null
5357 }
5458
5559 // check that all of the values are the same color, ignoring alpha
5660 const colorStrings = dedupe (
5761 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 } `
6163 )
6264 )
6365 if ( colorStrings . length !== 1 ) {
6466 return null
6567 }
6668
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 ]
7171 }
7272
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 '
7575 )
7676
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+ }
7882
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 )
8585 }
8686
8787 return null
@@ -99,9 +99,9 @@ export function getColorFromValue(value: unknown): string {
9999 return null
100100}
101101
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
105105 }
106106
107107 // matches: rgba(<r>, <g>, <b>, var(--bg-opacity))
0 commit comments