Skip to content

Commit fd13bf1

Browse files
authored
feat(preset-legacy-compat): add legacyColorSpace option (#4301)
1 parent c2df128 commit fd13bf1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/preset-legacy-compat/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ export interface LegacyCompatOptions {
1111
* @default false
1212
*/
1313
commaStyleColorFunction?: boolean
14+
15+
/**
16+
* Enable legacy color space conversion.
17+
*
18+
* @default false
19+
*/
20+
legacyColorSpace?: boolean
1421
}
1522

1623
/**
@@ -19,6 +26,7 @@ export interface LegacyCompatOptions {
1926
export const presetLegacyCompat = definePreset((options: LegacyCompatOptions = {}) => {
2027
const {
2128
commaStyleColorFunction = false,
29+
legacyColorSpace = false,
2230
} = options
2331

2432
return {
@@ -28,10 +36,15 @@ export const presetLegacyCompat = definePreset((options: LegacyCompatOptions = {
2836
let value = i[1]
2937
if (typeof value !== 'string')
3038
return
39+
3140
if (commaStyleColorFunction)
3241
value = toCommaStyleColorFunction(value)
3342
if (value !== i[1])
3443
i[1] = value
44+
45+
if (legacyColorSpace) {
46+
i[1] = i[1].replace(/\s*in (oklch|oklab)/g, '')
47+
}
3548
})
3649
},
3750
}

test/preset-legacy-compat.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@ describe('preset-legacy-compat', () => {
1616
it('with commaStyleColorFunction', async () => {
1717
const uno = await generateUno({
1818
commaStyleColorFunction: true,
19+
legacyColorSpace: true,
1920
})
2021

2122
const { css } = await uno.generate([
2223
'bg-[rgba(255,255,255,0.1)]',
2324
'text-red',
25+
'bg-gradient-to-b',
2426
].join(' '), { preflights: false })
2527

26-
await expect(css).toMatchInlineSnapshot(`
28+
expect(css).toMatchInlineSnapshot(`
2729
"/* layer: default */
2830
.bg-\\[rgba\\(255\\,255\\,255\\,0\\.1\\)\\]{--un-bg-opacity:0.1;background-color:rgba(255, 255, 255, var(--un-bg-opacity));}
31+
.bg-gradient-to-b{--un-gradient-shape:to bottom;--un-gradient:var(--un-gradient-shape), var(--un-gradient-stops);background-image:linear-gradient(var(--un-gradient));}
2932
.text-red{--un-text-opacity:1;color:rgba(248, 113, 113, var(--un-text-opacity));}"
3033
`)
3134
})

0 commit comments

Comments
 (0)