borderSpacing.js 896 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. const parsers = require("../parsers");
  3. module.exports.parse = function parse(v) {
  4. if (v === "") {
  5. return v;
  6. }
  7. const key = parsers.parseKeyword(v);
  8. if (key) {
  9. return key;
  10. }
  11. const parts = parsers.splitValue(v);
  12. if (!parts.length || parts.length > 2) {
  13. return;
  14. }
  15. const val = [];
  16. for (const part of parts) {
  17. const dim = parsers.parseLength(part);
  18. if (!dim) {
  19. return;
  20. }
  21. val.push(dim);
  22. }
  23. return val.join(" ");
  24. };
  25. module.exports.isValid = function isValid(v) {
  26. if (v === "") {
  27. return true;
  28. }
  29. return typeof module.exports.parse(v) === "string";
  30. };
  31. module.exports.definition = {
  32. set(v) {
  33. v = parsers.prepareValue(v, this._global);
  34. this._setProperty("border-spacing", module.exports.parse(v));
  35. },
  36. get() {
  37. return this.getPropertyValue("border-spacing");
  38. },
  39. enumerable: true,
  40. configurable: true
  41. };