Skip to content

Commit

Permalink
fix(preset-mini): stricter color match, close #1296
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 19, 2022
1 parent 54d0e32 commit 671e30b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/preset-mini/src/utils/utilities.ts
Expand Up @@ -83,9 +83,9 @@ export function parseColor(body: string, theme: Theme): ParsedColorValue | undef
const bracket = h.bracketOfColor(main)
const bracketOrMain = bracket || main

if (bracketOrMain.startsWith('#'))
if (bracketOrMain.match(/^#[\da-fA-F]+/g))
color = bracketOrMain
else if (bracketOrMain.startsWith('hex-'))
else if (bracketOrMain.match(/^hex-[\da-fA-F]+/g))
color = `#${bracketOrMain.slice(4)}`
else if (main.startsWith('$'))
color = h.cssvar(main)
Expand Down
16 changes: 16 additions & 0 deletions test/color.test.ts
Expand Up @@ -170,5 +170,21 @@ describe('color utils', () => {
expect(fn('danger/$o3')).eql({
prop: 'hsla(var(--danger),var(--o3))',
})

expect(fn('hex-fff')).eql({
'--un-v-opacity': 1,
'prop': 'rgba(255,255,255,var(--un-v-opacity))',
})

expect(fn('hex-fff/10')).eql({
prop: 'rgba(255,255,255,0.1)',
})

expect(fn('$abc')).eql({
prop: 'var(--abc)',
})

// invalid
expect(fn('hex-invalid')).eql({})
})
})

0 comments on commit 671e30b

Please sign in to comment.