Skip to content

Commit d76e2ee

Browse files
committed
Parse oklch colors with units in all positions
1 parent 1e2d55c commit d76e2ee

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/tailwindcss-language-server/tests/colors/colors.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ withFixture('v4/basic', (c) => {
246246
],
247247
})
248248

249+
testColors('oklch colors are parsed with percentages and angles', {
250+
text: '<div class="bg-[oklch(62.75%_64.75%_30deg)]">',
251+
expected: [
252+
{
253+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 43 } },
254+
color: {
255+
alpha: 1,
256+
red: 1,
257+
green: 0,
258+
blue: 0,
259+
},
260+
},
261+
],
262+
})
263+
249264
testColors('gradient utilities show colors', {
250265
text: '<div class="from-black from-black/50 via-black via-black/50 to-black to-black/50">',
251266
expected: [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function getKeywordColor(value: unknown): KeywordColor | null {
5050

5151
// https://github.com/khalilgharbaoui/coloregex
5252
const colorRegex = new RegExp(
53-
`(?:^|\\s|\\(|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgba?|hsla?|(?:ok)?(?:lab|lch))\\(\\s*(-?[\\d.]+(%|deg|rad|grad|turn)?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+%?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
53+
`(?:^|\\s|\\(|,)(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgba?|hsla?|(?:ok)?(?:lab|lch))\\(\\s*(-?[\\d.]+(%|deg|rad|grad|turn)?(\\s*[,/]\\s*|\\s+)+){2,3}\\s*([\\d.]+(%|deg|rad|grad|turn)?|var\\([^)]+\\))?\\)|transparent|currentColor|${Object.keys(
5454
namedColors,
5555
).join('|')})(?:$|\\s|\\)|,)`,
5656
'gi',

0 commit comments

Comments
 (0)