calculateRowHeights.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.calculateRowHeights = void 0;
  4. const calculateCellHeight_1 = require("./calculateCellHeight");
  5. const utils_1 = require("./utils");
  6. /**
  7. * Produces an array of values that describe the largest value length (height) in every row.
  8. */
  9. const calculateRowHeights = (rows, config) => {
  10. const rowHeights = [];
  11. for (const [rowIndex, row] of rows.entries()) {
  12. let rowHeight = 1;
  13. row.forEach((cell, cellIndex) => {
  14. var _a;
  15. const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
  16. row: rowIndex });
  17. if (!containingRange) {
  18. const cellHeight = (0, calculateCellHeight_1.calculateCellHeight)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
  19. rowHeight = Math.max(rowHeight, cellHeight);
  20. return;
  21. }
  22. const { topLeft, bottomRight, height } = containingRange;
  23. // bottom-most cell of a range needs to contain all remain lines of spanning cells
  24. if (rowIndex === bottomRight.row) {
  25. const totalOccupiedSpanningCellHeight = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row));
  26. const totalHorizontalBorderHeight = bottomRight.row - topLeft.row;
  27. const totalHiddenHorizontalBorderHeight = (0, utils_1.sequence)(topLeft.row + 1, bottomRight.row).filter((horizontalBorderIndex) => {
  28. var _a;
  29. /* istanbul ignore next */
  30. return !((_a = config.drawHorizontalLine) === null || _a === void 0 ? void 0 : _a.call(config, horizontalBorderIndex, rows.length));
  31. }).length;
  32. const cellHeight = height - totalOccupiedSpanningCellHeight - totalHorizontalBorderHeight + totalHiddenHorizontalBorderHeight;
  33. rowHeight = Math.max(rowHeight, cellHeight);
  34. }
  35. // otherwise, just depend on other sibling cell heights in the row
  36. });
  37. rowHeights.push(rowHeight);
  38. }
  39. return rowHeights;
  40. };
  41. exports.calculateRowHeights = calculateRowHeights;
  42. //# sourceMappingURL=calculateRowHeights.js.map