File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
packages/tailwindcss-language-service/src/util Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
const dlv = require ( 'dlv' )
2
2
import { State } from './state'
3
3
import removeMeta from './removeMeta'
4
- import { TinyColor } from '@ctrl/tinycolor'
4
+ import { TinyColor , names as colorNames } from '@ctrl/tinycolor'
5
5
import { ensureArray , dedupe , flatten } from './array'
6
6
7
7
const COLOR_PROPS = [
@@ -89,10 +89,18 @@ export function getColor(
89
89
90
90
export function getColorFromValue ( value : unknown ) : string {
91
91
if ( typeof value !== 'string' ) return null
92
- if ( value === 'transparent' ) {
92
+ const trimmedValue = value . trim ( )
93
+ if ( trimmedValue === 'transparent' ) {
93
94
return 'rgba(0, 0, 0, 0.01)'
94
95
}
95
- const color = new TinyColor ( value )
96
+ if (
97
+ ! / ^ \s * (?: r g b a ? | h s l a ? ) \s * \( [ ^ ) ] + \) \s * $ / . test ( trimmedValue ) &&
98
+ ! / ^ \s * # [ 0 - 9 a - f ] + \s * $ / i. test ( trimmedValue ) &&
99
+ ! Object . keys ( colorNames ) . includes ( trimmedValue )
100
+ ) {
101
+ return null
102
+ }
103
+ const color = new TinyColor ( trimmedValue )
96
104
if ( color . isValid ) {
97
105
return color . toRgbString ( )
98
106
}
You can’t perform that action at this time.
0 commit comments