diff --git a/packages/tailwindcss-language-service/src/util/color.ts b/packages/tailwindcss-language-service/src/util/color.ts index b7b55ca6e3a5bfe3b2b725a80d9000e463cbd576..8334a180d2594f43233b4ceb938feac4974cf701 100644 --- a/packages/tailwindcss-language-service/src/util/color.ts +++ b/packages/tailwindcss-language-service/src/util/color.ts @@ -42,23 +42,17 @@ } // https://github.com/khalilgharbaoui/coloregex const colorRegex = new RegExp( +import dlv from 'dlv' import { ensureArray, dedupe, flatten } from './array' -import dlv from 'dlv' namedColors ).join('|')})(?:$|\\s|\\)|,)`, 'gi' ) -function replaceColorVarsWithTheirDefaults(str: string): string { - // rgb(var(--primary, 66 66 66)) - // -> rgb(66 66 66) - return str.replace(/((?:rgb|hsl)a?\(\s*)var\([^,]+,\s*([^)]+)\)/gi, '$1$2') -} - function getColorsInString(str: string): (culori.Color | KeywordColor)[] { if (/(?:box|drop)-shadow/.test(str)) return [] - return Array.from(replaceColorVarsWithTheirDefaults(str).matchAll(colorRegex), (match) => { + return Array.from(str.matchAll(colorRegex), (match) => { let color = match[1].replace(/var\([^)]+\)/, '1') return getKeywordColor(color) ?? culori.parse(color) }).filter(Boolean)