Skip to content

Commit 25b3aba

Browse files
committed
Use reduce-css-calc to avoid inspecting value to negate
1 parent 4695f53 commit 25b3aba

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

__tests__/resolveConfig.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ test('custom properties are multiplied by -1 for negative values', () => {
11881188
'-4': '-4px',
11891189
'-foo': 'calc(var(--foo) * -1)',
11901190
'-bar': 'calc(var(--bar, 500px) * -1)',
1191-
'-baz': 'calc(calc(50% - 10px) * -1)',
1191+
'-baz': 'calc(-50% - -10px)',
11921192
},
11931193
},
11941194
variants: {},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"postcss-js": "^2.0.0",
5252
"postcss-nested": "^4.1.1",
5353
"postcss-selector-parser": "^6.0.0",
54-
"pretty-hrtime": "^1.0.3"
54+
"pretty-hrtime": "^1.0.3",
55+
"reduce-css-calc": "^2.1.6"
5556
},
5657
"browserslist": [
5758
"> 1%"

src/util/resolveConfig.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import isFunction from 'lodash/isFunction'
33
import defaults from 'lodash/defaults'
44
import map from 'lodash/map'
55
import toPath from 'lodash/toPath'
6-
import startsWith from 'lodash/startsWith'
6+
import reduceCalc from 'reduce-css-calc'
77

88
const configUtils = {
99
negative(scale) {
@@ -12,9 +12,7 @@ const configUtils = {
1212
.reduce(
1313
(negativeScale, key) => ({
1414
...negativeScale,
15-
[`-${key}`]: ['var(', 'calc('].some(prefix => startsWith(scale[key], prefix))
16-
? `calc(${scale[key]} * -1)`
17-
: `-${scale[key]}`,
15+
[`-${key}`]: reduceCalc(`calc(${scale[key]} * -1)`),
1816
}),
1917
{}
2018
)

yarn.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,11 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
14751475
shebang-command "^1.2.0"
14761476
which "^1.2.9"
14771477

1478+
css-unit-converter@^1.1.1:
1479+
version "1.1.1"
1480+
resolved "https://registry.yarnpkg.com/css-unit-converter/-/css-unit-converter-1.1.1.tgz#d9b9281adcfd8ced935bdbaba83786897f64e996"
1481+
integrity sha1-2bkoGtz9jO2TW9urqDeGiX9k6ZY=
1482+
14781483
cssesc@^2.0.0:
14791484
version "2.0.0"
14801485
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-2.0.0.tgz#3b13bd1bb1cb36e1bcb5a4dcd27f54c5dcb35703"
@@ -4006,6 +4011,14 @@ realpath-native@^1.1.0:
40064011
dependencies:
40074012
util.promisify "^1.0.0"
40084013

4014+
reduce-css-calc@^2.1.6:
4015+
version "2.1.6"
4016+
resolved "https://registry.yarnpkg.com/reduce-css-calc/-/reduce-css-calc-2.1.6.tgz#050fe6ee7d98a1d70775d2e93ce0b713cee394d2"
4017+
integrity sha512-+l5/qlQmdsbM9h6JerJ/y5vR5Ci0k93aszLNpCmbadC3nBcbRGmIBm0s9Nj59i22LvCjTGftWzdQRwdknayxhw==
4018+
dependencies:
4019+
css-unit-converter "^1.1.1"
4020+
postcss-value-parser "^3.3.0"
4021+
40094022
regenerate-unicode-properties@^8.0.2:
40104023
version "8.1.0"
40114024
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e"

0 commit comments

Comments
 (0)