Space.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default,
  21. spaceProps: () => spaceProps
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. const [name, bem] = (0, import_utils.createNamespace)("space");
  28. const spaceProps = {
  29. align: String,
  30. direction: {
  31. type: String,
  32. default: "horizontal"
  33. },
  34. size: {
  35. type: [Number, String, Array],
  36. default: 8
  37. },
  38. wrap: Boolean,
  39. fill: Boolean
  40. };
  41. function filterEmpty(children = []) {
  42. const nodes = [];
  43. children.forEach((child) => {
  44. if (Array.isArray(child)) {
  45. nodes.push(...child);
  46. } else if (child.type === import_vue2.Fragment) {
  47. nodes.push(...filterEmpty(child.children));
  48. } else {
  49. nodes.push(child);
  50. }
  51. });
  52. return nodes.filter((c) => {
  53. var _a;
  54. return !(c && (typeof Comment !== "undefined" && c.type === Comment || c.type === import_vue2.Fragment && ((_a = c.children) == null ? void 0 : _a.length) === 0 || c.type === Text && c.children.trim() === ""));
  55. });
  56. }
  57. var stdin_default = (0, import_vue2.defineComponent)({
  58. name,
  59. props: spaceProps,
  60. setup(props, {
  61. slots
  62. }) {
  63. const mergedAlign = (0, import_vue2.computed)(() => {
  64. var _a;
  65. return (_a = props.align) != null ? _a : props.direction === "horizontal" ? "center" : "";
  66. });
  67. const getMargin = (size) => {
  68. if (typeof size === "number") {
  69. return size + "px";
  70. }
  71. return size;
  72. };
  73. const getMarginStyle = (isLast) => {
  74. const style = {};
  75. const marginRight = `${getMargin(Array.isArray(props.size) ? props.size[0] : props.size)}`;
  76. const marginBottom = `${getMargin(Array.isArray(props.size) ? props.size[1] : props.size)}`;
  77. if (isLast) {
  78. return props.wrap ? {
  79. marginBottom
  80. } : {};
  81. }
  82. if (props.direction === "horizontal") {
  83. style.marginRight = marginRight;
  84. }
  85. if (props.direction === "vertical" || props.wrap) {
  86. style.marginBottom = marginBottom;
  87. }
  88. return style;
  89. };
  90. return () => {
  91. var _a;
  92. const children = filterEmpty((_a = slots.default) == null ? void 0 : _a.call(slots));
  93. return (0, import_vue.createVNode)("div", {
  94. "class": [bem({
  95. [props.direction]: props.direction,
  96. [`align-${mergedAlign.value}`]: mergedAlign.value,
  97. wrap: props.wrap,
  98. fill: props.fill
  99. })]
  100. }, [children.map((c, i) => (0, import_vue.createVNode)("div", {
  101. "key": `item-${i}`,
  102. "class": `${name}-item`,
  103. "style": getMarginStyle(i === children.length - 1)
  104. }, [c]))]);
  105. };
  106. }
  107. });