Skip to content

Commit d14f5b7

Browse files
committed
Tweak types
1 parent ed39ccf commit d14f5b7

File tree

1 file changed

+6
-5
lines changed
  • packages/tailwindcss-language-service/src/util

1 file changed

+6
-5
lines changed

packages/tailwindcss-language-service/src/util/color.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const COLOR_PROPS = [
3636
]
3737

3838
export type KeywordColor = 'transparent' | 'currentColor'
39+
export type ParsedColor = KeywordColor | culori.Color
3940

4041
function getKeywordColor(value: unknown): KeywordColor | null {
4142
if (typeof value !== 'string') return null
@@ -56,7 +57,7 @@ const colorRegex = new RegExp(
5657
'gi',
5758
)
5859

59-
function getColorsInString(state: State, str: string): (culori.Color | KeywordColor)[] {
60+
function getColorsInString(state: State, str: string): ParsedColor[] {
6061
if (/(?:box|drop)-shadow/.test(str) && !/--tw-drop-shadow/.test(str)) return []
6162

6263
function toColor(match: RegExpMatchArray) {
@@ -76,7 +77,7 @@ function getColorsInString(state: State, str: string): (culori.Color | KeywordCo
7677
function getColorFromDecls(
7778
state: State,
7879
decls: Record<string, string | string[]>,
79-
): culori.Color | KeywordColor | null {
80+
): ParsedColor | null {
8081
let props = Object.keys(decls).filter((prop) => {
8182
// ignore content: "";
8283
if (prop === 'content') {
@@ -151,7 +152,7 @@ function getColorFromDecls(
151152
return null
152153
}
153154

154-
function getColorFromRoot(state: State, css: AstNode[]): culori.Color | KeywordColor | null {
155+
function getColorFromRoot(state: State, css: AstNode[]): ParsedColor | null {
155156
let decls: Record<string, string[]> = {}
156157

157158
walk(css, (node) => {
@@ -202,7 +203,7 @@ function isLikelyColorless(className: string) {
202203
return false
203204
}
204205

205-
export function getColor(state: State, className: string): culori.Color | KeywordColor | null {
206+
export function getColor(state: State, className: string): ParsedColor | null {
206207
if (state.v4) {
207208
// FIXME: This is a performance optimization and not strictly correct
208209
if (isLikelyColorless(className)) return null
@@ -268,7 +269,7 @@ export function getColor(state: State, className: string): culori.Color | Keywor
268269
return getColorFromDecls(state, removeMeta(item))
269270
}
270271

271-
export function getColorFromValue(value: unknown): culori.Color | KeywordColor | null {
272+
export function getColorFromValue(value: unknown): ParsedColor | null {
272273
if (typeof value !== 'string') return null
273274

274275
let trimmedValue = value.trim()

0 commit comments

Comments
 (0)