calculateSpanningCellWidth.js 1.3 KB

1234567891011121314151617181920212223242526
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.calculateSpanningCellWidth = void 0;
  4. const utils_1 = require("./utils");
  5. const calculateSpanningCellWidth = (rangeConfig, dependencies) => {
  6. const { columnsConfig, drawVerticalLine } = dependencies;
  7. const { topLeft, bottomRight } = rangeConfig;
  8. const totalWidth = (0, utils_1.sumArray)(columnsConfig.slice(topLeft.col, bottomRight.col + 1).map(({ width }) => {
  9. return width;
  10. }));
  11. const totalPadding = topLeft.col === bottomRight.col ?
  12. columnsConfig[topLeft.col].paddingRight +
  13. columnsConfig[bottomRight.col].paddingLeft :
  14. (0, utils_1.sumArray)(columnsConfig
  15. .slice(topLeft.col, bottomRight.col + 1)
  16. .map(({ paddingLeft, paddingRight }) => {
  17. return paddingLeft + paddingRight;
  18. }));
  19. const totalBorderWidths = bottomRight.col - topLeft.col;
  20. const totalHiddenVerticalBorders = (0, utils_1.sequence)(topLeft.col + 1, bottomRight.col).filter((verticalBorderIndex) => {
  21. return !drawVerticalLine(verticalBorderIndex, columnsConfig.length);
  22. }).length;
  23. return totalWidth + totalPadding + totalBorderWidths - totalHiddenVerticalBorders;
  24. };
  25. exports.calculateSpanningCellWidth = calculateSpanningCellWidth;
  26. //# sourceMappingURL=calculateSpanningCellWidth.js.map