negateValue.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "default", {
  6. enumerable: true,
  7. get: function() {
  8. return negateValue;
  9. }
  10. });
  11. function negateValue(value) {
  12. value = `${value}`;
  13. if (value === "0") {
  14. return "0";
  15. }
  16. // Flip sign of numbers
  17. if (/^[+-]?(\d+|\d*\.\d+)(e[+-]?\d+)?(%|\w+)?$/.test(value)) {
  18. return value.replace(/^[+-]?/, (sign)=>sign === "-" ? "" : "-");
  19. }
  20. // What functions we support negating numeric values for
  21. // var() isn't inherently a numeric function but we support it anyway
  22. // The trigonometric functions are omitted because you'll need to use calc(…) with them _anyway_
  23. // to produce generally useful results and that will be covered already
  24. let numericFunctions = [
  25. "var",
  26. "calc",
  27. "min",
  28. "max",
  29. "clamp"
  30. ];
  31. for (const fn of numericFunctions){
  32. if (value.includes(`${fn}(`)) {
  33. return `calc(${value} * -1)`;
  34. }
  35. }
  36. }