Row.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. ROW_KEY: () => ROW_KEY,
  21. default: () => stdin_default,
  22. rowProps: () => rowProps
  23. });
  24. module.exports = __toCommonJS(stdin_exports);
  25. var import_vue = require("vue");
  26. var import_vue2 = require("vue");
  27. var import_utils = require("../utils");
  28. var import_use = require("@vant/use");
  29. const [name, bem] = (0, import_utils.createNamespace)("row");
  30. const ROW_KEY = Symbol(name);
  31. const rowProps = {
  32. tag: (0, import_utils.makeStringProp)("div"),
  33. wrap: import_utils.truthProp,
  34. align: String,
  35. gutter: (0, import_utils.makeNumericProp)(0),
  36. justify: String
  37. };
  38. var stdin_default = (0, import_vue2.defineComponent)({
  39. name,
  40. props: rowProps,
  41. setup(props, {
  42. slots
  43. }) {
  44. const {
  45. children,
  46. linkChildren
  47. } = (0, import_use.useChildren)(ROW_KEY);
  48. const groups = (0, import_vue2.computed)(() => {
  49. const groups2 = [[]];
  50. let totalSpan = 0;
  51. children.forEach((child, index) => {
  52. totalSpan += Number(child.span);
  53. if (totalSpan > 24) {
  54. groups2.push([index]);
  55. totalSpan -= 24;
  56. } else {
  57. groups2[groups2.length - 1].push(index);
  58. }
  59. });
  60. return groups2;
  61. });
  62. const spaces = (0, import_vue2.computed)(() => {
  63. const gutter = Number(props.gutter);
  64. const spaces2 = [];
  65. if (!gutter) {
  66. return spaces2;
  67. }
  68. groups.value.forEach((group) => {
  69. const averagePadding = gutter * (group.length - 1) / group.length;
  70. group.forEach((item, index) => {
  71. if (index === 0) {
  72. spaces2.push({
  73. right: averagePadding
  74. });
  75. } else {
  76. const left = gutter - spaces2[item - 1].right;
  77. const right = averagePadding - left;
  78. spaces2.push({
  79. left,
  80. right
  81. });
  82. }
  83. });
  84. });
  85. return spaces2;
  86. });
  87. linkChildren({
  88. spaces
  89. });
  90. return () => {
  91. const {
  92. tag,
  93. wrap,
  94. align,
  95. justify
  96. } = props;
  97. return (0, import_vue.createVNode)(tag, {
  98. "class": bem({
  99. [`align-${align}`]: align,
  100. [`justify-${justify}`]: justify,
  101. nowrap: !wrap
  102. })
  103. }, {
  104. default: () => {
  105. var _a;
  106. return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
  107. }
  108. });
  109. };
  110. }
  111. });