Skip to content

Commit 6fe9cb4

Browse files
committed
add support for calc() in arbitrary values
1 parent d3ca721 commit 6fe9cb4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/pluginUtils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ function asValue(modifier, lookup = {}, { validate = () => true, transform = (v)
110110
function asUnit(modifier, units, lookup = {}) {
111111
return asValue(modifier, lookup, {
112112
validate: (value) => {
113-
let pattern = new RegExp(`.+(${units.join('|')})$`, 'g')
114-
return value.match(pattern) !== null
113+
let unitsPattern = `(?:${units.join('|')})`
114+
return (
115+
new RegExp(`${unitsPattern}$`).test(value) ||
116+
new RegExp(`^calc\\(.+?${unitsPattern}`).test(value)
117+
)
118+
},
119+
transform: (value) => {
120+
// add spaces around operators inside calc() that do not follow an operator or (
121+
return value.replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
115122
},
116123
})
117124
}

0 commit comments

Comments
 (0)