Skip to content

Commit

Permalink
feat(preset-mini): add formatting support for clamp, max & min functi…
Browse files Browse the repository at this point in the history
…ons (#1155)
  • Loading branch information
chu121su12 committed Jun 25, 2022
1 parent 2c4fa1d commit 9673316
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/preset-mini/src/utils/handlers/handlers.ts
Expand Up @@ -109,7 +109,7 @@ function bracketWithType(str: string, type?: string) {
return base
.replace(/(url\(.*?\))/g, v => v.replace(/_/g, '\\_'))
.replace(/([^\\])_/g, '$1 ')
.replace(/calc\((.*)/g, (v) => {
.replace(/(?:calc|clamp|max|min)\((.*)/g, (v) => {
return v.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ')
})
}
Expand Down
15 changes: 15 additions & 0 deletions test/handler.test.ts
@@ -0,0 +1,15 @@
import { describe, expect, it } from 'vitest'
import { handler as h } from '@unocss/preset-mini/utils'

describe('value handler', () => {
it('bracket math function', () => {
expect(h.bracket('[calc(1-2)]')).eql('calc(1 - 2)')
expect(h.bracket('[min(1-2)]')).eql('min(1 - 2)')
expect(h.bracket('[max(1-2)]')).eql('max(1 - 2)')
expect(h.bracket('[clamp(1-2)]')).eql('clamp(1 - 2)')

expect(h.bracket('[calc(1+2)]')).eql('calc(1 + 2)')
expect(h.bracket('[calc(1/2)]')).eql('calc(1 / 2)')
expect(h.bracket('[calc(1*2)]')).eql('calc(1 * 2)')
})
})

0 comments on commit 9673316

Please sign in to comment.