diff --git a/src/utils/handlers/handlers.ts b/src/utils/handlers/handlers.ts index c8b170d..7c08cd7 100644 --- a/src/utils/handlers/handlers.ts +++ b/src/utils/handlers/handlers.ts @@ -136,7 +136,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 0000000..85f786b --- /dev/null +++ b/test/handler.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, it } from 'vitest' +import { handler as h } from '../src/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)') + }) +})