border.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const borderWidth = require("./borderWidth");
  4. const borderStyle = require("./borderStyle");
  5. const borderColor = require("./borderColor");
  6. const shorthandFor = new Map([
  7. ["border-width", borderWidth],
  8. ["border-style", borderStyle],
  9. ["border-color", borderColor]
  10. ]);
  11. module.exports.definition = {
  12. set(v) {
  13. v = parsers.prepareValue(v, this._global);
  14. if (/^none$/i.test(v)) {
  15. v = "";
  16. }
  17. if (parsers.hasVarFunc(v)) {
  18. for (const [key] of shorthandFor) {
  19. this._setProperty(key, "");
  20. }
  21. this._setProperty("border", v);
  22. } else {
  23. this._midShorthandSetter("border", v, shorthandFor, ["top", "right", "bottom", "left"]);
  24. }
  25. },
  26. get() {
  27. let val = this.getPropertyValue("border");
  28. if (parsers.hasVarFunc(val)) {
  29. return val;
  30. }
  31. val = this._shorthandGetter("border", shorthandFor);
  32. if (parsers.hasVarFunc(val)) {
  33. return "";
  34. }
  35. return val;
  36. },
  37. enumerable: true,
  38. configurable: true
  39. };