borderSpacing.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "border-spacing";
  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) {
  14. switch (value.length) {
  15. case 1: {
  16. return parsers.resolveNumericValue(value, {
  17. type: "length"
  18. });
  19. }
  20. case 2: {
  21. const [part1, part2] = value;
  22. const val1 = parsers.resolveNumericValue([part1], {
  23. type: "length"
  24. });
  25. const val2 = parsers.resolveNumericValue([part2], {
  26. type: "length"
  27. });
  28. if (val1 && val2) {
  29. return `${val1} ${val2}`;
  30. }
  31. break;
  32. }
  33. default:
  34. }
  35. } else if (typeof value === "string") {
  36. return value;
  37. }
  38. };
  39. module.exports.definition = {
  40. set(v) {
  41. v = parsers.prepareValue(v);
  42. if (parsers.hasVarFunc(v)) {
  43. this._setProperty(property, v);
  44. } else {
  45. const val = module.exports.parse(v, {
  46. globalObject: this._global
  47. });
  48. if (typeof val === "string") {
  49. const priority = this._priorities.get(property) ?? "";
  50. this._setProperty(property, val, priority);
  51. }
  52. }
  53. },
  54. get() {
  55. return this.getPropertyValue(property);
  56. },
  57. enumerable: true,
  58. configurable: true
  59. };
  60. module.exports.property = property;