Skip to content

fix(preset): resolve leftover alpha placeholders under presetWind4 - #5

Merged
nekomeowww merged 1 commit into
mainfrom
nekomeowww/fix/wind4-alpha
Oct 12, 2026
Merged

nekomeowww merged 1 commit into
mainfrom
nekomeowww/fix/wind4-alpha

Conversation

@nekomeowww

Copy link
Copy Markdown
Member

Problem

With presetWind4 + presetChromatic, color utilities generate invalid CSS, so browsers drop them:

/* text-primary-600 */
color: color-mix(in srgb, oklch(… calc(var(--chromatic-hue) + 0) / %alpha) var(--un-text-opacity), transparent);

presetWind4 inlines a theme color that contains var( into the utility as color-mix(<method>, <color> <opacity>, transparent) and does not replace its %alpha placeholder (colorCSSGenerator, @unocss/preset-wind4/dist/utils-*.mjs, 66.7.5 lines 569–586). It only replaces placeholders with 1 when it emits theme variables (getThemeVarsMap, dist/index.mjs line 456), which it skips for these colors. Every shade of the runtime palette contains var(--chromatic-hue), so every shade is affected. presetWind3 is fine.

Fix

A postprocess hook replaces leftover %alpha / <alpha-value> placeholders with 1, the value wind4 itself uses for theme variables. The surrounding color-mix(…, transparent) still applies the utility's opacity (/50 → … / 1) 50%, transparent)), and --chromatic-hue stays dynamic at runtime.

The hook runs on every utility, not only chromatic ones. A leftover placeholder is always invalid CSS, so the hook cannot change any output that was valid before.

wind3 output is unchanged

presetWind3 resolves every placeholder before postprocessing. I generated CSS for 16 utility prefixes × 11 shades × opacity / saturation / brightness modifiers and hover:, in both runtime and bakeColors modes, before and after the change: the results are byte-identical (cmp).

Tests

New packages/preset/src/shared.wind4.test.ts covers text-primary-600, bg-primary-500/50, border-primary-400, ring-primary-500, bg-primary-50, and the modifier syntax bg-primary-500/50~10*115. All 4 cases failed before the fix and pass after it. pnpm test:run (14 tests), pnpm typecheck, pnpm lint and pnpm build:packages pass.

Found while adopting chromatic in the vieval web viewer, which uses presetWind4.

🤖 Generated with Claude Code

presetWind4 inlines theme colors that contain `var(` into utilities as
`color-mix(..., <color> <opacity>, transparent)` without replacing their
`%alpha` placeholder. Every shade of the runtime palette contains
`var(--chromatic-hue)`, so `text-primary-600`, `bg-primary-500/50` and the
other color utilities produced invalid declarations that browsers drop.

Replace leftover placeholders with `1` in a postprocess hook, the value
wind4 itself uses for theme variables. The surrounding `color-mix` still
applies the utility opacity, and the runtime hue stays dynamic. wind3
resolves placeholders before postprocessing, so its output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for proj-airi-chromatic ready!

Name Link
🔨 Latest commit 2a82b89
🔍 Latest deploy log https://app.netlify.com/projects/proj-airi-chromatic/deploys/6accdeb46044010de5e43397
😎 Deploy Preview https://deploy-preview-5--proj-airi-chromatic.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@nekomeowww
nekomeowww merged commit 01a9d38 into main Oct 12, 2026
7 checks passed
@nekomeowww
nekomeowww deleted the nekomeowww/fix/wind4-alpha branch October 12, 2026 13:23
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.

1 participant