flexShrink.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "flex-shrink";
  4. const shorthand = "flex";
  5. module.exports.parse = (v, opt = {}) => {
  6. const { globalObject } = opt;
  7. if (v === "") {
  8. return v;
  9. }
  10. const value = parsers.parsePropertyValue(property, v, {
  11. globalObject,
  12. inArray: true
  13. });
  14. if (Array.isArray(value) && value.length === 1) {
  15. return parsers.resolveNumericValue(value, {
  16. min: 0
  17. });
  18. } else if (typeof value === "string") {
  19. return value;
  20. }
  21. };
  22. module.exports.definition = {
  23. set(v) {
  24. v = parsers.prepareValue(v);
  25. if (parsers.hasVarFunc(v)) {
  26. this._setProperty(shorthand, "");
  27. this._setProperty(property, v);
  28. } else {
  29. const val = module.exports.parse(v, {
  30. globalObject: this._global
  31. });
  32. if (typeof val === "string") {
  33. const priority =
  34. !this._priorities.get(shorthand) && this._priorities.has(property)
  35. ? this._priorities.get(property)
  36. : "";
  37. this._flexBoxSetter(property, val, priority, shorthand);
  38. }
  39. }
  40. },
  41. get() {
  42. return this.getPropertyValue(property);
  43. },
  44. enumerable: true,
  45. configurable: true
  46. };
  47. module.exports.property = property;