Skip to content

Commit e43d002

Browse files
committed
fix(preset-wind4): support special color key with alpha
close #4998
1 parent 118c658 commit e43d002

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

packages-presets/preset-wind4/src/utils/utilities.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,20 +253,24 @@ export function colorCSSGenerator(
253253
if (color) {
254254
const result: [CSSObject, ...CSSValueInput[]] = [css]
255255
const isCSSVar = color.includes('var(')
256-
if (Object.values(SpecialColorKey).includes(color)) {
256+
const isSpecial = Object.values(SpecialColorKey).includes(color)
257+
258+
if (isSpecial && !alpha) {
257259
css[property] = color
260+
return result
261+
}
262+
263+
const alphaKey = `--un-${varName}-opacity`
264+
const value = (keys && !isCSSVar && !isSpecial) ? generateThemeVariable('colors', keys) : color
265+
let method = modifier ?? (keys ? 'in srgb' : 'in oklab')
266+
if (!method.startsWith('in ') && !method.startsWith('var(')) {
267+
method = `in ${method}`
258268
}
259-
else {
260-
const alphaKey = `--un-${varName}-opacity`
261-
const value = (keys && !isCSSVar) ? generateThemeVariable('colors', keys) : color
262-
let method = modifier ?? (keys ? 'in srgb' : 'in oklab')
263-
if (!method.startsWith('in ') && !method.startsWith('var(')) {
264-
method = `in ${method}`
265-
}
266269

267-
css[property] = `color-mix(${method}, ${value} ${alpha ?? `var(${alphaKey})`}, transparent)${rawColorComment}`
268-
result.push(defineProperty(alphaKey, { syntax: '<percentage>', initialValue: '100%' }))
270+
css[property] = `color-mix(${method}, ${value} ${alpha ?? `var(${alphaKey})`}, transparent)${rawColorComment}`
271+
result.push(defineProperty(alphaKey, { syntax: '<percentage>', initialValue: '100%' }))
269272

273+
if (!isSpecial) {
270274
if (keys && !isCSSVar) {
271275
themeTracking(`colors`, keys)
272276
if (!modifier) {

test/assets/output/preset-wind4-targets.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,8 @@
725725
.bg-\[url\(https\:\/\/test\.unocss\.png\)\]{--un-url:url(https://test.unocss.png);background-image:var(--un-url);}
726726
.bg-\#452233\/40,
727727
.bg-hex-452233\/40{background-color:color-mix(in oklab, #452233 40%, transparent) /* #452233 */;}
728+
.bg-current{background-color:currentColor;}
729+
.bg-current\/10{background-color:color-mix(in oklab, currentColor 10%, transparent) /* currentColor */;}
728730
.first-letter\:bg-green-400::first-letter{background-color:color-mix(in srgb, var(--colors-green-400) var(--un-bg-opacity), transparent) /* oklch(79.2% 0.209 151.711) */;}
729731
.\[\&\[data-active\=\"true\"\]\]\:bg-red[data-active="true"]{background-color:color-mix(in srgb, var(--colors-red-DEFAULT) var(--un-bg-opacity), transparent) /* oklch(70.4% 0.191 22.216) */;}
730732
.bg-red-100{background-color:color-mix(in srgb, var(--colors-red-100) var(--un-bg-opacity), transparent) /* oklch(93.6% 0.032 17.717) */;}

test/assets/preset-wind4-targets.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export const presetWind4Targets: string[] = [
9797
'bg-repeat-revert',
9898
'bg-right-bottom',
9999
'bg-scroll',
100+
'bg-current',
101+
'bg-current/10',
100102

101103
// bg gradient
102104
'from-current',

0 commit comments

Comments
 (0)