marginLeft.js 1.2 KB

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