Skip to content

Commit fe8f97d

Browse files
committed
Make sure gradient utilities show color decorators in v4
1 parent eeb229e commit fe8f97d

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,68 @@ withFixture('basic', (c) => {
8787
},
8888
],
8989
})
90+
91+
testColors('gradient utilities show colors', {
92+
text: '<div class="from-black from-black/50 via-black via-black/50 to-black to-black/50">',
93+
expected: [
94+
{
95+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 22 } },
96+
color: {
97+
alpha: 1,
98+
red: 0,
99+
green: 0,
100+
blue: 0,
101+
},
102+
},
103+
{
104+
range: { start: { line: 0, character: 23 }, end: { line: 0, character: 36 } },
105+
color: {
106+
alpha: 0.5,
107+
red: 0,
108+
green: 0,
109+
blue: 0,
110+
},
111+
},
112+
113+
{
114+
range: { start: { line: 0, character: 37 }, end: { line: 0, character: 46 } },
115+
color: {
116+
alpha: 1,
117+
red: 0,
118+
green: 0,
119+
blue: 0,
120+
},
121+
},
122+
{
123+
range: { start: { line: 0, character: 47 }, end: { line: 0, character: 59 } },
124+
color: {
125+
alpha: 0.5,
126+
red: 0,
127+
green: 0,
128+
blue: 0,
129+
},
130+
},
131+
132+
{
133+
range: { start: { line: 0, character: 60 }, end: { line: 0, character: 68 } },
134+
color: {
135+
alpha: 1,
136+
red: 0,
137+
green: 0,
138+
blue: 0,
139+
},
140+
},
141+
{
142+
range: { start: { line: 0, character: 69 }, end: { line: 0, character: 80 } },
143+
color: {
144+
alpha: 0.5,
145+
red: 0,
146+
green: 0,
147+
blue: 0,
148+
},
149+
},
150+
],
151+
})
90152
})
91153

92154
withFixture('v4/basic', (c) => {
@@ -175,4 +237,66 @@ withFixture('v4/basic', (c) => {
175237
},
176238
],
177239
})
240+
241+
testColors('gradient utilities show colors', {
242+
text: '<div class="from-black from-black/50 via-black via-black/50 to-black to-black/50">',
243+
expected: [
244+
{
245+
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 22 } },
246+
color: {
247+
alpha: 1,
248+
red: 0,
249+
green: 0,
250+
blue: 0,
251+
},
252+
},
253+
{
254+
range: { start: { line: 0, character: 23 }, end: { line: 0, character: 36 } },
255+
color: {
256+
alpha: 0.5,
257+
red: 0,
258+
green: 0,
259+
blue: 0,
260+
},
261+
},
262+
263+
{
264+
range: { start: { line: 0, character: 37 }, end: { line: 0, character: 46 } },
265+
color: {
266+
alpha: 1,
267+
red: 0,
268+
green: 0,
269+
blue: 0,
270+
},
271+
},
272+
{
273+
range: { start: { line: 0, character: 47 }, end: { line: 0, character: 59 } },
274+
color: {
275+
alpha: 0.5,
276+
red: 0,
277+
green: 0,
278+
blue: 0,
279+
},
280+
},
281+
282+
{
283+
range: { start: { line: 0, character: 60 }, end: { line: 0, character: 68 } },
284+
color: {
285+
alpha: 1,
286+
red: 0,
287+
green: 0,
288+
blue: 0,
289+
},
290+
},
291+
{
292+
range: { start: { line: 0, character: 69 }, end: { line: 0, character: 80 } },
293+
color: {
294+
alpha: 0.5,
295+
red: 0,
296+
green: 0,
297+
blue: 0,
298+
},
299+
},
300+
],
301+
})
178302
})

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ function getColorFromDecls(
145145
}
146146

147147
function getColorFromRoot(state: State, css: postcss.Root): culori.Color | KeywordColor | null {
148+
// Remove any `@property` rules
149+
css = css.clone()
150+
css.walkAtRules((rule) => {
151+
// Ignore declarations inside `@property` rules
152+
if (rule.name === 'property') {
153+
rule.remove()
154+
}
155+
156+
// Ignore declarations @supports (-moz-orient: inline)
157+
// this is a hack used for `@property` fallbacks in Firefox
158+
if (rule.name === 'supports' && rule.params === '(-moz-orient: inline)') {
159+
rule.remove()
160+
}
161+
})
162+
148163
let decls: Record<string, string[]> = {}
149164

150165
let rule = postcss.rule({

0 commit comments

Comments
 (0)