|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
771 bytes
|
| Line | |
|---|
| 1 | export default function negateValue(value) {
|
|---|
| 2 | value = `${value}`
|
|---|
| 3 |
|
|---|
| 4 | if (value === '0') {
|
|---|
| 5 | return '0'
|
|---|
| 6 | }
|
|---|
| 7 |
|
|---|
| 8 | // Flip sign of numbers
|
|---|
| 9 | if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
|
|---|
| 10 | return value.replace(/^[+-]?/, (sign) => (sign === '-' ? '' : '-'))
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | // What functions we support negating numeric values for
|
|---|
| 14 | // var() isn't inherently a numeric function but we support it anyway
|
|---|
| 15 | // The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
|
|---|
| 16 | // to produce generally useful results and that will be covered already
|
|---|
| 17 | let numericFunctions = ['var', 'calc', 'min', 'max', 'clamp']
|
|---|
| 18 |
|
|---|
| 19 | for (const fn of numericFunctions) {
|
|---|
| 20 | if (value.includes(`${fn}(`)) {
|
|---|
| 21 | return `calc(${value} * -1)`
|
|---|
| 22 | }
|
|---|
| 23 | }
|
|---|
| 24 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.