Update Stylelint and Postcss

R=jacktfranklin@chromium.org

Bug: none
Change-Id: I961be18530d3ccbc4efed0c2cda9bd603b14e27b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3372931
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
This commit is contained in:
Tim van der Lippe
2022-01-07 14:36:30 +00:00
committed by Devtools-frontend LUCI CQ
parent 0150c2a641
commit 4cb097430f
367 changed files with 6536 additions and 18593 deletions
+79 -1
View File
@@ -3,7 +3,7 @@
> Produces a string that represents array data in a text table.
[![Travis build status](http://img.shields.io/travis/gajus/table/master.svg?style=flat-square)](https://travis-ci.org/gajus/table)
[![Github action status](https://github.com/gajus/table/actions/workflows/main.yml/badge.svg)](https://github.com/gajus/table/actions)
[![Coveralls](https://img.shields.io/coveralls/gajus/table.svg?style=flat-square)](https://coveralls.io/github/gajus/table)
[![NPM version](http://img.shields.io/npm/v/table.svg?style=flat-square)](https://www.npmjs.org/package/table)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
@@ -548,6 +548,8 @@ Type: `object`
Header configuration.
*Deprecated in favor of the new spanning cells API.*
The header configuration inherits the most of the column's, except:
- `content` **{string}**: the header content.
- `width:` calculate based on the content width automatically.
@@ -589,6 +591,82 @@ console.log(table(data, config));
```
<a name="table-api-table-1-config-spanningcells"></a>
##### config.spanningCells
Type: `SpanningCellConfig[]`
Spanning cells configuration.
The configuration should be straightforward: just specify an array of minimal cell configurations including the position of top-left cell
and the number of columns and/or rows will be expanded from it.
The content of overlap cells will be ignored to make the `data` shape be consistent.
By default, the configuration of column that the top-left cell belongs to will be applied to the whole spanning cell, except:
* The `width` will be summed up of all spanning columns.
* The `paddingRight` will be received from the right-most column intentionally.
Advances customized column-like styles can be configurable to each spanning cell to overwrite the default behavior.
```js
const data = [
['Test Coverage Report', '', '', '', '', ''],
['Module', 'Component', 'Test Cases', 'Failures', 'Durations', 'Success Rate'],
['Services', 'User', '50', '30', '3m 7s', '60.0%'],
['', 'Payment', '100', '80', '7m 15s', '80.0%'],
['Subtotal', '', '150', '110', '10m 22s', '73.3%'],
['Controllers', 'User', '24', '18', '1m 30s', '75.0%'],
['', 'Payment', '30', '24', '50s', '80.0%'],
['Subtotal', '', '54', '42', '2m 20s', '77.8%'],
['Total', '', '204', '152', '12m 42s', '74.5%'],
];
const config = {
columns: [
{ alignment: 'center', width: 12 },
{ alignment: 'center', width: 10 },
{ alignment: 'right' },
{ alignment: 'right' },
{ alignment: 'right' },
{ alignment: 'right' }
],
spanningCells: [
{ col: 0, row: 0, colSpan: 6 },
{ col: 0, row: 2, rowSpan: 2, verticalAlignment: 'middle'},
{ col: 0, row: 4, colSpan: 2, alignment: 'right'},
{ col: 0, row: 5, rowSpan: 2, verticalAlignment: 'middle'},
{ col: 0, row: 7, colSpan: 2, alignment: 'right' },
{ col: 0, row: 8, colSpan: 2, alignment: 'right' }
],
};
console.log(table(data, config));
```
```
╔══════════════════════════════════════════════════════════════════════════════╗
║ Test Coverage Report ║
╟──────────────┬────────────┬────────────┬──────────┬───────────┬──────────────╢
║ Module │ Component │ Test Cases │ Failures │ Durations │ Success Rate ║
╟──────────────┼────────────┼────────────┼──────────┼───────────┼──────────────╢
║ │ User │ 50 │ 30 │ 3m 7s │ 60.0% ║
║ Services ├────────────┼────────────┼──────────┼───────────┼──────────────╢
║ │ Payment │ 100 │ 80 │ 7m 15s │ 80.0% ║
╟──────────────┴────────────┼────────────┼──────────┼───────────┼──────────────╢
║ Subtotal │ 150 │ 110 │ 10m 22s │ 73.3% ║
╟──────────────┬────────────┼────────────┼──────────┼───────────┼──────────────╢
║ │ User │ 24 │ 18 │ 1m 30s │ 75.0% ║
║ Controllers ├────────────┼────────────┼──────────┼───────────┼──────────────╢
║ │ Payment │ 30 │ 24 │ 50s │ 80.0% ║
╟──────────────┴────────────┼────────────┼──────────┼───────────┼──────────────╢
║ Subtotal │ 54 │ 42 │ 2m 20s │ 77.8% ║
╟───────────────────────────┼────────────┼──────────┼───────────┼──────────────╢
║ Total │ 204 │ 152 │ 12m 42s │ 74.5% ║
╚═══════════════════════════╧════════════╧══════════╧═══════════╧══════════════╝
```
<a name="table-api-createstream"></a>
### createStream
-13
View File
@@ -1,13 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alignTableData = void 0;
const alignString_1 = require("./alignString");
const alignTableData = (rows, config) => {
return rows.map((row) => {
return row.map((cell, cellIndex) => {
const { width, alignment } = config.columns[cellIndex];
return alignString_1.alignString(cell, width, alignment);
});
});
};
exports.alignTableData = alignTableData;
-5
View File
@@ -1,5 +0,0 @@
import type { Cell } from './types/internal';
/**
* Calculates width of each cell contents in a row.
*/
export declare const calculateCellWidths: (cells: Cell[]) => number[];
-16
View File
@@ -1,16 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateCellWidths = void 0;
const string_width_1 = __importDefault(require("string-width"));
/**
* Calculates width of each cell contents in a row.
*/
const calculateCellWidths = (cells) => {
return cells.map((cell) => {
return Math.max(...cell.split('\n').map(string_width_1.default));
});
};
exports.calculateCellWidths = calculateCellWidths;
-6
View File
@@ -1,6 +0,0 @@
import type { Row } from './types/internal';
declare const _default: (rows: Row[]) => number[];
/**
* Produces an array of values that describe the largest value length (width) in every column.
*/
export default _default;
-16
View File
@@ -1,16 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const calculateCellWidths_1 = require("./calculateCellWidths");
/**
* Produces an array of values that describe the largest value length (width) in every column.
*/
exports.default = (rows) => {
const columnWidths = new Array(rows[0].length).fill(0);
rows.forEach((row) => {
const cellWidths = calculateCellWidths_1.calculateCellWidths(row);
cellWidths.forEach((cellWidth, cellIndex) => {
columnWidths[cellIndex] = Math.max(columnWidths[cellIndex], cellWidth);
});
});
return columnWidths;
};
-18
View File
@@ -1,18 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateRowHeights = void 0;
const calculateCellHeight_1 = require("./calculateCellHeight");
/**
* Produces an array of values that describe the largest value length (height) in every row.
*/
const calculateRowHeights = (rows, config) => {
return rows.map((row) => {
let rowHeight = 1;
row.forEach((cell, cellIndex) => {
const cellHeight = calculateCellHeight_1.calculateCellHeight(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
rowHeight = Math.max(rowHeight, cellHeight);
});
return rowHeight;
});
};
exports.calculateRowHeights = calculateRowHeights;
-26
View File
@@ -1,26 +0,0 @@
import type { DrawVerticalLine } from './types/api';
import type { TableConfig, SeparatorGetter, TopBorderConfig, JoinBorderConfig, BottomBorderConfig } from './types/internal';
declare type Separator = {
readonly left: string;
readonly right: string;
readonly body: string;
readonly join: string;
};
declare const drawBorder: (columnWidths: number[], config: {
separator: Separator;
drawVerticalLine: DrawVerticalLine;
}) => string;
declare const drawBorderTop: (columnWidths: number[], config: {
border: TopBorderConfig;
drawVerticalLine: DrawVerticalLine;
}) => string;
declare const drawBorderJoin: (columnWidths: number[], config: {
border: JoinBorderConfig;
drawVerticalLine: DrawVerticalLine;
}) => string;
declare const drawBorderBottom: (columnWidths: number[], config: {
border: BottomBorderConfig;
drawVerticalLine: DrawVerticalLine;
}) => string;
export declare const createTableBorderGetter: (columnWidths: number[], config: TableConfig) => SeparatorGetter;
export { drawBorder, drawBorderBottom, drawBorderJoin, drawBorderTop, };
-100
View File
@@ -1,100 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = exports.createTableBorderGetter = void 0;
const drawContent_1 = require("./drawContent");
const drawBorder = (columnWidths, config) => {
const { separator, drawVerticalLine } = config;
const columns = columnWidths.map((size) => {
return config.separator.body.repeat(size);
});
return drawContent_1.drawContent(columns, {
drawSeparator: drawVerticalLine,
separatorGetter: (index, columnCount) => {
if (index === 0) {
return separator.left;
}
if (index === columnCount) {
return separator.right;
}
return separator.join;
},
}) + '\n';
};
exports.drawBorder = drawBorder;
const drawBorderTop = (columnWidths, config) => {
const result = drawBorder(columnWidths, {
...config,
separator: {
body: config.border.topBody,
join: config.border.topJoin,
left: config.border.topLeft,
right: config.border.topRight,
},
});
if (result === '\n') {
return '';
}
return result;
};
exports.drawBorderTop = drawBorderTop;
const drawBorderJoin = (columnWidths, config) => {
return drawBorder(columnWidths, {
...config,
separator: {
body: config.border.joinBody,
join: config.border.joinJoin,
left: config.border.joinLeft,
right: config.border.joinRight,
},
});
};
exports.drawBorderJoin = drawBorderJoin;
const drawBorderBottom = (columnWidths, config) => {
return drawBorder(columnWidths, {
...config,
separator: {
body: config.border.bottomBody,
join: config.border.bottomJoin,
left: config.border.bottomLeft,
right: config.border.bottomRight,
},
});
};
exports.drawBorderBottom = drawBorderBottom;
const createTableBorderGetter = (columnWidths, config) => {
return (index, size) => {
if (!config.header) {
if (index === 0) {
return drawBorderTop(columnWidths, config);
}
if (index === size) {
return drawBorderBottom(columnWidths, config);
}
return drawBorderJoin(columnWidths, config);
}
// Deal with the header
if (index === 0) {
return drawBorderTop(columnWidths, {
...config,
border: {
...config.border,
topJoin: config.border.topBody,
},
});
}
if (index === 1) {
return drawBorderJoin(columnWidths, {
...config,
border: {
...config.border,
joinJoin: config.border.headerJoin,
},
});
}
if (index === size) {
return drawBorderBottom(columnWidths, config);
}
return drawBorderJoin(columnWidths, config);
};
};
exports.createTableBorderGetter = createTableBorderGetter;
-9
View File
@@ -1,9 +0,0 @@
declare type SeparatorConfig = {
drawSeparator: (index: number, size: number) => boolean;
separatorGetter: (index: number, size: number) => string;
};
/**
* Shared function to draw horizontal borders, rows or the entire table
*/
export declare const drawContent: (contents: string[], separatorConfig: SeparatorConfig) => string;
export {};
-26
View File
@@ -1,26 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawContent = void 0;
/**
* Shared function to draw horizontal borders, rows or the entire table
*/
const drawContent = (contents, separatorConfig) => {
const { separatorGetter, drawSeparator } = separatorConfig;
const contentSize = contents.length;
const result = [];
if (drawSeparator(0, contentSize)) {
result.push(separatorGetter(0, contentSize));
}
contents.forEach((content, contentIndex) => {
result.push(content);
// Only append the middle separator if the content is not the last
if (contentIndex + 1 < contentSize && drawSeparator(contentIndex + 1, contentSize)) {
result.push(separatorGetter(contentIndex + 1, contentSize));
}
});
if (drawSeparator(contentSize, contentSize)) {
result.push(separatorGetter(contentSize, contentSize));
}
return result.join('');
};
exports.drawContent = drawContent;
-2
View File
@@ -1,2 +0,0 @@
import type { TableConfig } from './types/internal';
export declare const drawHeader: (width: number, config: TableConfig) => string;
-29
View File
@@ -1,29 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawHeader = void 0;
const alignString_1 = require("./alignString");
const drawRow_1 = require("./drawRow");
const padTableData_1 = require("./padTableData");
const truncateTableData_1 = require("./truncateTableData");
const wrapCell_1 = require("./wrapCell");
const drawHeader = (width, config) => {
if (!config.header) {
throw new Error('Can not draw header without header configuration');
}
const { alignment, paddingRight, paddingLeft, wrapWord } = config.header;
let content = config.header.content;
content = truncateTableData_1.truncateString(content, config.header.truncate);
const headerLines = wrapCell_1.wrapCell(content, width, wrapWord);
return headerLines.map((headerLine) => {
let line = alignString_1.alignString(headerLine, width, alignment);
line = padTableData_1.padString(line, paddingLeft, paddingRight);
return drawRow_1.drawRow([line], {
...config,
drawVerticalLine: (index) => {
const columnCount = config.columns.length;
return config.drawVerticalLine(index === 0 ? 0 : columnCount, columnCount);
},
});
}).join('');
};
exports.drawHeader = drawHeader;
-6
View File
@@ -1,6 +0,0 @@
import type { DrawVerticalLine } from './types/api';
import type { BodyBorderConfig, Row } from './types/internal';
export declare const drawRow: (row: Row, config: {
border: BodyBorderConfig;
drawVerticalLine: DrawVerticalLine;
}) => string;
-2
View File
@@ -1,2 +0,0 @@
import type { TableConfig, Row } from './types/internal';
export declare const drawTable: (rows: Row[], columnWidths: number[], rowHeights: number[], config: TableConfig) => string;
-38
View File
@@ -1,38 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawTable = void 0;
const string_width_1 = __importDefault(require("string-width"));
const drawBorder_1 = require("./drawBorder");
const drawContent_1 = require("./drawContent");
const drawHeader_1 = require("./drawHeader");
const drawRow_1 = require("./drawRow");
const utils_1 = require("./utils");
const drawTable = (rows, columnWidths, rowHeights, config) => {
const { drawHorizontalLine, singleLine, } = config;
const contents = utils_1.groupBySizes(rows, rowHeights).map((group) => {
return group.map((row) => {
return drawRow_1.drawRow(row, config);
}).join('');
});
if (config.header) {
// assume that topLeft/right border have width = 1
const headerWidth = string_width_1.default(drawRow_1.drawRow(rows[0], config)) - 2 -
config.header.paddingLeft - config.header.paddingRight;
const header = drawHeader_1.drawHeader(headerWidth, config);
contents.unshift(header);
}
return drawContent_1.drawContent(contents, {
drawSeparator: (index, size) => {
// Top/bottom border
if (index === 0 || index === size) {
return drawHorizontalLine(index, size);
}
return !singleLine && drawHorizontalLine(index, size);
},
separatorGetter: drawBorder_1.createTableBorderGetter(columnWidths, config),
});
};
exports.drawTable = drawTable;
-7
View File
@@ -1,7 +0,0 @@
import type { TableUserConfig } from './types/api';
import type { Row, TableConfig } from './types/internal';
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
export declare const makeTableConfig: (rows: Row[], userConfig?: TableUserConfig) => TableConfig;
-66
View File
@@ -1,66 +0,0 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTableConfig = void 0;
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
const calculateColumnWidths_1 = __importDefault(require("./calculateColumnWidths"));
const utils_1 = require("./utils");
const validateConfig_1 = require("./validateConfig");
/**
* Creates a configuration for every column using default
* values for the missing configuration properties.
*/
const makeColumnsConfig = (rows, columns, columnDefault) => {
const columnWidths = calculateColumnWidths_1.default(rows);
return rows[0].map((_, columnIndex) => {
return {
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
truncate: Number.POSITIVE_INFINITY,
verticalAlignment: 'top',
width: columnWidths[columnIndex],
wrapWord: false,
...columnDefault,
...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
};
});
};
const makeHeaderConfig = (config) => {
if (!config.header) {
return undefined;
}
return {
alignment: 'center',
paddingLeft: 1,
paddingRight: 1,
truncate: Number.POSITIVE_INFINITY,
wrapWord: false,
...config.header,
};
};
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
const makeTableConfig = (rows, userConfig = {}) => {
var _a, _b, _c;
validateConfig_1.validateConfig('config.json', userConfig);
const config = lodash_clonedeep_1.default(userConfig);
return {
...config,
border: utils_1.makeBorderConfig(config.border),
columns: makeColumnsConfig(rows, config.columns, config.columnDefault),
drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
return true;
}),
drawVerticalLine: (_b = config.drawVerticalLine) !== null && _b !== void 0 ? _b : (() => {
return true;
}),
header: makeHeaderConfig(config),
singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
};
};
exports.makeTableConfig = makeTableConfig;
-2
View File
@@ -1,2 +0,0 @@
import type { BaseConfig, Row } from './types/internal';
export declare const mapDataUsingRowHeights: (unmappedRows: Row[], rowHeights: number[], config: BaseConfig) => Row[];
+7
View File
@@ -0,0 +1,7 @@
import type { SpanningCellContext } from './spanningCellManager';
import type { RangeConfig } from './types/internal';
/**
* Fill content into all cells in range in order to calculate total height
*/
export declare const wrapRangeContent: (rangeConfig: RangeConfig, rangeWidth: number, context: SpanningCellContext) => string[];
export declare const alignVerticalRangeContent: (range: RangeConfig, content: string[], context: SpanningCellContext) => string[];
+44
View File
@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alignVerticalRangeContent = exports.wrapRangeContent = void 0;
const alignString_1 = require("./alignString");
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
const padTableData_1 = require("./padTableData");
const truncateTableData_1 = require("./truncateTableData");
const utils_1 = require("./utils");
const wrapCell_1 = require("./wrapCell");
/**
* Fill content into all cells in range in order to calculate total height
*/
const wrapRangeContent = (rangeConfig, rangeWidth, context) => {
const { topLeft, paddingRight, paddingLeft, truncate, wrapWord, alignment } = rangeConfig;
const originalContent = context.rows[topLeft.row][topLeft.col];
const contentWidth = rangeWidth - paddingLeft - paddingRight;
return (0, wrapCell_1.wrapCell)((0, truncateTableData_1.truncateString)(originalContent, truncate), contentWidth, wrapWord).map((line) => {
const alignedLine = (0, alignString_1.alignString)(line, contentWidth, alignment);
return (0, padTableData_1.padString)(alignedLine, paddingLeft, paddingRight);
});
};
exports.wrapRangeContent = wrapRangeContent;
const alignVerticalRangeContent = (range, content, context) => {
const { rows, drawHorizontalLine, rowHeights } = context;
const { topLeft, bottomRight, verticalAlignment } = range;
// They are empty before calculateRowHeights function run
if (rowHeights.length === 0) {
return [];
}
const totalCellHeight = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row, bottomRight.row + 1));
const totalBorderHeight = bottomRight.row - topLeft.row;
const hiddenHorizontalBorderCount = (0, utils_1.sequence)(topLeft.row + 1, bottomRight.row).filter((horizontalBorderIndex) => {
return !drawHorizontalLine(horizontalBorderIndex, rows.length);
}).length;
const availableRangeHeight = totalCellHeight + totalBorderHeight - hiddenHorizontalBorderCount;
return (0, mapDataUsingRowHeights_1.padCellVertically)(content, availableRangeHeight, verticalAlignment).map((line) => {
if (line.length === 0) {
return ' '.repeat(content[0].length);
}
return line;
});
};
exports.alignVerticalRangeContent = alignVerticalRangeContent;
//# sourceMappingURL=alignSpanningCell.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alignSpanningCell.js","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e,GAAG,IAAA,gBAAQ,EAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACrF,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxD,MAAM,2BAA2B,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,GAAG,GAAG,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,qBAAqB,EAAE,EAAE;QAC9G,OAAO,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC,MAAM,CAAC;IAEV,MAAM,oBAAoB,GAAG,eAAe,GAAG,iBAAiB,GAAG,2BAA2B,CAAC;IAE/F,OAAO,IAAA,0CAAiB,EAAC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtF,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;SACtC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAxBW,QAAA,yBAAyB,6BAwBpC"}
@@ -16,11 +16,11 @@ const alignCenter = (subject, width) => {
return ' '.repeat(Math.floor(width / 2)) + subject + ' '.repeat(Math.ceil(width / 2));
};
const alignJustify = (subject, width) => {
const spaceSequenceCount = utils_1.countSpaceSequence(subject);
const spaceSequenceCount = (0, utils_1.countSpaceSequence)(subject);
if (spaceSequenceCount === 0) {
return alignLeft(subject, width);
}
const addingSpaces = utils_1.distributeUnevenly(width, spaceSequenceCount);
const addingSpaces = (0, utils_1.distributeUnevenly)(width, spaceSequenceCount);
if (Math.max(...addingSpaces) > 3) {
return alignLeft(subject, width);
}
@@ -34,7 +34,7 @@ const alignJustify = (subject, width) => {
* text in a desired alignment within a container.
*/
const alignString = (subject, containerWidth, alignment) => {
const subjectWidth = string_width_1.default(subject);
const subjectWidth = (0, string_width_1.default)(subject);
if (subjectWidth === containerWidth) {
return subject;
}
@@ -57,3 +57,4 @@ const alignString = (subject, containerWidth, alignment) => {
return alignCenter(subject, availableWidth);
};
exports.alignString = alignString;
//# sourceMappingURL=alignString.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alignString.js","sourceRoot":"","sources":["../../src/alignString.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AAIvC,mCAEiB;AAEjB,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE;IAC3D,OAAO,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE;IAC5D,OAAO,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE;IAC7D,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,KAAa,EAAU,EAAE;IAC9D,MAAM,kBAAkB,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;IAEvD,IAAI,kBAAkB,KAAK,CAAC,EAAE;QAC5B,OAAO,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;KAClC;IAED,MAAM,YAAY,GAAG,IAAA,0B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CAAC;AA9BW,QAAA,WAAW,eA8BtB"}
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alignTableData = void 0;
const alignString_1 = require("./alignString");
const alignTableData = (rows, config) => {
return rows.map((row, rowIndex) => {
return row.map((cell, cellIndex) => {
var _a;
const { width, alignment } = config.columns[cellIndex];
const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
row: rowIndex }, { mapped: true });
if (containingRange) {
return cell;
}
return (0, alignString_1.alignString)(cell, width, alignment);
});
});
};
exports.alignTableData = alignTableData;
//# sourceMappingURL=alignTableData.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"alignTableData.js","sourceRoot":"","sources":["../../src/alignTableData.ts"],"names":[],"mappings":";;;AAAA,+CAEuB;AAMhB,MAAM,cAAc,GAAG,CAAC,IAAW,EAAE,MAAkB,EAAS,EAAE;IACvE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QAChC,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;;YACjC,MAAM,EAAC,KAAK,EAAE,SAAS,EAAC,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAErD,MAAM,eAAe,GAAG,MAAA,MAAM,CAAC,mBAAmB,0CAAE,kBAAkB,CAAC,EAAC,GAAG,EAAE,SAAS;gBACpF,GAAG,EAAE,QAAQ,EAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;YAClC,IAAI,eAAe,EAAE;gBACnB,OAAO,IAAI,CAAC;aACb;YAED,OAAO,IAAA,yBAAW,EAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,cAAc,kBAczB"}
@@ -6,6 +6,7 @@ const wrapCell_1 = require("./wrapCell");
* Calculates height of cell content in regard to its width and word wrapping.
*/
const calculateCellHeight = (value, columnWidth, useWrapWord = false) => {
return wrapCell_1.wrapCell(value, columnWidth, useWrapWord).length;
return (0, wrapCell_1.wrapCell)(value, columnWidth, useWrapWord).length;
};
exports.calculateCellHeight = calculateCellHeight;
//# sourceMappingURL=calculateCellHeight.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"calculateCellHeight.js","sourceRoot":"","sources":["../../src/calculateCellHeight.ts"],"names":[],"mappings":";;;AAAA,yCAEoB;AAEpB;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAE,WAAmB,EAAE,WAAW,GAAG,KAAK,EAAU,EAAE;IACrG,OAAO,IAAA,mBAAQ,EAAC,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B"}
+7
View File
@@ -0,0 +1,7 @@
import type { SpanningCellConfig } from './types/api';
import type { Row, Cell } from './types/internal';
export declare const calculateMaximumCellWidth: (cell: Cell) => number;
/**
* Produces an array of values that describe the largest value length (width) in every column.
*/
export declare const calculateMaximumColumnWidths: (rows: Row[], spanningCellConfigs?: SpanningCellConfig[]) => number[];
+36
View File
@@ -0,0 +1,36 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateMaximumColumnWidths = exports.calculateMaximumCellWidth = void 0;
const string_width_1 = __importDefault(require("string-width"));
const utils_1 = require("./utils");
const calculateMaximumCellWidth = (cell) => {
return Math.max(...cell.split('\n').map(string_width_1.default));
};
exports.calculateMaximumCellWidth = calculateMaximumCellWidth;
/**
* Produces an array of values that describe the largest value length (width) in every column.
*/
const calculateMaximumColumnWidths = (rows, spanningCellConfigs = []) => {
const columnWidths = new Array(rows[0].length).fill(0);
const rangeCoordinates = spanningCellConfigs.map(utils_1.calculateRangeCoordinate);
const isSpanningCell = (rowIndex, columnIndex) => {
return rangeCoordinates.some((rangeCoordinate) => {
return (0, utils_1.isCellInRange)({ col: columnIndex,
row: rowIndex }, rangeCoordinate);
});
};
rows.forEach((row, rowIndex) => {
row.forEach((cell, cellIndex) => {
if (isSpanningCell(rowIndex, cellIndex)) {
return;
}
columnWidths[cellIndex] = Math.max(columnWidths[cellIndex], (0, exports.calculateMaximumCellWidth)(cell));
});
});
return columnWidths;
};
exports.calculateMaximumColumnWidths = calculateMaximumColumnWidths;
//# sourceMappingURL=calculateMaximumColumnWidths.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"calculateMaximumColumnWidths.js","sourceRoot":"","sources":["../../src/calculateMaximumColumnWidths.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AAQvC,mCAEiB;AAEV,MAAM,yBAAyB,GAAG,CAAC,IAAU,EAAU,EAAE;IAC9D,OAAO,IAAI,CAAC,GAAG,CACb,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,sBAAW,CAAC,CACrC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,yBAAyB,6BAIpC;AAEF;;GAEG;AACI,MAAM,4BAA4B,GAAG,CAAC,IAAW,EAAE,sBAA4C,EAAE,EAAY,EAAE;IACpH,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,GAAG,CAAC,gCAAwB,CAAC,CAAC;IAC3E,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,WAAmB,EAAW,EAAE;QACxE,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE;YAC/C,OAAO,IAAA,qBAAa,EAAC,EAAC,GAAG,EAAE,WAAW;gBACpC,GAAG,EAAE,QAAQ,EAAC,EAAE,eAAe,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QAC7B,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;YAC9B,IAAI,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE;gBACvC,OAAO;aACR;YACD,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAA,iCAAyB,EAAC,IAAI,CAAC,CAAC,CAAC;QAC/F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AApBW,QAAA,4BAA4B,gCAoBvC"}
+2
View File
@@ -0,0 +1,2 @@
import type { TableConfig } from './types/internal';
export declare const calculateOutputColumnWidths: (config: TableConfig) => number[];
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateOutputColumnWidths = void 0;
const calculateOutputColumnWidths = (config) => {
return config.columns.map((col) => {
return col.paddingLeft + col.width + col.paddingRight;
});
};
exports.calculateOutputColumnWidths = calculateOutputColumnWidths;
//# sourceMappingURL=calculateOutputColumnWidths.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"calculateOutputColumnWidths.js","sourceRoot":"","sources":["../../src/calculateOutputColumnWidths.ts"],"names":[],"mappings":";;;AAIO,MAAM,2BAA2B,GAAG,CAAC,MAAmB,EAAY,EAAE;IAC3E,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,OAAO,GAAG,CAAC,WAAW,GAAG,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,2BAA2B,+BAItC"}
+42
View File
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateRowHeights = void 0;
const calculateCellHeight_1 = require("./calculateCellHeight");
const utils_1 = require("./utils");
/**
* Produces an array of values that describe the largest value length (height) in every row.
*/
const calculateRowHeights = (rows, config) => {
const rowHeights = [];
for (const [rowIndex, row] of rows.entries()) {
let rowHeight = 1;
row.forEach((cell, cellIndex) => {
var _a;
const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
row: rowIndex });
if (!containingRange) {
const cellHeight = (0, calculateCellHeight_1.calculateCellHeight)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
rowHeight = Math.max(rowHeight, cellHeight);
return;
}
const { topLeft, bottomRight, height } = containingRange;
// bottom-most cell of a range needs to contain all remain lines of spanning cells
if (rowIndex === bottomRight.row) {
const totalOccupiedSpanningCellHeight = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row));
const totalHorizontalBorderHeight = bottomRight.row - topLeft.row;
const totalHiddenHorizontalBorderHeight = (0, utils_1.sequence)(topLeft.row + 1, bottomRight.row).filter((horizontalBorderIndex) => {
var _a;
/* istanbul ignore next */
return !((_a = config.drawHorizontalLine) === null || _a === void 0 ? void 0 : _a.call(config, horizontalBorderIndex, rows.length));
}).length;
const cellHeight = height - totalOccupiedSpanningCellHeight - totalHorizontalBorderHeight + totalHiddenHorizontalBorderHeight;
rowHeight = Math.max(rowHeight, cellHeight);
}
// otherwise, just depend on other sibling cell heights in the row
});
rowHeights.push(rowHeight);
}
return rowHeights;
};
exports.calculateRowHeights = calculateRowHeights;
//# sourceMappingURL=calculateRowHeights.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"calculateRowHeights.js","sourceRoot":"","sources":["../../src/calculateRowHeights.ts"],"names":[],"mappings":";;;AAAA,+DAE+B;AAK/B,mCAGiB;AAEjB;;GAEG;AACI,MAAM,mBAA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AA,MAAM,CAAC,kBAAkB,+CAAzB,MAAM,EAAsB,qBAAqB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA,CAAC;gBAC1E,CAAC,CAAC,CAAC,MAAM,CAAC;gBAEV,MAAM,UAAU,GAAG,MAAM,GAAG,+BAA+B,GAAG,2BAA2B,GAAG,iCAAiC,CAAC;gBAC9H,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;aAC7C;YAED,kEAAkE;QACpE,CAAC,CAAC,CAAC;QAEH,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KAC5B;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAtCW,QAAA,mBAAmB,uBAsC9B"}
+3
View File
@@ -0,0 +1,3 @@
import type { SpanningCellParameters } from './spanningCellManager';
import type { RangeConfig } from './types/internal';
export declare const calculateSpanningCellWidth: (rangeConfig: RangeConfig, dependencies: SpanningCellParameters) => number;
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateSpanningCellWidth = void 0;
const utils_1 = require("./utils");
const calculateSpanningCellWidth = (rangeConfig, dependencies) => {
const { columnsConfig, drawVerticalLine } = dependencies;
const { topLeft, bottomRight } = rangeConfig;
const totalWidth = (0, utils_1.sumArray)(columnsConfig.slice(topLeft.col, bottomRight.col + 1).map(({ width }) => {
return width;
}));
const totalPadding = topLeft.col === bottomRight.col ?
columnsConfig[topLeft.col].paddingRight +
columnsConfig[bottomRight.col].paddingLeft :
(0, utils_1.sumArray)(columnsConfig
.slice(topLeft.col, bottomRight.col + 1)
.map(({ paddingLeft, paddingRight }) => {
return paddingLeft + paddingRight;
}));
const totalBorderWidths = bottomRight.col - topLeft.col;
const totalHiddenVerticalBorders = (0, utils_1.sequence)(topLeft.col + 1, bottomRight.col).filter((verticalBorderIndex) => {
return !drawVerticalLine(verticalBorderIndex, columnsConfig.length);
}).length;
return totalWidth + totalPadding + totalBorderWidths - totalHiddenVerticalBorders;
};
exports.calculateSpanningCellWidth = calculateSpanningCellWidth;
//# sourceMappingURL=calculateSpanningCellWidth.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"calculateSpanningCellWidth.js","sourceRoot":"","sources":["../../src/calculateSpanningCellWidth.ts"],"names":[],"mappings":";;;AAMA,mCAEiB;AAEV,MAAM,0BAA0B,GAAG,CAAC,WAAwB,EAAE,YAAoC,EAAU,EAAE;IACnH,MAAM,EAAC,aAAa,EAAE,gBAAgB,EAAC,GAAG,YAAY,CAAC;IACvD,MAAM,EAAC,OAAO,EAAE,WAAW,EAAC,GAAG,WAAW,CAAC;IAE3C,MAAM,UAAU,GAAG,IAAA,gBAAQ,EACzB,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAC,KAAK,EAAC,EAAE,EAAE;QACpE,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,YAAY,GAChB,OAAO,CAAC,GAAG,KAAK,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/B,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY;YACvC,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC;QAC5C,IAAA,gBAAQ,EACN,aAAa;aACV,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,GAAG,CAAC,CAAC;aACvC,GAAG,CAAC,CAAC,EAAC,WAAW,EAAE,YAAY,EAAC,EAAE,EAAE;YACnC,OAAO,WAAW,GAAG,YAAY,CAAC;QACpC,CAAC,CAAC,CACL,CAAC;IACN,MAAM,iBAAiB,GAAG,WAAW,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAExD,MAAM,0BAA0B,GAAG,IAAA,gBAAQ,EAAC,OAAO,CAAC,GAAG,GAAG,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAmB,EAAE,EAAE;QAC3G,OAAO,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC,MAAM,CAAC;IAEV,OAAO,UAAU,GAAG,YAAY,GAAG,iBAAiB,GAAG,0BAA0B,CAAC;AACpF,CAAC,CAAC;AA5BW,QAAA,0BAA0B,8BA4BrC"}
@@ -10,46 +10,47 @@ const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
const padTableData_1 = require("./padTableData");
const stringifyTableData_1 = require("./stringifyTableData");
const truncateTableData_1 = require("./truncateTableData");
const utils_1 = require("./utils");
const prepareData = (data, config) => {
let rows = stringifyTableData_1.stringifyTableData(data);
rows = truncateTableData_1.truncateTableData(rows, config);
const rowHeights = calculateRowHeights_1.calculateRowHeights(rows, config);
rows = mapDataUsingRowHeights_1.mapDataUsingRowHeights(rows, rowHeights, config);
rows = alignTableData_1.alignTableData(rows, config);
rows = padTableData_1.padTableData(rows, config);
let rows = (0, stringifyTableData_1.stringifyTableData)(data);
rows = (0, truncateTableData_1.truncateTableData)(rows, (0, utils_1.extractTruncates)(config));
const rowHeights = (0, calculateRowHeights_1.calculateRowHeights)(rows, config);
rows = (0, mapDataUsingRowHeights_1.mapDataUsingRowHeights)(rows, rowHeights, config);
rows = (0, alignTableData_1.alignTableData)(rows, config);
rows = (0, padTableData_1.padTableData)(rows, config);
return rows;
};
const create = (row, columnWidths, config) => {
const rows = prepareData([row], config);
const body = rows.map((literalRow) => {
return drawRow_1.drawRow(literalRow, config);
return (0, drawRow_1.drawRow)(literalRow, config);
}).join('');
let output;
output = '';
output += drawBorder_1.drawBorderTop(columnWidths, config);
output += (0, drawBorder_1.drawBorderTop)(columnWidths, config);
output += body;
output += drawBorder_1.drawBorderBottom(columnWidths, config);
output += (0, drawBorder_1.drawBorderBottom)(columnWidths, config);
output = output.trimEnd();
process.stdout.write(output);
};
const append = (row, columnWidths, config) => {
const rows = prepareData([row], config);
const body = rows.map((literalRow) => {
return drawRow_1.drawRow(literalRow, config);
return (0, drawRow_1.drawRow)(literalRow, config);
}).join('');
let output = '';
const bottom = drawBorder_1.drawBorderBottom(columnWidths, config);
const bottom = (0, drawBorder_1.drawBorderBottom)(columnWidths, config);
if (bottom !== '\n') {
output = '\r\u001B[K';
}
output += drawBorder_1.drawBorderJoin(columnWidths, config);
output += (0, drawBorder_1.drawBorderJoin)(columnWidths, config);
output += body;
output += bottom;
output = output.trimEnd();
process.stdout.write(output);
};
const createStream = (userConfig) => {
const config = makeStreamConfig_1.makeStreamConfig(userConfig);
const config = (0, makeStreamConfig_1.makeStreamConfig)(userConfig);
const columnWidths = Object.values(config.columns).map((column) => {
return column.width + column.paddingLeft + column.paddingRight;
});
@@ -70,3 +71,4 @@ const createStream = (userConfig) => {
};
};
exports.createStream = createStream;
//# sourceMappingURL=createStream.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"createStream.js","sourceRoot":"","sources":["../../src/createStream.ts"],"names":[],"mappings":";;;AAAA,qDAE0B;AAC1B,+DAE+B;AAC/B,6CAIsB;AACtB,uCAEmB;AACnB,yDAE4B;AAC5B,qEAEkC;AAClC,iDAEwB;AACxB,6DAE8B;AAC9B,2DAE6B;AAQ7B,mCAEiB;AAEjB,MAAM,WAAW,GAAG,CAAC,IAAW,EAAE,MAAoB,EAAE,EAAE;IACxD,IAAI,IAAI,GAAG,IAAA,uCAAkB,EAAC,IAAI,CAAC,CAAC;IAEpC,IAAI,GAAG,IAAA,qCAAiB,EAAC,IAAI,EAAE,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC,CAAC;IAEzD,MAAM,UAAU,GAAG,IAAA,yCAAmB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAErD,IAAI,GAAG,IAAA,+CAAsB,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACxD,IAA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@ -0,0 +1,34 @@
import type { SpanningCellManager } from './spanningCellManager';
import type { BorderConfig, DrawVerticalLine } from './types/api';
import type { SeparatorGetter } from './types/internal';
declare type Separator = {
readonly left: string;
readonly right: string;
readonly body: string;
readonly bodyJoinOuter?: string;
readonly bodyJoinInner?: string;
readonly join: string;
readonly joinUp?: string;
readonly joinDown?: string;
readonly joinLeft?: string;
readonly joinRight?: string;
};
export declare const drawBorderSegments: (columnWidths: number[], parameters: Parameters<typeof drawBorder>[1]) => string[];
export declare const createSeparatorGetter: (dependencies: Parameters<typeof drawBorder>[1]) => (verticalBorderIndex: number, columnCount: number) => string;
export declare const drawBorder: (columnWidths: number[], parameters: Omit<DrawBorderParameters, 'border'> & {
separator: Separator;
}) => string;
export declare const drawBorderTop: (columnWidths: number[], parameters: DrawBorderParameters) => string;
export declare const drawBorderJoin: (columnWidths: number[], parameters: DrawBorderParameters) => string;
export declare const drawBorderBottom: (columnWidths: number[], parameters: DrawBorderParameters) => string;
export declare type BorderGetterParameters = {
border: BorderConfig;
drawVerticalLine: DrawVerticalLine;
spanningCellManager?: SpanningCellManager;
rowCount?: number;
};
export declare type DrawBorderParameters = Omit<BorderGetterParameters, 'outputColumnWidths'> & {
horizontalBorderIndex?: number;
};
export declare const createTableBorderGetter: (columnWidths: number[], parameters: BorderGetterParameters) => SeparatorGetter;
export {};
+202
View File
@@ -0,0 +1,202 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTableBorderGetter = exports.drawBorderBottom = exports.drawBorderJoin = exports.drawBorderTop = exports.drawBorder = exports.createSeparatorGetter = exports.drawBorderSegments = void 0;
const drawContent_1 = require("./drawContent");
const drawBorderSegments = (columnWidths, parameters) => {
const { separator, horizontalBorderIndex, spanningCellManager } = parameters;
return columnWidths.map((columnWidth, columnIndex) => {
const normalSegment = separator.body.repeat(columnWidth);
if (horizontalBorderIndex === undefined) {
return normalSegment;
}
/* istanbul ignore next */
const range = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.getContainingRange({ col: columnIndex,
row: horizontalBorderIndex });
if (!range) {
return normalSegment;
}
const { topLeft } = range;
// draw border segments as usual for top border of spanning cell
if (horizontalBorderIndex === topLeft.row) {
return normalSegment;
}
// if for first column/row of spanning cell, just skip
if (columnIndex !== topLeft.col) {
return '';
}
return range.extractBorderContent(horizontalBorderIndex);
});
};
exports.drawBorderSegments = drawBorderSegments;
const createSeparatorGetter = (dependencies) => {
const { separator, spanningCellManager, horizontalBorderIndex, rowCount } = dependencies;
// eslint-disable-next-line complexity
return (verticalBorderIndex, columnCount) => {
const inSameRange = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.inSameRange;
if (horizontalBorderIndex !== undefined && inSameRange) {
const topCell = { col: verticalBorderIndex,
row: horizontalBorderIndex - 1 };
const leftCell = { col: verticalBorderIndex - 1,
row: horizontalBorderIndex };
const oppositeCell = { col: verticalBorderIndex - 1,
row: horizontalBorderIndex - 1 };
const currentCell = { col: verticalBorderIndex,
row: horizontalBorderIndex };
const pairs = [
[oppositeCell, topCell],
[topCell, currentCell],
[currentCell, leftCell],
[leftCell, oppositeCell],
];
// left side of horizontal border
if (verticalBorderIndex === 0) {
if (inSameRange(currentCell, topCell) && separator.bodyJoinOuter) {
return separator.bodyJoinOuter;
}
return separator.left;
}
// right side of horizontal border
if (verticalBorderIndex === columnCount) {
if (inSameRange(oppositeCell, leftCell) && separator.bodyJoinOuter) {
return separator.bodyJoinOuter;
}
return separator.right;
}
// top horizontal border
if (horizontalBorderIndex === 0) {
if (inSameRange(currentCell, leftCell)) {
return separator.body;
}
return separator.join;
}
// bottom horizontal border
if (horizontalBorderIndex === rowCount) {
if (inSameRange(topCell, oppositeCell)) {
return separator.body;
}
return separator.join;
}
const sameRangeCount = pairs.map((pair) => {
return inSameRange(...pair);
}).filter(Boolean).length;
// four cells are belongs to different spanning cells
if (sameRangeCount === 0) {
return separator.join;
}
// belong to one spanning cell
if (sameRangeCount === 4) {
return '';
}
// belongs to two spanning cell
if (sameRangeCount === 2) {
if (inSameRange(...pairs[1]) && inSameRange(...pairs[3]) && separator.bodyJoinInner) {
return separator.bodyJoinInner;
}
return separator.body;
}
/* istanbul ignore next */
if (sameRangeCount === 1) {
if (!separator.joinRight || !separator.joinLeft || !separator.joinUp || !separator.joinDown) {
throw new Error(`Can not get border separator for position [${horizontalBorderIndex}, ${verticalBorderIndex}]`);
}
if (inSameRange(...pairs[0])) {
return separator.joinDown;
}
if (inSameRange(...pairs[1])) {
return separator.joinLeft;
}
if (inSameRange(...pairs[2])) {
return separator.joinUp;
}
return separator.joinRight;
}
/* istanbul ignore next */
throw new Error('Invalid case');
}
if (verticalBorderIndex === 0) {
return separator.left;
}
if (verticalBorderIndex === columnCount) {
return separator.right;
}
return separator.join;
};
};
exports.createSeparatorGetter = createSeparatorGetter;
const drawBorder = (columnWidths, parameters) => {
const borderSegments = (0, exports.drawBorderSegments)(columnWidths, parameters);
const { drawVerticalLine, horizontalBorderIndex, spanningCellManager } = parameters;
return (0, drawContent_1.drawContent)({
contents: borderSegments,
drawSeparator: drawVerticalLine,
elementType: 'border',
rowIndex: horizontalBorderIndex,
separatorGetter: (0, exports.createSeparatorGetter)(parameters),
spanningCellManager,
}) + '\n';
};
exports.drawBorder = drawBorder;
const drawBorderTop = (columnWidths, parameters) => {
const { border } = parameters;
const result = (0, exports.drawBorder)(columnWidths, {
...parameters,
separator: {
body: border.topBody,
join: border.topJoin,
left: border.topLeft,
right: border.topRight,
},
});
if (result === '\n') {
return '';
}
return result;
};
exports.drawBorderTop = drawBorderTop;
const drawBorderJoin = (columnWidths, parameters) => {
const { border } = parameters;
return (0, exports.drawBorder)(columnWidths, {
...parameters,
separator: {
body: border.joinBody,
bodyJoinInner: border.bodyJoin,
bodyJoinOuter: border.bodyLeft,
join: border.joinJoin,
joinDown: border.joinMiddleDown,
joinLeft: border.joinMiddleLeft,
joinRight: border.joinMiddleRight,
joinUp: border.joinMiddleUp,
left: border.joinLeft,
right: border.joinRight,
},
});
};
exports.drawBorderJoin = drawBorderJoin;
const drawBorderBottom = (columnWidths, parameters) => {
const { border } = parameters;
return (0, exports.drawBorder)(columnWidths, {
...parameters,
separator: {
body: border.bottomBody,
join: border.bottomJoin,
left: border.bottomLeft,
right: border.bottomRight,
},
});
};
exports.drawBorderBottom = drawBorderBottom;
const createTableBorderGetter = (columnWidths, parameters) => {
return (index, size) => {
const drawBorderParameters = { ...parameters,
horizontalBorderIndex: index };
if (index === 0) {
return (0, exports.drawBorderTop)(columnWidths, drawBorderParameters);
}
else if (index === size) {
return (0, exports.drawBorderBottom)(columnWidths, drawBorderParameters);
}
return (0, exports.drawBorderJoin)(columnWidths, drawBorderParameters);
};
};
exports.createTableBorderGetter = createTableBorderGetter;
//# sourceMappingURL=drawBorder.js.map
File diff suppressed because one or more lines are too long
+14
View File
@@ -0,0 +1,14 @@
import type { SpanningCellManager } from './spanningCellManager';
/**
* Shared function to draw horizontal borders, rows or the entire table
*/
declare type DrawContentParameters = {
contents: string[];
drawSeparator: (index: number, size: number) => boolean;
separatorGetter: (index: number, size: number) => string;
spanningCellManager?: SpanningCellManager;
rowIndex?: number;
elementType?: 'border' | 'cell' | 'row';
};
export declare const drawContent: (parameters: DrawContentParameters) => string;
export {};
+51
View File
@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawContent = void 0;
const drawContent = (parameters) => {
const { contents, separatorGetter, drawSeparator, spanningCellManager, rowIndex, elementType } = parameters;
const contentSize = contents.length;
const result = [];
if (drawSeparator(0, contentSize)) {
result.push(separatorGetter(0, contentSize));
}
contents.forEach((content, contentIndex) => {
if (!elementType || elementType === 'border' || elementType === 'row') {
result.push(content);
}
if (elementType === 'cell' && rowIndex === undefined) {
result.push(content);
}
if (elementType === 'cell' && rowIndex !== undefined) {
/* istanbul ignore next */
const containingRange = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.getContainingRange({ col: contentIndex,
row: rowIndex });
// when drawing content row, just add a cell when it is a normal cell
// or belongs to first column of spanning cell
if (!containingRange || contentIndex === containingRange.topLeft.col) {
result.push(content);
}
}
// Only append the middle separator if the content is not the last
if (contentIndex + 1 < contentSize && drawSeparator(contentIndex + 1, contentSize)) {
const separator = separatorGetter(contentIndex + 1, contentSize);
if (elementType === 'cell' && rowIndex !== undefined) {
const currentCell = { col: contentIndex + 1,
row: rowIndex };
/* istanbul ignore next */
const containingRange = spanningCellManager === null || spanningCellManager === void 0 ? void 0 : spanningCellManager.getContainingRange(currentCell);
if (!containingRange || containingRange.topLeft.col === currentCell.col) {
result.push(separator);
}
}
else {
result.push(separator);
}
}
});
if (drawSeparator(contentSize, contentSize)) {
result.push(separatorGetter(contentSize, contentSize));
}
return result.join('');
};
exports.drawContent = drawContent;
//# sourceMappingURL=drawContent.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"drawContent.js","sourceRoot":"","sources":["../../src/drawContent.ts"],"names":[],"mappings":";;;AAmBO,MAAM,WAAW,GAAG,CAAC,UAAiC,EAAU,EAAE;IACvE,MAAM,EAAC,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAC,GAAG,UAAU,CAAC;IAC1G,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC;IACpC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,aAAa,CAAC,CAAC,EAAE,WAAW,CAAC,EAAE;QACjC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;KAC9C;IAED,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;QACzC,IAAI,CAAC,WAAW,IAAI,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,KAAK,EAAE;YACrE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACtB;QAED,IAAI,WAAW,KAAK,MAAM,IAAI,QAAQ,KAAK,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C,EAAE;QAC3C,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;KACxD;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC,CAAC;AArDW,QAAA,WAAW,eAqDtB"}
+10
View File
@@ -0,0 +1,10 @@
import type { SpanningCellManager } from './spanningCellManager';
import type { DrawVerticalLine } from './types/api';
import type { BodyBorderConfig, Row } from './types/internal';
export declare type DrawRowConfig = {
border: BodyBorderConfig;
drawVerticalLine: DrawVerticalLine;
spanningCellManager?: SpanningCellManager;
rowIndex?: number;
};
export declare const drawRow: (row: Row, config: DrawRowConfig) => string;
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.drawRow = void 0;
const drawContent_1 = require("./drawContent");
const drawRow = (row, config) => {
const { border, drawVerticalLine } = config;
return drawContent_1.drawContent(row, {
const { border, drawVerticalLine, rowIndex, spanningCellManager } = config;
return (0, drawContent_1.drawContent)({
contents: row,
drawSeparator: drawVerticalLine,
elementType: 'cell',
rowIndex,
separatorGetter: (index, columnCount) => {
if (index === 0) {
return border.bodyLeft;
@@ -15,6 +18,8 @@ const drawRow = (row, config) => {
}
return border.bodyJoin;
},
spanningCellManager,
}) + '\n';
};
exports.drawRow = drawRow;
//# sourceMappingURL=drawRow.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"drawRow.js","sourceRoot":"","sources":["../../src/drawRow.ts"],"names":[],"mappings":";;;AAAA,+CAEuB;AAmBhB,MAAM,OAAO,GAAG,CAAC,GAAQ,EAAE,MAAqB,EAAU,EAAE;IACjE,MAAM,EAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAC,GAAG,MAAM,CAAC;IAEzE,OAAO,IAAA,yBAAW,EAAC;QACjB,QAAQ,EAAE,GAAG;QACb,aAAa,EAAE,gBAAgB;QAC/B,WAAW,EAAE,MAAM;QACnB,QAAQ;QACR,eAAe,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;YACtC,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO,MAAM,CAAC,QAAQ,CAAC;aACxB;YAED,IAAI,KAAK,KAAK,WAAW,EAAE;gBACzB,OAAO,MAAM,CAAC,SAAS,CAAC;aACzB;YAED,OAAO,MAAM,CAAC,QAAQ,CAAC;QACzB,CAAC;QACD,mBAAmB;KACpB,CAAC,GAAG,IAAI,CAAC;AACZ,CAAC,CAAC;AArBW,QAAA,OAAO,WAqBlB"}
+2
View File
@@ -0,0 +1,2 @@
import type { TableConfig, Row } from './types/internal';
export declare const drawTable: (rows: Row[], outputColumnWidths: number[], rowHeights: number[], config: TableConfig) => string;
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.drawTable = void 0;
const drawBorder_1 = require("./drawBorder");
const drawContent_1 = require("./drawContent");
const drawRow_1 = require("./drawRow");
const utils_1 = require("./utils");
const drawTable = (rows, outputColumnWidths, rowHeights, config) => {
const { drawHorizontalLine, singleLine, } = config;
const contents = (0, utils_1.groupBySizes)(rows, rowHeights).map((group, groupIndex) => {
return group.map((row) => {
return (0, drawRow_1.drawRow)(row, { ...config,
rowIndex: groupIndex });
}).join('');
});
return (0, drawContent_1.drawContent)({ contents,
drawSeparator: (index, size) => {
// Top/bottom border
if (index === 0 || index === size) {
return drawHorizontalLine(index, size);
}
return !singleLine && drawHorizontalLine(index, size);
},
elementType: 'row',
rowIndex: -1,
separatorGetter: (0, drawBorder_1.createTableBorderGetter)(outputColumnWidths, { ...config,
rowCount: contents.length }),
spanningCellManager: config.spanningCellManager });
};
exports.drawTable = drawTable;
//# sourceMappingURL=drawTable.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"drawTable.js","sourceRoot":"","sources":["../../src/drawTable.ts"],"names":[],"mappings":";;;AAAA,6CAEsB;AACtB,+CAEuB;AACvB,uCAEmB;AAInB,mCAEiB;AAEV,MAAM,SAAS,GAAG,CAAC,IAAW,EAAE,kBAA4B,EAAE,UAAoB,EAAE,MAAmB,EAAU,EAAE;IACxH,MAAM,EACJ,kBAAkB,EAClB,UAAU,GACX,GAAG,MAAM,CAAC;IAEX,MAAM,QAAQ,GAAG,IAAA,oBAAY,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE;QACxE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACvB,OAAO,IAAA,iBAAO,EAAC,GAAG,EAAE,EAAC,GAAG,MAAM;gBAC5B,QAAQ,EAAE,UAAU,EAAC,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,yBAAW,EAAC,EAAC,QAAQ;QAC1B,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC7B,oBAAoB;YACpB,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,EAAE;gBACjC,OAAO,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;aACxC;YAED,OAAO,CAAC,UAAU,IAAI,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,CAAC,CAAC;QACZ,eAAe,EAAE,IAAA,oCAAuB,EAAC,kBAAkB,EAAE,EAAC,GAAG,MAAM;YACrE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAC,CAAC;QAC7B,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,EAAC,CAAC,CAAC;AACtD,CAAC,CAAC;AA3BW,QAAA,SAAS,aA2BpB"}
@@ -4,10 +4,10 @@ declare function validate43(data: any, { instancePath, parentData, parentDataPro
parentDataProperty: any;
rootData?: any;
}): boolean;
declare function validate76(data: any, { instancePath, parentData, parentDataProperty, rootData }?: {
declare function validate86(data: any, { instancePath, parentData, parentDataProperty, rootData }?: {
instancePath?: string | undefined;
parentData: any;
parentDataProperty: any;
rootData?: any;
}): boolean;
export { validate43 as _config_json, validate76 as _streamConfig_json };
export { validate43 as _config_json, validate86 as _streamConfig_json };
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
@@ -21,6 +21,10 @@ const getBorderCharacters = (name) => {
joinLeft: '╟',
joinRight: '╢',
joinJoin: '┼',
joinMiddleDown: '┬',
joinMiddleUp: '┴',
joinMiddleLeft: '┤',
joinMiddleRight: '├',
};
}
if (name === 'norc') {
@@ -41,6 +45,10 @@ const getBorderCharacters = (name) => {
joinLeft: '├',
joinRight: '┤',
joinJoin: '┼',
joinMiddleDown: '┬',
joinMiddleUp: '┴',
joinMiddleLeft: '┤',
joinMiddleRight: '├',
};
}
if (name === 'ramac') {
@@ -61,6 +69,10 @@ const getBorderCharacters = (name) => {
joinLeft: '|',
joinRight: '|',
joinJoin: '|',
joinMiddleDown: '+',
joinMiddleUp: '+',
joinMiddleLeft: '+',
joinMiddleRight: '+',
};
}
if (name === 'void') {
@@ -81,8 +93,13 @@ const getBorderCharacters = (name) => {
joinLeft: '',
joinRight: '',
joinJoin: '',
joinMiddleDown: '',
joinMiddleUp: '',
joinMiddleLeft: '',
joinMiddleRight: '',
};
}
throw new Error('Unknown border template "' + name + '".');
};
exports.getBorderCharacters = getBorderCharacters;
//# sourceMappingURL=getBorderCharacters.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"getBorderCharacters.js","sourceRoot":"","sources":["../../src/getBorderCharacters.ts"],"names":[],"mappings":";AAAA,gDAAgD;;;AAMzC,MAAM,mBAAmB,GAAG,CAAC,IAAY,EAAgB,EAAE;IAChE,IAAI,IAAI,KAAK,WAAW,EAAE;QACxB,OAAO;YACL,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,GAAG;YACZ,QAAQ,EAAE,GAA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AQ,EAAE,GAAG;YACb,UAAU,EAAE,GAAG;YAEf,QAAQ,EAAE,GAAG;YACb,QAAQ,EAAE,GAAG;YACb,SAAS,EAAE,GAAG;YACd,QAAQ,EAAE,GAAG;YACb,cAAc,EAAE,GAAG;YACnB,YAAY,EAAE,GAAG;YACjB,cAAc,EAAE,GAAG;YACnB,eAAe,EAAE,GAAG;SACrB,CAAC;KACH;IAED,IAAI,IAAI,KAAK,MAAM,EAAE;QACnB,OAAO;YACL,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,EAAE;YACX,QAAQ,EAAE,EAAE;YAEZ,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,EAAE;YACd,UAAU,EAAE,EAAE;YACd,WAAW,EAAE,EAAE;YAEf,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,EAAE;YAEd,QAAQ,EAAE,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,EAAE;YACZ,cAAc,EAAE,EAAE;YAClB,YAAY,EAAE,EAAE;YAChB,cAAc,EAAE,EAAE;YAClB,eAAe,EAAE,EAAE;SACpB,CAAC;KACH;IAED,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;AAC7D,CAAC,CAAC;AAlHW,QAAA,mBAAmB,uBAkH9B"}
@@ -18,3 +18,4 @@ Object.defineProperty(exports, "getBorderCharacters", { enumerable: true, get: f
const table_1 = require("./table");
Object.defineProperty(exports, "table", { enumerable: true, get: function () { return table_1.table; } });
__exportStar(require("./types/api"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,iDAEwB;AAUtB,6FAXA,2BAAY,OAWA;AATd,+DAE+B;AAQ7B,oGATA,yCAAmB,OASA;AAPrB,mCAEiB;AAGf,sFAJA,aAAK,OAIA;AAKP,8CAA4B"}
+3
View File
@@ -0,0 +1,3 @@
import type { SpanningCellConfig, TableUserConfig } from './types/api';
import type { Row } from './types/internal';
export declare const injectHeaderConfig: (rows: Row[], config: TableUserConfig) => [Row[], SpanningCellConfig[]];
+29
View File
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectHeaderConfig = void 0;
const injectHeaderConfig = (rows, config) => {
var _a;
let spanningCellConfig = (_a = config.spanningCells) !== null && _a !== void 0 ? _a : [];
const headerConfig = config.header;
const adjustedRows = [...rows];
if (headerConfig) {
spanningCellConfig = spanningCellConfig.map(({ row, ...rest }) => {
return { ...rest,
row: row + 1 };
});
const { content, ...headerStyles } = headerConfig;
spanningCellConfig.unshift({ alignment: 'center',
col: 0,
colSpan: rows[0].length,
paddingLeft: 1,
paddingRight: 1,
row: 0,
wrapWord: false,
...headerStyles });
adjustedRows.unshift([content, ...Array.from({ length: rows[0].length - 1 }).fill('')]);
}
return [adjustedRows,
spanningCellConfig];
};
exports.injectHeaderConfig = injectHeaderConfig;
//# sourceMappingURL=injectHeaderConfig.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"injectHeaderConfig.js","sourceRoot":"","sources":["../../src/injectHeaderConfig.ts"],"names":[],"mappings":";;;AAQO,MAAM,kBAAkB,GAAG,CAAC,IAAW,EAAE,MAAuB,EAAiC,EAAE;;IACxG,IAAI,kBAAkB,GAAG,MAAA,MAAM,CAAC,aAAa,mCAAI,EAAE,CAAC;IACpD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IAE/B,IAAI,YAAY,EAAE;QAChB,kBAAkB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAC,GAAG,EAAE,GAAG,IAAI,EAAC,EAAE,EAAE;YAC7D,OAAO,EAAC,GAAG,IAAI;gBACb,GAAG,EAAE,GAAG,GAAG,CAAC,EAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM,EAAC,OAAO,EAAE,GAAG,YAAY,EAAC,GAAG,YAAY,CAAC;QAEhD,kBAAkB,CAAC,OAAO,CAAC,EAAC,SAAS,EAAE,QAAQ;YAC7C,GAAG,EAAE,CAAC;YACN,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM;YACvB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,GAAG,EAAE,CAAC;YACN,QAAQ,EAAE,KAAK;YACf,GAAG,YAAY,EAAC,CAAC,CAAC;QAEpB,YAAY,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,IAAI,CAAS,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC/F;IAED,OAAO,CAAC,YAAY;QAClB,kBAAkB,CAAC,CAAC;AACxB,CAAC,CAAC;AA3BW,QAAA,kBAAkB,sBA2B7B"}
+3
View File
@@ -0,0 +1,3 @@
import type { SpanningCellConfig } from './types/api';
import type { ColumnConfig, RangeConfig } from './types/internal';
export declare const makeRangeConfig: (spanningCellConfig: SpanningCellConfig, columnsConfig: ColumnConfig[]) => RangeConfig;
+18
View File
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeRangeConfig = void 0;
const utils_1 = require("./utils");
const makeRangeConfig = (spanningCellConfig, columnsConfig) => {
var _a;
const { topLeft, bottomRight } = (0, utils_1.calculateRangeCoordinate)(spanningCellConfig);
const cellConfig = {
...columnsConfig[topLeft.col],
...spanningCellConfig,
paddingRight: (_a = spanningCellConfig.paddingRight) !== null && _a !== void 0 ? _a : columnsConfig[bottomRight.col].paddingRight,
};
return { ...cellConfig,
bottomRight,
topLeft };
};
exports.makeRangeConfig = makeRangeConfig;
//# sourceMappingURL=makeRangeConfig.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"makeRangeConfig.js","sourceRoot":"","sources":["../../src/makeRangeConfig.ts"],"names":[],"mappings":";;;AAMA,mCAEiB;AAEV,MAAM,eAAe,GAAG,CAAC,kBAAsC,EAAE,aAA6B,EAAe,EAAE;;IACpH,MAAM,EAAC,OAAO,EAAE,WAAW,EAAC,GAAG,IAAA,gCAAwB,EAAC,kBAAkB,CAAC,CAAC;IAE5E,MAAM,UAAU,GAA6B;QAC3C,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC;QAC7B,GAAG,kBAAkB;QACrB,YAAY,EACV,MAAA,kBAAkB,CAAC,YAAY,mCAC/B,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,YAAY;KAC9C,CAAC;IAEF,OAAO,EAAC,GAAG,UAAU;QACnB,WAAW;QACX,OAAO,EAAC,CAAC;AACb,CAAC,CAAC;AAdW,QAAA,eAAe,mBAc1B"}
@@ -4,4 +4,4 @@ import type { StreamConfig } from './types/internal';
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
export declare const makeStreamConfig: (userConfig: StreamUserConfig) => StreamConfig;
export declare const makeStreamConfig: (config: StreamUserConfig) => StreamConfig;
@@ -1,10 +1,6 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeStreamConfig = void 0;
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
const utils_1 = require("./utils");
const validateConfig_1 = require("./validateConfig");
/**
@@ -29,9 +25,8 @@ const makeColumnsConfig = (columnCount, columns = {}, columnDefault) => {
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
const makeStreamConfig = (userConfig) => {
validateConfig_1.validateConfig('streamConfig.json', userConfig);
const config = lodash_clonedeep_1.default(userConfig);
const makeStreamConfig = (config) => {
(0, validateConfig_1.validateConfig)('streamConfig.json', config);
if (config.columnDefault.width === undefined) {
throw new Error('Must provide config.columnDefault.width when creating a stream.');
}
@@ -40,8 +35,9 @@ const makeStreamConfig = (userConfig) => {
return true;
},
...config,
border: utils_1.makeBorderConfig(config.border),
border: (0, utils_1.makeBorderConfig)(config.border),
columns: makeColumnsConfig(config.columnCount, config.columns, config.columnDefault),
};
};
exports.makeStreamConfig = makeStreamConfig;
//# sourceMappingURL=makeStreamConfig.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"makeStreamConfig.js","sourceRoot":"","sources":["../../src/makeStreamConfig.ts"],"names":[],"mappings":";;;AASA,mCAEiB;AACjB,qDAE0B;AAE1B;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAC5C,UAAuC,EAAE,EACzC,aAAgD,EAAkB,EAAE;IACpE,OAAO,KAAK,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,WAAW,EAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QACxD,OAAO;YACL,SAAS,EAAE,MAAM;YACjB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,QAAQ,EAAE,MAAM,CAAC,iBAAiB;YAClC,iBAAiB,EAAE,KAAK;YACxB,QAAQ,EAAE,KAAK;YACf,GAAG,aAAa;YAChB,GAAG,OAAO,CAAC,KAAK,CAAC;SAClB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;GAGG;AACI,MAAM,gBAAgB,GAAG,CAAC,MAAwB,EAAgB,EAAE;IACzE,IAAA,+BAAc,EAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAE5C,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,KAAK,SAAS,EAAE;QAC5C,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;KACpF;IAED,OAAO;QACL,gBAAgB,EAAE,GAAG,EAAE;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,GAAG,MAAM;QACT,MAAM,EAAE,IAAA,wBAAgB,EAAC,MAAM,CAAC,MAAM,CAAC;QACvC,OAAO,EAAE,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC;KACrF,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,gBAAgB,oBAe3B"}
+7
View File
@@ -0,0 +1,7 @@
import type { SpanningCellConfig, TableUserConfig } from './types/api';
import type { Row, TableConfig } from './types/internal';
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
export declare const makeTableConfig: (rows: Row[], config?: TableUserConfig, injectedSpanningCellConfig?: SpanningCellConfig[] | undefined) => TableConfig;
+62
View File
@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeTableConfig = void 0;
const calculateMaximumColumnWidths_1 = require("./calculateMaximumColumnWidths");
const spanningCellManager_1 = require("./spanningCellManager");
const utils_1 = require("./utils");
const validateConfig_1 = require("./validateConfig");
const validateSpanningCellConfig_1 = require("./validateSpanningCellConfig");
/**
* Creates a configuration for every column using default
* values for the missing configuration properties.
*/
const makeColumnsConfig = (rows, columns, columnDefault, spanningCellConfigs) => {
const columnWidths = (0, calculateMaximumColumnWidths_1.calculateMaximumColumnWidths)(rows, spanningCellConfigs);
return rows[0].map((_, columnIndex) => {
return {
alignment: 'left',
paddingLeft: 1,
paddingRight: 1,
truncate: Number.POSITIVE_INFINITY,
verticalAlignment: 'top',
width: columnWidths[columnIndex],
wrapWord: false,
...columnDefault,
...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
};
});
};
/**
* Makes a new configuration object out of the userConfig object
* using default values for the missing configuration properties.
*/
const makeTableConfig = (rows, config = {}, injectedSpanningCellConfig) => {
var _a, _b, _c, _d, _e;
(0, validateConfig_1.validateConfig)('config.json', config);
(0, validateSpanningCellConfig_1.validateSpanningCellConfig)(rows, (_a = config.spanningCells) !== null && _a !== void 0 ? _a : []);
const spanningCellConfigs = (_b = injectedSpanningCellConfig !== null && injectedSpanningCellConfig !== void 0 ? injectedSpanningCellConfig : config.spanningCells) !== null && _b !== void 0 ? _b : [];
const columnsConfig = makeColumnsConfig(rows, config.columns, config.columnDefault, spanningCellConfigs);
const drawVerticalLine = (_c = config.drawVerticalLine) !== null && _c !== void 0 ? _c : (() => {
return true;
});
const drawHorizontalLine = (_d = config.drawHorizontalLine) !== null && _d !== void 0 ? _d : (() => {
return true;
});
return {
...config,
border: (0, utils_1.makeBorderConfig)(config.border),
columns: columnsConfig,
drawHorizontalLine,
drawVerticalLine,
singleLine: (_e = config.singleLine) !== null && _e !== void 0 ? _e : false,
spanningCellManager: (0, spanningCellManager_1.createSpanningCellManager)({
columnsConfig,
drawHorizontalLine,
drawVerticalLine,
rows,
spanningCellConfigs,
}),
};
};
exports.makeTableConfig = makeTableConfig;
//# sourceMappingURL=makeTableConfig.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"makeTableConfig.js","sourceRoot":"","sources":["../../src/makeTableConfig.ts"],"names":[],"mappings":";;;AAAA,iFAEwC;AACxC,+DAE+B;AAS/B,mCAEiB;AACjB,qDAE0B;AAC1B,6EAEsC;AAEtC;;;GAGG;AACH,MAAM,iBAAiB,GAAG,CAAC,IAAW,EACpC,OAAqC,EACrC,aAAgC,EAChC,mBAA0C,EAAkB,EAAE;IAC9D,MAAM,YAAY,GAAG,IAAA,2DAA4B,EAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAE7E,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE;QACpC,OAAO;YACL,SAAS,EAAE,MAAM;YACjB,WAAW,EAAE,CAAC;YACd,YAAY,EAAE,CAAC;YACf,QAAQ,EAAE,MAAM,CAAC,iBAAiB;YAClC,iBAAiB,EAAE,K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mBAAmB;SACpB,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,eAAe,mBA8B1B"}
+4
View File
@@ -0,0 +1,4 @@
import type { VerticalAlignment } from './types/api';
import type { BaseConfig, Row } from './types/internal';
export declare const padCellVertically: (lines: string[], rowHeight: number, verticalAlignment: VerticalAlignment) => string[];
export declare const mapDataUsingRowHeights: (unmappedRows: Row[], rowHeights: number[], config: BaseConfig) => Row[];
@@ -1,12 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapDataUsingRowHeights = void 0;
exports.mapDataUsingRowHeights = exports.padCellVertically = void 0;
const utils_1 = require("./utils");
const wrapCell_1 = require("./wrapCell");
const createEmptyStrings = (length) => {
return new Array(length).fill('');
};
const padCellVertically = (lines, rowHeight, columnConfig) => {
const { verticalAlignment } = columnConfig;
const padCellVertically = (lines, rowHeight, verticalAlignment) => {
const availableLines = rowHeight - lines.length;
if (verticalAlignment === 'top') {
return [...lines, ...createEmptyStrings(availableLines)];
@@ -20,25 +20,33 @@ const padCellVertically = (lines, rowHeight, columnConfig) => {
...createEmptyStrings(Math.ceil(availableLines / 2)),
];
};
const flatten = (array) => {
return [].concat(...array);
};
exports.padCellVertically = padCellVertically;
const mapDataUsingRowHeights = (unmappedRows, rowHeights, config) => {
const tableWidth = unmappedRows[0].length;
const nColumns = unmappedRows[0].length;
const mappedRows = unmappedRows.map((unmappedRow, unmappedRowIndex) => {
const outputRowHeight = rowHeights[unmappedRowIndex];
const outputRow = Array.from({ length: outputRowHeight }, () => {
return new Array(tableWidth).fill('');
return new Array(nColumns).fill('');
});
unmappedRow.forEach((cell, cellIndex) => {
const cellLines = wrapCell_1.wrapCell(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
const paddedCellLines = padCellVertically(cellLines, outputRowHeight, config.columns[cellIndex]);
var _a;
const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
row: unmappedRowIndex });
if (containingRange) {
containingRange.extractCellContent(unmappedRowIndex).forEach((cellLine, cellLineIndex) => {
outputRow[cellLineIndex][cellIndex] = cellLine;
});
return;
}
const cellLines = (0, wrapCell_1.wrapCell)(cell, config.columns[cellIndex].width, config.columns[cellIndex].wrapWord);
const paddedCellLines = (0, exports.padCellVertically)(cellLines, outputRowHeight, config.columns[cellIndex].verticalAlignment);
paddedCellLines.forEach((cellLine, cellLineIndex) => {
outputRow[cellLineIndex][cellIndex] = cellLine;
});
});
return outputRow;
});
return flatten(mappedRows);
return (0, utils_1.flatten)(mappedRows);
};
exports.mapDataUsingRowHeights = mapDataUsingRowHeights;
//# sourceMappingURL=mapDataUsingRowHeights.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"mapDataUsingRowHeights.js","sourceRoot":"","sources":["../../src/mapDataUsingRowHeights.ts"],"names":[],"mappings":";;;AAOA,mCAEiB;AACjB,yCAEoB;AAEpB,MAAM,kBAAkB,GAAG,CAAC,MAAc,EAAE,EAAE;IAC5C,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC,CAAC;AAEK,MAAM,iBAAiB,GAAG,CAAC,KAAe,EAAE,SAAiB,EAAE,iBAAoC,EAAY,EAAE;IACtH,MAAM,cAAc,GAAG,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC;IAEhD,IAAI,iBAAiB,KAAK,KAAK,EAAE;QAC/B,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC,CAAC;KAC1D;IAED,IAAI,iBAAiB,KAAK,QAAQ,EAAE;QAClC,OAAO,CAAC,GAAG,kBAAkB,CAAC,cAAc,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC;KAC1D;IAED,OAAO;QACL,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;QACrD,GAAG,KAAK;QACR,GAAG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AC,CAAC;YAEtG,MAAM,eAAe,GAAG,IAAA,yBAAiB,EAAC,SAAS,EAAE,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAEnH,eAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,aAAa,EAAE,EAAE;gBAClD,SAAS,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;YACjD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,IAAA,eAAO,EAAC,UAAU,CAAC,CAAC;AAC7B,CAAC,CAAC;AAhCW,QAAA,sBAAsB,0BAgCjC"}
@@ -6,11 +6,18 @@ const padString = (input, paddingLeft, paddingRight) => {
};
exports.padString = padString;
const padTableData = (rows, config) => {
return rows.map((cells) => {
return rows.map((cells, rowIndex) => {
return cells.map((cell, cellIndex) => {
var _a;
const containingRange = (_a = config.spanningCellManager) === null || _a === void 0 ? void 0 : _a.getContainingRange({ col: cellIndex,
row: rowIndex }, { mapped: true });
if (containingRange) {
return cell;
}
const { paddingLeft, paddingRight } = config.columns[cellIndex];
return exports.padString(cell, paddingLeft, paddingRight);
return (0, exports.padString)(cell, paddingLeft, paddingRight);
});
});
};
exports.padTableData = padTableData;
//# sourceMappingURL=padTableData.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"padTableData.js","sourceRoot":"","sources":["../../src/padTableData.ts"],"names":[],"mappings":";;;AAKO,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,WAAmB,EAAE,YAAoB,EAAU,EAAE;IAC5F,OAAO,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AACpE,CAAC,CAAC;AAFW,QAAA,SAAS,aAEpB;AAEK,MAAM,YAAY,GAAG,CAAC,IAAW,EAAE,MAAkB,EAAS,EAAE;IACrE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QAClC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;;YACnC,MAAM,eAAe,GAAG,MAAA,MAAM,CAAC,mBAAmB,0CAAE,kBAAkB,CAAC,EAAC,GAAG,EAAE,SAAS;gBACpF,GAAG,EAAE,QAAQ,EAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;YAClC,IAAI,eAAe,EAAE;gBACnB,OAAO,IAAI,CAAC;aACb;YAED,MAAM,EAAC,WAAW,EAAE,YAAY,EAAC,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAE9D,OAAO,IAAA,iBAAS,EAAC,IAAI,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB"}
+95
View File
@@ -0,0 +1,95 @@
{
"$id": "config.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "shared.json#/definitions/borders"
},
"header": {
"type": "object",
"properties": {
"content": {
"type": "string"
},
"alignment": {
"$ref": "shared.json#/definitions/alignment"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "integer"
},
"paddingLeft": {
"type": "integer"
},
"paddingRight": {
"type": "integer"
}
},
"required": ["content"],
"additionalProperties": false
},
"columns": {
"$ref": "shared.json#/definitions/columns"
},
"columnDefault": {
"$ref": "shared.json#/definitions/column"
},
"drawVerticalLine": {
"typeof": "function"
},
"drawHorizontalLine": {
"typeof": "function"
},
"singleLine": {
"typeof": "boolean"
},
"spanningCells": {
"type": "array",
"items": {
"type": "object",
"properties": {
"col": {
"type": "integer",
"minimum": 0
},
"row": {
"type": "integer",
"minimum": 0
},
"colSpan": {
"type": "integer",
"minimum": 1
},
"rowSpan": {
"type": "integer",
"minimum": 1
},
"alignment": {
"$ref": "shared.json#/definitions/alignment"
},
"verticalAlignment": {
"$ref": "shared.json#/definitions/verticalAlignment"
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "integer"
},
"paddingLeft": {
"type": "integer"
},
"paddingRight": {
"type": "integer"
}
},
"required": ["row", "col"],
"additionalProperties": false
}
}
},
"additionalProperties": false
}
+139
View File
@@ -0,0 +1,139 @@
{
"$id": "shared.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"columns": {
"oneOf": [
{
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"$ref": "#/definitions/column"
}
},
"additionalProperties": false
},
{
"type": "array",
"items": {
"$ref": "#/definitions/column"
}
}
]
},
"column": {
"type": "object",
"properties": {
"alignment": {
"$ref": "#/definitions/alignment"
},
"verticalAlignment": {
"$ref": "#/definitions/verticalAlignment"
},
"width": {
"type": "integer",
"minimum": 1
},
"wrapWord": {
"type": "boolean"
},
"truncate": {
"type": "integer"
},
"paddingLeft": {
"type": "integer"
},
"paddingRight": {
"type": "integer"
}
},
"additionalProperties": false
},
"borders": {
"type": "object",
"properties": {
"topBody": {
"$ref": "#/definitions/border"
},
"topJoin": {
"$ref": "#/definitions/border"
},
"topLeft": {
"$ref": "#/definitions/border"
},
"topRight": {
"$ref": "#/definitions/border"
},
"bottomBody": {
"$ref": "#/definitions/border"
},
"bottomJoin": {
"$ref": "#/definitions/border"
},
"bottomLeft": {
"$ref": "#/definitions/border"
},
"bottomRight": {
"$ref": "#/definitions/border"
},
"bodyLeft": {
"$ref": "#/definitions/border"
},
"bodyRight": {
"$ref": "#/definitions/border"
},
"bodyJoin": {
"$ref": "#/definitions/border"
},
"headerJoin": {
"$ref": "#/definitions/border"
},
"joinBody": {
"$ref": "#/definitions/border"
},
"joinLeft": {
"$ref": "#/definitions/border"
},
"joinRight": {
"$ref": "#/definitions/border"
},
"joinJoin": {
"$ref": "#/definitions/border"
},
"joinMiddleUp": {
"$ref": "#/definitions/border"
},
"joinMiddleDown": {
"$ref": "#/definitions/border"
},
"joinMiddleLeft": {
"$ref": "#/definitions/border"
},
"joinMiddleRight": {
"$ref": "#/definitions/border"
}
},
"additionalProperties": false
},
"border": {
"type": "string"
},
"alignment": {
"type": "string",
"enum": [
"left",
"right",
"center",
"justify"
]
},
"verticalAlignment": {
"type": "string",
"enum": [
"top",
"middle",
"bottom"
]
}
}
}
+25
View File
@@ -0,0 +1,25 @@
{
"$id": "streamConfig.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"border": {
"$ref": "shared.json#/definitions/borders"
},
"columns": {
"$ref": "shared.json#/definitions/columns"
},
"columnDefault": {
"$ref": "shared.json#/definitions/column"
},
"columnCount": {
"type": "integer",
"minimum": 1
},
"drawVerticalLine": {
"typeof": "function"
}
},
"required": ["columnDefault", "columnCount"],
"additionalProperties": false
}
+21
View File
@@ -0,0 +1,21 @@
import type { DrawHorizontalLine, DrawVerticalLine, SpanningCellConfig } from './types/api';
import type { CellCoordinates, ColumnConfig, ResolvedRangeConfig, Row } from './types/internal';
export declare type SpanningCellManager = {
getContainingRange: (cell: CellCoordinates, options?: {
mapped: true;
}) => ResolvedRangeConfig | undefined;
inSameRange: (cell1: CellCoordinates, cell2: CellCoordinates) => boolean;
rowHeights: number[];
setRowHeights: (rowHeights: number[]) => void;
};
export declare type SpanningCellParameters = {
spanningCellConfigs: SpanningCellConfig[];
rows: Row[];
columnsConfig: ColumnConfig[];
drawVerticalLine: DrawVerticalLine;
drawHorizontalLine: DrawHorizontalLine;
};
export declare type SpanningCellContext = SpanningCellParameters & {
rowHeights: number[];
};
export declare const createSpanningCellManager: (parameters: SpanningCellParameters) => SpanningCellManager;
+86
View File
@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSpanningCellManager = void 0;
const alignSpanningCell_1 = require("./alignSpanningCell");
const calculateSpanningCellWidth_1 = require("./calculateSpanningCellWidth");
const makeRangeConfig_1 = require("./makeRangeConfig");
const utils_1 = require("./utils");
const findRangeConfig = (cell, rangeConfigs) => {
return rangeConfigs.find((rangeCoordinate) => {
return (0, utils_1.isCellInRange)(cell, rangeCoordinate);
});
};
const getContainingRange = (rangeConfig, context) => {
const width = (0, calculateSpanningCellWidth_1.calculateSpanningCellWidth)(rangeConfig, context);
const wrappedContent = (0, alignSpanningCell_1.wrapRangeContent)(rangeConfig, width, context);
const alignedContent = (0, alignSpanningCell_1.alignVerticalRangeContent)(rangeConfig, wrappedContent, context);
const getCellContent = (rowIndex) => {
const { topLeft } = rangeConfig;
const { drawHorizontalLine, rowHeights } = context;
const totalWithinHorizontalBorderHeight = rowIndex - topLeft.row;
const totalHiddenHorizontalBorderHeight = (0, utils_1.sequence)(topLeft.row + 1, rowIndex).filter((index) => {
/* istanbul ignore next */
return !(drawHorizontalLine === null || drawHorizontalLine === void 0 ? void 0 : drawHorizontalLine(index, rowHeights.length));
}).length;
const offset = (0, utils_1.sumArray)(rowHeights.slice(topLeft.row, rowIndex)) + totalWithinHorizontalBorderHeight - totalHiddenHorizontalBorderHeight;
return alignedContent.slice(offset, offset + rowHeights[rowIndex]);
};
const getBorderContent = (borderIndex) => {
const { topLeft } = rangeConfig;
const offset = (0, utils_1.sumArray)(context.rowHeights.slice(topLeft.row, borderIndex)) + (borderIndex - topLeft.row - 1);
return alignedContent[offset];
};
return {
...rangeConfig,
extractBorderContent: getBorderContent,
extractCellContent: getCellContent,
height: wrappedContent.length,
width,
};
};
const inSameRange = (cell1, cell2, ranges) => {
const range1 = findRangeConfig(cell1, ranges);
const range2 = findRangeConfig(cell2, ranges);
if (range1 && range2) {
return (0, utils_1.areCellEqual)(range1.topLeft, range2.topLeft);
}
return false;
};
const hashRange = (range) => {
const { row, col } = range.topLeft;
return `${row}/${col}`;
};
const createSpanningCellManager = (parameters) => {
const { spanningCellConfigs, columnsConfig } = parameters;
const ranges = spanningCellConfigs.map((config) => {
return (0, makeRangeConfig_1.makeRangeConfig)(config, columnsConfig);
});
const rangeCache = {};
let rowHeights = [];
return { getContainingRange: (cell, options) => {
var _a;
const originalRow = (options === null || options === void 0 ? void 0 : options.mapped) ? (0, utils_1.findOriginalRowIndex)(rowHeights, cell.row) : cell.row;
const range = findRangeConfig({ ...cell,
row: originalRow }, ranges);
if (!range) {
return undefined;
}
if (rowHeights.length === 0) {
return getContainingRange(range, { ...parameters,
rowHeights });
}
const hash = hashRange(range);
(_a = rangeCache[hash]) !== null && _a !== void 0 ? _a : (rangeCache[hash] = getContainingRange(range, { ...parameters,
rowHeights }));
return rangeCache[hash];
},
inSameRange: (cell1, cell2) => {
return inSameRange(cell1, cell2, ranges);
},
rowHeights,
setRowHeights: (_rowHeights) => {
rowHeights = _rowHeights;
} };
};
exports.createSpanningCellManager = createSpanningCellManager;
//# sourceMappingURL=spanningCellManager.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"spanningCellManager.js","sourceRoot":"","sources":["../../src/spanningCellManager.ts"],"names":[],"mappings":";;;AAAA,2DAE6B;AAC7B,6EAEsC;AACtC,uDAE2B;AAa3B,mCAIiB;AAqBjB,MAAM,eAAe,GAAG,CAAC,IAAqB,EAAE,YAA2B,EAA2B,EAAE;IACtG,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,EAAE;QAC3C,OAAO,IAAA,qBAAa,EAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,WAAwB,EAAE,OAA4B,EAAmC,EAAE;IACrH,MAAM,KAAK,GAAG,IAAA,uDAA0B,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE/D,MAAM,cAAc,GAAG,IAAA,oCAAgB,EAAC,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAErE,MAAM,cAAc,GAAG,IAAA,6CAAyB,EAAC,WAAW,EAAE,cAAc,EAAE,O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,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;YAE5F,MAAM,KAAK,GAAG,eAAe,CAAC,EAAC,GAAG,IAAI;gBACpC,GAAG,EAAE,WAAW,EAAC,EAAE,MAAM,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,EAAE;gBACV,OAAO,SAAS,CAAC;aAClB;YAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC3B,OAAO,kBAAkB,CAAC,KAAK,EAAE,EAAC,GAAG,UAAU;oBAC7C,UAAU,EAAC,CAAC,CAAC;aAChB;YAED,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAC9B,MAAA,UAAU,CAAC,IAAI,qCAAf,UAAU,CAAC,IAAI,IAAM,kBAAkB,CAAC,KAAK,EAAE,EAAC,GAAG,UAAU;gBAC3D,UAAU,EAAC,CAAC,EAAC;YAEf,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QACD,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAC5B,OAAO,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAC3C,CAAC;QACD,UAAU;QACV,aAAa,EAAE,CAAC,WAAqB,EAAE,EAAE;YACvC,UAAU,GAAG,WAAW,CAAC;QAC3B,CAAC,EAAC,CAAC;AACL,CAAC,CAAC;AArCW,QAAA,yBAAyB,6BAqCpC"}
@@ -5,8 +5,9 @@ const utils_1 = require("./utils");
const stringifyTableData = (rows) => {
return rows.map((cells) => {
return cells.map((cell) => {
return utils_1.normalizeString(String(cell));
return (0, utils_1.normalizeString)(String(cell));
});
});
};
exports.stringifyTableData = stringifyTableData;
//# sourceMappingURL=stringifyTableData.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"stringifyTableData.js","sourceRoot":"","sources":["../../src/stringifyTableData.ts"],"names":[],"mappings":";;;AAGA,mCAEiB;AAEV,MAAM,kBAAkB,GAAG,CAAC,IAAiB,EAAS,EAAE;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACxB,OAAO,IAAA,uBAAe,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,kBAAkB,sBAM7B"}
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.table = void 0;
const alignTableData_1 = require("./alignTableData");
const calculateOutputColumnWidths_1 = require("./calculateOutputColumnWidths");
const calculateRowHeights_1 = require("./calculateRowHeights");
const drawTable_1 = require("./drawTable");
const injectHeaderConfig_1 = require("./injectHeaderConfig");
const makeTableConfig_1 = require("./makeTableConfig");
const mapDataUsingRowHeights_1 = require("./mapDataUsingRowHeights");
const padTableData_1 = require("./padTableData");
const stringifyTableData_1 = require("./stringifyTableData");
const truncateTableData_1 = require("./truncateTableData");
const utils_1 = require("./utils");
const validateTableData_1 = require("./validateTableData");
const table = (data, userConfig = {}) => {
(0, validateTableData_1.validateTableData)(data);
let rows = (0, stringifyTableData_1.stringifyTableData)(data);
const [injectedRows, injectedSpanningCellConfig] = (0, injectHeaderConfig_1.injectHeaderConfig)(rows, userConfig);
const config = (0, makeTableConfig_1.makeTableConfig)(injectedRows, userConfig, injectedSpanningCellConfig);
rows = (0, truncateTableData_1.truncateTableData)(injectedRows, (0, utils_1.extractTruncates)(config));
const rowHeights = (0, calculateRowHeights_1.calculateRowHeights)(rows, config);
config.spanningCellManager.setRowHeights(rowHeights);
rows = (0, mapDataUsingRowHeights_1.mapDataUsingRowHeights)(rows, rowHeights, config);
rows = (0, alignTableData_1.alignTableData)(rows, config);
rows = (0, padTableData_1.padTableData)(rows, config);
const outputColumnWidths = (0, calculateOutputColumnWidths_1.calculateOutputColumnWidths)(config);
return (0, drawTable_1.drawTable)(rows, outputColumnWidths, rowHeights, config);
};
exports.table = table;
//# sourceMappingURL=table.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/table.ts"],"names":[],"mappings":";;;AAAA,qDAE0B;AAC1B,+EAEuC;AACvC,+DAE+B;AAC/B,2CAEqB;AACrB,6DAE8B;AAC9B,uDAE2B;AAC3B,qEAEkC;AAClC,iDAEwB;AACxB,6DAE8B;AAC9B,2DAE6B;AAI7B,mCAEiB;AACjB,2DAE6B;AAEtB,MAAM,KAAK,GAAG,CAAC,IAAiB,EAAE,aAA8B,EAAE,EAAU,EAAE;IACnF,IAAA,qCAAiB,EAAC,IAAI,CAAC,CAAC;IAExB,IAAI,IAAI,GAAG,IAAA,uCAAkB,EAAC,IAAI,CAAC,CAAC;IAEpC,MAAM,CAAC,YAAY,EAAE,0BAA0B,CAAC,GAAG,IAAA,uCAAkB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAExF,MAAM,MAAM,GAAG,IAAA,iCAAe,EAAC,YAAY,EAAE,UAAU,EAAE,0BAA0B,CAAC,CAAC;IAErF,IAAI,GAAG,IAAA,qCAAiB,EAAC,YAAY,EAAE,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC,CAAC;IAEjE,MAAM,UAAU,GAAG,IAAA,yCAAmB,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAErD,MAAM,CAAC,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAErD,IAAI,GAAG,IAAA,+CAAsB,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACxD,IAAI,GAAG,IAAA,+BAAc,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACpC,IAAI,GAAG,IAAA,2BAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAElC,MAAM,kBAAkB,GAAG,IAAA,yDAA2B,EAAC,MAAM,CAAC,CAAC;IAE/D,OAAO,IAAA,qBAAS,EAAC,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC,CAAC;AAtBW,QAAA,KAAK,SAsBhB"}
+6
View File
@@ -0,0 +1,6 @@
import type { Row } from './types/internal';
export declare const truncateString: (input: string, length: number) => string;
/**
* @todo Make it work with ASCII content.
*/
export declare const truncateTableData: (rows: Row[], truncates: number[]) => Row[];
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.truncateTableData = exports.truncateString = void 0;
const lodash_truncate_1 = __importDefault(require("lodash.truncate"));
const truncateString = (input, length) => {
return lodash_truncate_1.default(input, { length,
return (0, lodash_truncate_1.default)(input, { length,
omission: '…' });
};
exports.truncateString = truncateString;
/**
* @todo Make it work with ASCII content.
*/
const truncateTableData = (rows, config) => {
const truncateTableData = (rows, truncates) => {
return rows.map((cells) => {
return cells.map((cell, cellIndex) => {
return exports.truncateString(cell, config.columns[cellIndex].truncate);
return (0, exports.truncateString)(cell, truncates[cellIndex]);
});
});
};
exports.truncateTableData = truncateTableData;
//# sourceMappingURL=truncateTableData.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"truncateTableData.js","sourceRoot":"","sources":["../../src/truncateTableData.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAuC;AAKhC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,MAAc,EAAU,EAAE;IACtE,OAAO,IAAA,yBAAQ,EAAC,KAAK,EAAE,EAAC,MAAM;QAC5B,QAAQ,EAAE,GAAG,EAAC,CAAC,CAAC;AACpB,CAAC,CAAC;AAHW,QAAA,cAAc,kBAGzB;AAEF;;GAEG;AACI,MAAM,iBAAiB,GAAG,CAAC,IAAW,EAAE,SAAmB,EAAS,EAAE;IAC3E,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;YACnC,OAAO,IAAA,sBAAc,EAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,iBAAiB,qBAM5B"}

Some files were not shown because too many files have changed in this diff Show More