Skip to content

Commit 7c0e4bc

Browse files
sibbngadamwathan
authored andcommitted
[JIT] Support CSS Variables in arbitrary calc (#4147)
1 parent 2db2f60 commit 7c0e4bc

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

jit/pluginUtils.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ function asValue(modifier, lookup = {}, { validate = () => true, transform = (v)
112112
}
113113

114114
// add spaces around operators inside calc() that do not follow an operator or (
115-
return transform(value).replace(/(?<=^calc\(.+?)(?<![-+*/(])([-+*/])/g, ' $1 ')
115+
return transform(value).replace(
116+
/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
117+
'$1 $2 '
118+
)
116119
}
117120

118121
function asUnit(modifier, units, lookup = {}) {

jit/tests/arbitrary-values.test.css

+9
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,18 @@
4949
.w-\[calc\(100\%\+1rem\)\] {
5050
width: calc(100% + 1rem);
5151
}
52+
.w-\[calc\(var\(--10-10px\2c calc\(-20px-\(-30px--40px\)\)\)-50px\)\] {
53+
width: calc(var(--10-10px, calc(-20px - (-30px - -40px))) - 50px);
54+
}
5255
.w-\[var\(--width\)\] {
5356
width: var(--width);
5457
}
58+
.w-\[var\(--width\2c calc\(100\%\+1rem\)\)\] {
59+
width: var(--width, calc(100% + 1rem));
60+
}
61+
.w-\[calc\(100\%\/3-1rem\*2\)\] {
62+
width: calc(100% / 3 - 1rem * 2);
63+
}
5564
.min-w-\[3\.23rem\] {
5665
min-width: 3.23rem;
5766
}

jit/tests/arbitrary-values.test.html

+3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
<div class="border-[2.5px]"></div>
1717
<div class="w-[3.23rem]"></div>
1818
<div class="w-[calc(100%+1rem)]"></div>
19+
<div class="w-[calc(var(--10-10px,calc(-20px-(-30px--40px)))-50px)]"></div>
1920
<div class="w-[var(--width)]"></div>
21+
<div class="w-[var(--width,calc(100%+1rem))]"></div>
22+
<div class="w-[calc(100%/3-1rem*2)]"></div>
2023
<div class="min-w-[3.23rem]"></div>
2124
<div class="min-w-[calc(100%+1rem)]"></div>
2225
<div class="min-w-[var(--width)]"></div>

0 commit comments

Comments
 (0)