margin.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const positions = ["top", "right", "bottom", "left"];
  4. module.exports.parse = function parse(v) {
  5. const val = parsers.parseMeasurement(v);
  6. if (val) {
  7. return val;
  8. }
  9. return parsers.parseKeyword(v, ["auto"]);
  10. };
  11. module.exports.isValid = function isValid(v) {
  12. if (v === "") {
  13. return true;
  14. }
  15. return typeof module.exports.parse(v) === "string";
  16. };
  17. module.exports.definition = {
  18. set(v) {
  19. v = parsers.prepareValue(v, this._global);
  20. if (parsers.hasVarFunc(v)) {
  21. this._implicitSetter(
  22. "margin",
  23. "",
  24. "",
  25. module.exports.isValid,
  26. module.exports.parse,
  27. positions
  28. );
  29. this._setProperty("margin", v);
  30. } else {
  31. this._implicitSetter(
  32. "margin",
  33. "",
  34. v,
  35. module.exports.isValid,
  36. module.exports.parse,
  37. positions
  38. );
  39. }
  40. },
  41. get() {
  42. const val = this._implicitGetter("margin", positions);
  43. if (val === "") {
  44. return this.getPropertyValue("margin");
  45. }
  46. if (parsers.hasVarFunc(val)) {
  47. return "";
  48. }
  49. return val;
  50. },
  51. enumerable: true,
  52. configurable: true
  53. };