1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.calculateMaximumColumnWidths = exports.calculateMaximumCellWidth = void 0;
|
7 | const string_width_1 = __importDefault(require("string-width"));
|
8 | const utils_1 = require("./utils");
|
9 | const calculateMaximumCellWidth = (cell) => {
|
10 | return Math.max(...cell.split('\n').map(string_width_1.default));
|
11 | };
|
12 | exports.calculateMaximumCellWidth = calculateMaximumCellWidth;
|
13 |
|
14 |
|
15 |
|
16 | const calculateMaximumColumnWidths = (rows, spanningCellConfigs = []) => {
|
17 | const columnWidths = new Array(rows[0].length).fill(0);
|
18 | const rangeCoordinates = spanningCellConfigs.map(utils_1.calculateRangeCoordinate);
|
19 | const isSpanningCell = (rowIndex, columnIndex) => {
|
20 | return rangeCoordinates.some((rangeCoordinate) => {
|
21 | return (0, utils_1.isCellInRange)({ col: columnIndex,
|
22 | row: rowIndex }, rangeCoordinate);
|
23 | });
|
24 | };
|
25 | rows.forEach((row, rowIndex) => {
|
26 | row.forEach((cell, cellIndex) => {
|
27 | if (isSpanningCell(rowIndex, cellIndex)) {
|
28 | return;
|
29 | }
|
30 | columnWidths[cellIndex] = Math.max(columnWidths[cellIndex], (0, exports.calculateMaximumCellWidth)(cell));
|
31 | });
|
32 | });
|
33 | return columnWidths;
|
34 | };
|
35 | exports.calculateMaximumColumnWidths = calculateMaximumColumnWidths;
|
36 |
|
\ | No newline at end of file |