2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.mapDataUsingRowHeights = void 0;
4 const wrapCell_1 = require("./wrapCell");
5 const createEmptyStrings = (length) => {
6 return new Array(length).fill('');
8 const padCellVertically = (lines, rowHeight, columnConfig) => {
9 const { verticalAlignment } = columnConfig;
10 const availableLines = rowHeight - lines.length;
11 if (verticalAlignment === 'top') {
12 return [...lines, ...createEmptyStrings(availableLines)];
14 if (verticalAlignment === 'bottom') {
15 return [...createEmptyStrings(availableLines), ...lines];
18 ...createEmptyStrings(Math.floor(availableLines / 2)),
20 ...createEmptyStrings(Math.ceil(availableLines / 2)),
23 const flatten = (array) => {
24 return [].concat(...array);
26 const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
27 const tableWidth = unmappedRows[0].length;
28 const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
29 const outputRowHeight = rowHeights[unmappedRowIndex];
30 const outputRow = Array.from({ length: outputRowHeight }, () => {
31 return new Array(tableWidth).fill('');
33 unmappedRow.forEach((cell, cellIndex) => {
34 const cellLines = (0, wrapCell_1.wrapCell)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
35 const paddedCellLines = padCellVertically(cellLines, outputRowHeight, config.columns[cellIndex]);
36 paddedCellLines.forEach((cellLine, cellLineIndex) => {
37 outputRow[cellLineIndex][cellIndex] = cellLine;
42 return flatten(mappedRows);
44 exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
45 //# sourceMappingURL=mapDataUsingRowHeights.js.map