From 2f82781055507b60af1d6f2b49e5ea8e4d8a1afc Mon Sep 17 00:00:00 2001 From: Saya Date: Sat, 25 Jun 2022 12:11:13 +0800 Subject: [PATCH] wip --- .../preset-mini/src/utils/handlers/handlers.ts | 2 +- test/handler.test.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/handler.test.ts diff --git a/packages/preset-mini/src/utils/handlers/handlers.ts b/packages/preset-mini/src/utils/handlers/handlers.ts index 08fe41ab3b..f3e069a45f 100644 --- a/packages/preset-mini/src/utils/handlers/handlers.ts +++ b/packages/preset-mini/src/utils/handlers/handlers.ts @@ -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 ') }) } diff --git a/test/handler.test.ts b/test/handler.test.ts new file mode 100644 index 0000000000..ce1ef778f9 --- /dev/null +++ b/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)') + }) +})