Skip to content

fix(preset-wind4): support nested spacing theme functions#5161

Closed
Jack-lea wants to merge 1 commit intounocss:mainfrom
Jack-lea:fix/wind4-spacing-calc-arbitrary-values
Closed

fix(preset-wind4): support nested spacing theme functions#5161
Jack-lea wants to merge 1 commit intounocss:mainfrom
Jack-lea:fix/wind4-spacing-calc-arbitrary-values

Conversation

@Jack-lea
Copy link
Copy Markdown

No description provided.

@Jack-lea Jack-lea requested review from antfu and zyyv as code owners March 23, 2026 10:33
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 23, 2026

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 611288c
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/69c116e41ab3d80008defa74
😎 Deploy Preview https://deploy-preview-5161--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines +211 to +212
if (theme)
base = replaceThemeFunctions(base, theme)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I don't think this is a very good solution.

Comment on lines 214 to 242
if (base.startsWith('--')) {
const calcMatch = base.match(/^--([\w.-]+)\(([^)]+)\)$/)
if (calcMatch != null && theme) {
// Handle theme function with calculation: --theme.key(factor)
const [, name, factor] = calcMatch
const [key, ...paths] = name.split('.') as [keyof Theme, ...string[]]
const { val, varKey } = processThemeVariable(name, key, paths, theme)

if (val != null)
base = `calc(var(--${escapeSelector(varKey.replaceAll('.', '-'))}) * ${factor})`
}
else {
// Handle regular CSS variable: --name or --theme.key with optional default
const [name, defaultValue] = base.slice(2).split(',')
const suffix = defaultValue ? `, ${defaultValue}` : ''
const escapedName = escapeSelector(name)

if (theme) {
const [key, ...paths] = name.split('.') as [keyof Theme, ...string[]]
const { val, varKey } = processThemeVariable(name, key, paths, theme)
base = val != null
? `var(--${escapeSelector(varKey.replaceAll('.', '-'))}${suffix})`
: `var(--${escapedName}${suffix})`
}
else {
base = `var(--${escapedName}${suffix})`
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My previous assessment was too narrow; I shouldn't have relied on a simple startsWith check. I think we should rewrite this logic to replace all theme variables enclosed within [].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants