Skip to content

Commit f1094ed

Browse files
authored
fix(preset-wind4): fix option variable-prefix not working (#5142)
1 parent a48f031 commit f1094ed

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

packages-presets/preset-wind4/src/postprocess/varPrefix.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type { PresetWind4Options } from '..'
33

44
export function varPrefix({ variablePrefix: prefix }: PresetWind4Options): Postprocessor[] {
55
const processor: Postprocessor = (obj) => {
6+
if (obj.layer === 'properties')
7+
obj.selector = obj.selector.replace(/^@property --un-/, `@property --${prefix}`)
8+
69
obj.entries.forEach((i) => {
710
i[0] = i[0].replace(/^--un-/, `--${prefix}`)
811
if (typeof i[1] === 'string')

packages-presets/preset-wind4/src/preflights/property.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ export function property(options: PresetWind4Options): Preflight<Theme> | undefi
1818
const selector = propertyConfig?.selector
1919
?? '*, ::before, ::after, ::backdrop'
2020

21+
const prefix = options.variablePrefix ?? 'un-'
22+
2123
return {
2224
getCSS: () => {
2325
if (trackedProperties.size === 0)
2426
return
2527

2628
const css = Array.from(trackedProperties.entries())
27-
.map(([property, value]) => `${property}:${value};`)
29+
.map(([property, value]) => `${property.replace(/^--un-/, `--${prefix}`)}:${value};`)
2830
.join('')
2931

3032
return parentSelector === false

test/preset-wind4.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,32 @@ describe('preset-wind4', () => {
464464
"
465465
`)
466466
})
467+
468+
it('basic variable prefix', async () => {
469+
const uno = await createGenerator({
470+
presets: [
471+
presetWind4({
472+
variablePrefix: 'foo-',
473+
preflights: {
474+
reset: false,
475+
theme: false,
476+
property: true,
477+
},
478+
}),
479+
],
480+
})
481+
const { css } = await uno.generate('bg-white')
482+
expect(css).toMatchInlineSnapshot(`
483+
"/* layer: properties */
484+
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))){*, ::before, ::after, ::backdrop{--foo-bg-opacity:100%;}}
485+
@property --foo-bg-opacity{syntax:"<percentage>";inherits:false;initial-value:100%;}
486+
/* layer: default */
487+
.bg-white{background-color:color-mix(in srgb, var(--colors-white) var(--foo-bg-opacity), transparent);}
488+
@supports (color: color-mix(in lab, red, red)){
489+
.bg-white{background-color:color-mix(in oklab, var(--colors-white) var(--foo-bg-opacity), transparent);}
490+
}"
491+
`)
492+
})
467493
})
468494

469495
describe('important', () => {

0 commit comments

Comments
 (0)