Skip to content

Commit 70a16f8

Browse files
committed
Refactor
1 parent 2a4b33f commit 70a16f8

File tree

1 file changed

+20
-15
lines changed
  • packages/tailwindcss-language-service/src/util

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,25 @@ export function generateRules(
3535
}
3636
}
3737

38+
export function addThemeValues(css: string, state: State) {
39+
if (!state.designSystem) return css
40+
41+
// Add fallbacks to variables with their theme values
42+
// Ideally these would just be commentss like
43+
// `var(--foo) /* 3rem = 48px */` or
44+
// `calc(var(--spacing) * 5) /* 1.25rem = 20px */`
45+
css = replaceCssVars(css, (name) => {
46+
if (!name.startsWith('--')) return null
47+
48+
let value = state.designSystem.resolveThemeValue?.(name) ?? null
49+
if (value === null) return null
50+
51+
return `var(${name}, ${value})`
52+
})
53+
54+
return css
55+
}
56+
3857
export async function stringifyRoot(state: State, root: Root, uri?: string): Promise<string> {
3958
let settings = await state.editor.getConfiguration(uri)
4059
let clone = root.clone()
@@ -45,21 +64,7 @@ export async function stringifyRoot(state: State, root: Root, uri?: string): Pro
4564

4665
let css = clone.toString()
4766

48-
// Add fallbacks to variables with their theme values
49-
// Ideally these would just be commentss like
50-
// `var(--foo) /* 3rem = 48px */` or
51-
// `calc(var(--spacing) * 5) /* 1.25rem = 20px */`
52-
if (state.designSystem) {
53-
css = replaceCssVars(css, (name) => {
54-
if (!name.startsWith('--')) return null
55-
56-
let value = state.designSystem.resolveThemeValue?.(name) ?? null
57-
if (value === null) return null
58-
59-
return `var(${name}, ${value})`
60-
})
61-
}
62-
67+
css = addThemeValues(css, state)
6368
css = addEquivalents(css, settings.tailwindCSS)
6469

6570
let identSize = state.v4 ? 2 : 4

0 commit comments

Comments
 (0)