UNPKG

2.36 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.alignVerticalRangeContent = exports.wrapRangeContent = void 0;
4const alignString_1 = require("./alignString");
5const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
6const padTableData_1 = require("./padTableData");
7const truncateTableData_1 = require("./truncateTableData");
8const utils_1 = require("./utils");
9const wrapCell_1 = require("./wrapCell");
10/**
11 * Fill content into all cells in range in order to calculate total height
12 */
13const wrapRangeContent = (rangeConfig, rangeWidth, context) => {
14 const { topLeft, paddingRight, paddingLeft, truncate, wrapWord, alignment } = rangeConfig;
15 const originalContent = context.rows[topLeft.row][topLeft.col];
16 const contentWidth = rangeWidth - paddingLeft - paddingRight;
17 return (0, wrapCell_1.wrapCell)((0, truncateTableData_1.truncateString)(originalContent, truncate), contentWidth, wrapWord).map((line) => {
18 const alignedLine = (0, alignString_1.alignString)(line, contentWidth, alignment);
19 return (0, padTableData_1.padString)(alignedLine, paddingLeft, paddingRight);
20 });
21};
22exports.wrapRangeContent = wrapRangeContent;
23const alignVerticalRangeContent = (range, content, context) => {
24 const { rows, drawHorizontalLine, rowHeights } = context;
25 const { topLeft, bottomRight, verticalAlignment } = range;
26 // They are empty before calculateRowHeights function run
27 if (rowHeights.length === 0) {
28 return [];
29 }
30 const totalCellHeight = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row, bottomRight.row + 1));
31 const totalBorderHeight = bottomRight.row - topLeft.row;
32 const hiddenHorizontalBorderCount = (0, utils_1.sequence)(topLeft.row + 1, bottomRight.row).filter((horizontalBorderIndex) => {
33 return !drawHorizontalLine(horizontalBorderIndex, rows.length);
34 }).length;
35 const availableRangeHeight = totalCellHeight + totalBorderHeight - hiddenHorizontalBorderCount;
36 return (0, mapDataUsingRowHeights_1.padCellVertically)(content, availableRangeHeight, verticalAlignment).map((line) => {
37 if (line.length === 0) {
38 return ' '.repeat(content[0].length);
39 }
40 return line;
41 });
42};
43exports.alignVerticalRangeContent = alignVerticalRangeContent;
44//# sourceMappingURL=alignSpanningCell.js.map
\No newline at end of file