width.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "width";
  4. module.exports.parse = (v, opt = {}) => {
  5. const { globalObject } = opt;
  6. if (v === "") {
  7. return v;
  8. }
  9. const value = parsers.parsePropertyValue(property, v, {
  10. globalObject,
  11. inArray: true
  12. });
  13. if (Array.isArray(value) && value.length === 1) {
  14. return parsers.resolveNumericValue(value, {
  15. min: 0,
  16. type: "length"
  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(property, v);
  27. } else {
  28. const val = module.exports.parse(v, {
  29. globalObject: this._global
  30. });
  31. if (typeof val === "string") {
  32. const priority = this._priorities.get(property) ?? "";
  33. this._setProperty(property, val, priority);
  34. }
  35. }
  36. },
  37. get() {
  38. return this.getPropertyValue(property);
  39. },
  40. enumerable: true,
  41. configurable: true
  42. };
  43. module.exports.property = property;