svg-table 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/d3types.ts +17 -0
  4. package/dist/d3types.d.ts +12 -0
  5. package/dist/d3types.d.ts.map +1 -0
  6. package/dist/d3types.js +3 -0
  7. package/dist/d3types.js.map +1 -0
  8. package/dist/index.d.ts +10 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +36 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/stylings.d.ts +206 -0
  13. package/dist/stylings.d.ts.map +1 -0
  14. package/dist/stylings.js +123 -0
  15. package/dist/stylings.js.map +1 -0
  16. package/dist/tableData.d.ts +168 -0
  17. package/dist/tableData.d.ts.map +1 -0
  18. package/dist/tableData.js +329 -0
  19. package/dist/tableData.js.map +1 -0
  20. package/dist/tableData.test.d.ts +2 -0
  21. package/dist/tableData.test.d.ts.map +1 -0
  22. package/dist/tableData.test.js +259 -0
  23. package/dist/tableData.test.js.map +1 -0
  24. package/dist/tableFormatter.d.ts +179 -0
  25. package/dist/tableFormatter.d.ts.map +1 -0
  26. package/dist/tableFormatter.js +298 -0
  27. package/dist/tableFormatter.js.map +1 -0
  28. package/dist/tableFormatter.test.d.ts +2 -0
  29. package/dist/tableFormatter.test.d.ts.map +1 -0
  30. package/dist/tableFormatter.test.js +101 -0
  31. package/dist/tableFormatter.test.js.map +1 -0
  32. package/dist/tableStyler.d.ts +310 -0
  33. package/dist/tableStyler.d.ts.map +1 -0
  34. package/dist/tableStyler.js +665 -0
  35. package/dist/tableStyler.js.map +1 -0
  36. package/dist/tableStyler.test.d.ts +2 -0
  37. package/dist/tableStyler.test.d.ts.map +1 -0
  38. package/dist/tableStyler.test.js +225 -0
  39. package/dist/tableStyler.test.js.map +1 -0
  40. package/dist/tableSvg.d.ts +41 -0
  41. package/dist/tableSvg.d.ts.map +1 -0
  42. package/dist/tableSvg.js +634 -0
  43. package/dist/tableSvg.js.map +1 -0
  44. package/dist/tableUtils.d.ts +14 -0
  45. package/dist/tableUtils.d.ts.map +1 -0
  46. package/dist/tableUtils.js +18 -0
  47. package/dist/tableUtils.js.map +1 -0
  48. package/eslint.config.js +23 -0
  49. package/index.ts +82 -0
  50. package/jest.config.js +5 -0
  51. package/package.json +44 -0
  52. package/stylings.ts +311 -0
  53. package/svg-table-0.0.1-snapshot.tgz +0 -0
  54. package/tableData.test.ts +290 -0
  55. package/tableData.ts +359 -0
  56. package/tableFormatter.test.ts +122 -0
  57. package/tableFormatter.ts +306 -0
  58. package/tableStyler.test.ts +268 -0
  59. package/tableStyler.ts +798 -0
  60. package/tableSvg.ts +820 -0
  61. package/tableUtils.ts +20 -0
  62. package/tsconfig.json +102 -0
@@ -0,0 +1,665 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.TableStyler = exports.StyledTable = void 0;
15
+ var tableData_1 = require("./tableData");
16
+ var data_frame_ts_1 = require("data-frame-ts");
17
+ var result_fn_1 = require("result-fn");
18
+ var stylings_1 = require("./stylings");
19
+ /**
20
+ * Represents a table with applied styles.
21
+ * Provides methods to access the styling information for different parts of the table.
22
+ */
23
+ var StyledTable = /** @class */ (function () {
24
+ /**
25
+ * Creates a new StyledTable instance.
26
+ * @param dataFrame The data frame containing the table data
27
+ * @param font The font settings for the table
28
+ * @param border The border settings for the table
29
+ * @param background The background settings for the table
30
+ * @param dimension The dimension settings for the table
31
+ * @param padding The padding settings for the table
32
+ * @param margin The margin settings for the table
33
+ */
34
+ function StyledTable(dataFrame, font, border, background, dimension, padding, margin) {
35
+ this.dataFrame = dataFrame;
36
+ this.font = font;
37
+ this.border = border;
38
+ this.background = background;
39
+ this.dimension = dimension;
40
+ this.padding = padding;
41
+ this.margin = margin;
42
+ }
43
+ /**
44
+ * @return A copy of the {@link DataFrame} with all the styling and formatting tags
45
+ */
46
+ StyledTable.prototype.data = function () {
47
+ return this.dataFrame.copy();
48
+ };
49
+ StyledTable.prototype.tableData = function () {
50
+ // fromDataFrame makes a copy of the data frame
51
+ return tableData_1.TableData.fromDataFrame(this.dataFrame);
52
+ };
53
+ /**
54
+ * Returns the font settings for the table.
55
+ * @returns A copy of the table's font settings
56
+ */
57
+ StyledTable.prototype.tableFont = function () {
58
+ return __assign({}, this.font);
59
+ };
60
+ /**
61
+ * Returns the border settings for the table.
62
+ * @returns A copy of the table's border settings
63
+ */
64
+ StyledTable.prototype.tableBorder = function () {
65
+ return __assign({}, this.border);
66
+ };
67
+ /**
68
+ * Returns the background settings for the table.
69
+ * @returns A copy of the table's background settings
70
+ */
71
+ StyledTable.prototype.tableBackground = function () {
72
+ return __assign({}, this.background);
73
+ };
74
+ /**
75
+ * Returns the dimension settings for the table.
76
+ * @returns A copy of the table's dimension settings
77
+ */
78
+ StyledTable.prototype.tableDimensions = function () {
79
+ return __assign({}, this.dimension);
80
+ };
81
+ /**
82
+ * Returns the padding settings for the table.
83
+ * @returns A copy of the table's padding settings
84
+ */
85
+ StyledTable.prototype.tablePadding = function () {
86
+ return __assign({}, this.padding);
87
+ };
88
+ /**
89
+ * Returns the margin settings for the table.
90
+ * @returns A copy of the table's margin settings
91
+ */
92
+ StyledTable.prototype.tableMargin = function () {
93
+ return __assign({}, this.margin);
94
+ };
95
+ /**
96
+ * Retrieves styling tags for a specific column.
97
+ * @param columnIndex The index of the column
98
+ * @param tagStyleType The type of style tag to retrieve
99
+ * @returns A Result containing the tag if found, or an error message
100
+ * @private
101
+ */
102
+ StyledTable.prototype.columnTagsFor = function (columnIndex, tagStyleType) {
103
+ // find all the tags and type them to row-header tags
104
+ var tags = this.dataFrame
105
+ .columnTagsFor(columnIndex)
106
+ .filter(function (tag) { return tag.matchesId(tagStyleType, data_frame_ts_1.ColumnCoordinate.of(columnIndex)); })
107
+ .map(function (tag) { return tag; });
108
+ if (tags.length === 0) {
109
+ return (0, result_fn_1.failureResult)("(StyledTable::columnTagsFor) No matching column-style tags found for table; column_index: ".concat(columnIndex, "; tag_type: ").concat(tagStyleType));
110
+ }
111
+ // when there are more than one tag representing the row-header style, then sort based on priority and
112
+ // take the first one
113
+ if (tags.length > 1) {
114
+ tags.sort(function (tagA, tagB) { return tagB.value.priority - tagA.value.priority; });
115
+ }
116
+ return (0, result_fn_1.successResult)(tags[0]);
117
+ };
118
+ /**
119
+ * Retrieves styling tags for a specific row.
120
+ * @param rowIndex The index of the row
121
+ * @param tagStyleType The type of style tag to retrieve (can be more than one)
122
+ * @returns A Result containing the tag if found, or an error message
123
+ * @private
124
+ */
125
+ StyledTable.prototype.rowTagsFor = function (rowIndex) {
126
+ var tagStyleType = [];
127
+ for (var _i = 1; _i < arguments.length; _i++) {
128
+ tagStyleType[_i - 1] = arguments[_i];
129
+ }
130
+ // find all the tags and type them to column-header tags
131
+ var tags = this.dataFrame
132
+ .rowTagsFor(rowIndex)
133
+ .filter(function (tag) { return tagStyleType.filter(function (styleType) { return tag.matchesId(styleType, data_frame_ts_1.RowCoordinate.of(rowIndex)); }).length > 0; })
134
+ .map(function (tag) { return tag; });
135
+ if (tags.length === 0) {
136
+ return (0, result_fn_1.failureResult)("(StyledTable::rowTagsFor) No matching row-style tags found for table; row_index: ".concat(rowIndex, "; tag_type: ").concat(tagStyleType));
137
+ }
138
+ // when there are more than one tag representing the column-header, the sort based on the priority and
139
+ // take the first one
140
+ if (tags.length > 1) {
141
+ tags.sort(function (tagA, tagB) { return tagB.value.priority - tagA.value.priority; });
142
+ }
143
+ return (0, result_fn_1.successResult)(tags[0]);
144
+ };
145
+ StyledTable.prototype.hasRowHeader = function () {
146
+ return tableData_1.TableData.hasRowHeader(this.dataFrame);
147
+ };
148
+ StyledTable.prototype.hasColumnHeader = function () {
149
+ return tableData_1.TableData.hasColumnHeader(this.dataFrame);
150
+ };
151
+ StyledTable.prototype.hasFooter = function () {
152
+ return tableData_1.TableData.hasFooter(this.dataFrame);
153
+ };
154
+ /**
155
+ * Gets the style for the row header.
156
+ * @returns A Result containing the row header style if found, or an error message
157
+ */
158
+ StyledTable.prototype.rowHeaderStyle = function () {
159
+ if (!tableData_1.TableData.hasRowHeader(this.dataFrame)) {
160
+ return (0, result_fn_1.failureResult)("(StyledTable::rowHeaderStyle) The table data does not have a row header");
161
+ }
162
+ return this
163
+ .columnTagsFor(0, stylings_1.TableStyleType.ROW_HEADER)
164
+ .map(function (tag) { return tag.value; });
165
+ };
166
+ /**
167
+ * Gets the style for the column header.
168
+ * @returns A Result containing the column header style if found, or an error message
169
+ */
170
+ StyledTable.prototype.columnHeaderStyle = function () {
171
+ if (!tableData_1.TableData.hasColumnHeader(this.dataFrame)) {
172
+ return (0, result_fn_1.failureResult)("(StyledTable::columnHeaderStyle) The table data does not have a column header");
173
+ }
174
+ return this
175
+ .rowTagsFor(0, stylings_1.TableStyleType.COLUMN_HEADER)
176
+ .map(function (tag) { return tag.value; });
177
+ };
178
+ StyledTable.prototype.footerStyle = function () {
179
+ if (!tableData_1.TableData.hasFooter(this.dataFrame)) {
180
+ return (0, result_fn_1.failureResult)("(StyledTable::footerStyle) The table data does not have a footer");
181
+ }
182
+ return this
183
+ .rowTagsFor(this.dataFrame.rowCount() - 1, stylings_1.TableStyleType.FOOTER)
184
+ .map(function (tag) { return tag.value; });
185
+ };
186
+ /**
187
+ * Gets the style for a specific row.
188
+ * @param rowIndex The index of the row
189
+ * @returns A Result containing the row style if found, or an error message
190
+ */
191
+ StyledTable.prototype.rowStyleFor = function (rowIndex) {
192
+ return this
193
+ .rowTagsFor(rowIndex, stylings_1.TableStyleType.ROW)
194
+ .map(function (tag) { return tag.value; });
195
+ };
196
+ /**
197
+ * Gets the style for a specific column.
198
+ * @param columnIndex The index of the column
199
+ * @returns A Result containing the column style if found, or an error message
200
+ */
201
+ StyledTable.prototype.columnStyleFor = function (columnIndex) {
202
+ return this
203
+ .columnTagsFor(columnIndex, stylings_1.TableStyleType.COLUMN)
204
+ .map(function (tag) { return tag.value; });
205
+ };
206
+ /**
207
+ * Gets the style for a specific cell.
208
+ * @param rowIndex The row index of the cell
209
+ * @param columnIndex The column index of the cell
210
+ * @returns A Result containing the cell style if found, or an error message
211
+ */
212
+ StyledTable.prototype.cellStyleFor = function (rowIndex, columnIndex) {
213
+ // find all the tags and type them to column-header tags
214
+ var tags = this.dataFrame
215
+ .cellTagsFor(rowIndex, columnIndex)
216
+ .filter(function (tag) { return tag.matchesId(stylings_1.TableStyleType.CELL, data_frame_ts_1.CellCoordinate.of(rowIndex, columnIndex)); })
217
+ .map(function (tag) { return tag; });
218
+ if (tags.length === 0) {
219
+ return (0, result_fn_1.failureResult)("(StyledTable::cellStyleFor) No matching cell-style tags found for table; row_index: ".concat(rowIndex, "; column_index: ").concat(columnIndex));
220
+ }
221
+ // when there are more than one tag representing the column-header, the sort based on the priority and
222
+ // take the first one
223
+ if (tags.length > 1) {
224
+ tags.sort(function (tagA, tagB) { return tagB.value.priority - tagA.value.priority; });
225
+ }
226
+ return (0, result_fn_1.successResult)(tags[0].value);
227
+ };
228
+ /**
229
+ * Unlike the methods that retrieve the particular styles, say for a cell, a column header,
230
+ * and so forth, this method returns a {@link CellStyle} calculated from all the styles
231
+ * that apply to the specified cell by using the style properties with the highest priority.
232
+ * <p>
233
+ * Retrieves the styles to be applied to a specific data cell in the table. This method
234
+ * accounts for column headers, row headers, and footers. For example, regardless of whether the
235
+ * table has a column header, a row index of 0 refers to the first row of data. And
236
+ * regardless of whether the table has a row header, a column index of 0 refers to the
237
+ * first column of data.
238
+ *
239
+ * @param rowIndex - The index of the row in the table data for which styles are required.
240
+ * Must be within the valid row index range.
241
+ * @param columnIndex - The index of the column in the table data for which styles are required.
242
+ * Must be within the valid column index range.
243
+ * @return A result object containing the cell style if the indices are valid, or an error
244
+ * message if they are not.
245
+ */
246
+ StyledTable.prototype.stylesForDataCoordinates = function (rowIndex, columnIndex) {
247
+ if (rowIndex < 0 || rowIndex >= tableData_1.TableData.dataRowCount(this.dataFrame) ||
248
+ columnIndex < 0 || columnIndex >= tableData_1.TableData.dataColumnCount(this.dataFrame)) {
249
+ return (0, result_fn_1.failureResult)("(StyledTable::dataCellStyles) Invalid row and/or column index for data; row_index".concat(rowIndex) +
250
+ "; column_index: ".concat(columnIndex) +
251
+ "; valid_row_index: [0, ".concat(tableData_1.TableData.dataRowCount(this.dataFrame), ")") +
252
+ "; valid_column_index: [0, ".concat(tableData_1.TableData.dataColumnCount(this.dataFrame), ")") +
253
+ "; has_column_header: ".concat(tableData_1.TableData.hasColumnHeader(this.dataFrame)) +
254
+ "; has_row_header: ".concat(tableData_1.TableData.hasRowHeader(this.dataFrame)) +
255
+ "; has_footer: ".concat(tableData_1.TableData.hasFooter(this.dataFrame)));
256
+ }
257
+ var columnHeaderOffset = tableData_1.TableData.hasColumnHeader(this.dataFrame) ? 1 : 0;
258
+ var rowHeaderOffset = tableData_1.TableData.hasRowHeader(this.dataFrame) ? 1 : 0;
259
+ return this.stylesForTableCoordinates(rowIndex + columnHeaderOffset, columnIndex + rowHeaderOffset);
260
+ };
261
+ /**
262
+ * Unlike the methods that retrieve the particular styles, say for a cell, a column header,
263
+ * and so forth, this method returns a {@link CellStyle} calculated from all the styles
264
+ * that apply to the specified cell by using the style properties with the highest priority.
265
+ * <p>
266
+ * Calculates the style for the cell based on the styles applied to the table and their
267
+ * relative priority. The row and column indexes refer to the entire table and do not account
268
+ * for column headers, row headers, or footers.
269
+ * @param rowIndex The index of the row in the entire table. For example, if the table has column
270
+ * headers, then a rowIndex of 0 would be that column header.
271
+ * @param columnIndex The index of the column in the entire table. For example, if the table has
272
+ * row headers, then a column index of 0 would be the row header
273
+ * @return A {@link Result} holding the {@link CellStyle}; or a failure {@link Result} if the
274
+ * row or column indexes are out of range.
275
+ * @see stylesForDataCoordinates
276
+ */
277
+ StyledTable.prototype.stylesForTableCoordinates = function (rowIndex, columnIndex) {
278
+ if (rowIndex < 0 || rowIndex >= this.dataFrame.rowCount() || columnIndex < 0 || columnIndex >= this.dataFrame.columnCount()) {
279
+ return (0, result_fn_1.failureResult)("(StyledTable::stylesFor) Invalid row and/or column index" +
280
+ "; row_index: ".concat(rowIndex) +
281
+ "; column_index: ".concat(columnIndex) +
282
+ "; valid_row_index: [0, ".concat(this.dataFrame.rowCount(), ")") +
283
+ "; valid_column_index: [0, ".concat(this.dataFrame.columnCount(), ")"));
284
+ }
285
+ //
286
+ // determine what styles may be available
287
+ var availableStyling = [];
288
+ if (rowIndex === 0) {
289
+ this.columnHeaderStyle().onSuccess(function (styling) { return availableStyling.push(styling); });
290
+ }
291
+ if (columnIndex === 0) {
292
+ this.rowHeaderStyle().onSuccess(function (styling) { return availableStyling.push(styling); });
293
+ }
294
+ if (rowIndex === this.dataFrame.rowCount() - 1) {
295
+ this.footerStyle().onSuccess(function (styling) { return availableStyling.push(styling); });
296
+ }
297
+ this.rowStyleFor(rowIndex).onSuccess(function (styling) { return availableStyling.push(styling); });
298
+ this.columnStyleFor(columnIndex).onSuccess(function (styling) { return availableStyling.push(styling); });
299
+ // the cell style is handled differently when it doesn't exist because we need a default set of
300
+ // values for the cell style in case not all properties are found in the available styles
301
+ this.cellStyleFor(rowIndex, columnIndex)
302
+ .onSuccess(function (styling) { return availableStyling.push(styling); })
303
+ .onFailure(function () { return availableStyling.push({ style: stylings_1.defaultCellStyle, priority: -1 }); });
304
+ //
305
+ // calculate the style for the cell based on the priorities and available styles
306
+ var cellStyle = availableStyling
307
+ .sort(function (stylingA, stylingB) { return stylingA.priority - stylingB.priority; })
308
+ .reduce(function (style, curr) { return ({
309
+ font: (curr.style.hasOwnProperty('font') ?
310
+ // @ts-ignore
311
+ __assign(__assign({}, style.font), curr.style.font) : (style.hasOwnProperty('font') ? __assign({}, style.font) : stylings_1.defaultTableFont)),
312
+ alignText: (curr.style.hasOwnProperty('alignText') ?
313
+ // @ts-ignore
314
+ curr.style.alignText : (style.hasOwnProperty('alignText') ? style.alignText : stylings_1.defaultColumnStyle.alignText)),
315
+ verticalAlignText: (curr.style.hasOwnProperty('verticalAlignText') ?
316
+ // @ts-ignore
317
+ curr.style.verticalAlignText : (style.hasOwnProperty('verticalAlignText') ? style.verticalAlignText : stylings_1.defaultColumnStyle.verticalAlignText)),
318
+ background: (curr.style.hasOwnProperty('background') ?
319
+ // @ts-ignore
320
+ __assign(__assign({}, style.background), curr.style.background) : (style.hasOwnProperty('background') ? style.background : stylings_1.defaultTableBackground)),
321
+ dimension: (curr.style.hasOwnProperty('dimension') ?
322
+ // @ts-ignore
323
+ __assign(__assign({}, style.dimension), curr.style.dimension) : (style.hasOwnProperty('dimension') ? __assign({}, style.dimension) : stylings_1.defaultDimension)),
324
+ padding: (curr.style.hasOwnProperty('padding') ?
325
+ // @ts-ignore
326
+ __assign(__assign({}, style.padding), curr.style.padding) : (style.hasOwnProperty('padding') ? __assign({}, style.padding) : stylings_1.defaultTablePadding)),
327
+ border: (curr.style.hasOwnProperty('border') ?
328
+ // @ts-ignore
329
+ __assign(__assign({}, style.border), curr.style.border) : (style.hasOwnProperty('border') ? __assign({}, style.border) : stylings_1.defaultBorder)),
330
+ }); }, stylings_1.defaultCellStyle);
331
+ return (0, result_fn_1.successResult)(cellStyle);
332
+ };
333
+ return StyledTable;
334
+ }());
335
+ exports.StyledTable = StyledTable;
336
+ /**
337
+ * Builder class for creating styled tables.
338
+ * Provides methods to configure various styling aspects of a table.
339
+ */
340
+ var TableStyler = /** @class */ (function () {
341
+ /**
342
+ * Private constructor to enforce factory method usage.
343
+ * @param dataFrame The data frame containing the table data
344
+ * @param font The font settings for the table
345
+ * @param border The border settings for the table
346
+ * @param background The background settings for the table
347
+ * @param dimension The dimension settings for the table
348
+ * @param padding The padding settings for the table
349
+ * @param margin The margin settings for the table
350
+ * @param errors Array to collect error messages during styling operations
351
+ */
352
+ function TableStyler(dataFrame, font, border, background, dimension, padding, margin, errors) {
353
+ if (font === void 0) { font = stylings_1.defaultTableFont; }
354
+ if (border === void 0) { border = stylings_1.defaultBorder; }
355
+ if (background === void 0) { background = stylings_1.defaultTableBackground; }
356
+ if (dimension === void 0) { dimension = { width: NaN, height: NaN }; }
357
+ if (padding === void 0) { padding = stylings_1.defaultTablePadding; }
358
+ if (margin === void 0) { margin = stylings_1.defaultTableMargin; }
359
+ if (errors === void 0) { errors = []; }
360
+ this.dataFrame = dataFrame;
361
+ this.font = font;
362
+ this.border = border;
363
+ this.background = background;
364
+ this.dimension = dimension;
365
+ this.padding = padding;
366
+ this.margin = margin;
367
+ this.errors = errors;
368
+ }
369
+ /**
370
+ * Creates a TableStyler from a TableData object.
371
+ * @param tableData The TableData object to style
372
+ * @returns A new TableStyler instance
373
+ */
374
+ TableStyler.fromTableData = function (tableData) {
375
+ return new TableStyler(tableData.unwrapDataFrame());
376
+ };
377
+ /**
378
+ * Creates a TableStyler from a DataFrame object.
379
+ * @param dataFrame The DataFrame object to style
380
+ * @returns A new TableStyler instance
381
+ */
382
+ TableStyler.fromDataFrame = function (dataFrame) {
383
+ return new TableStyler(dataFrame.copy());
384
+ };
385
+ /**
386
+ * Creates a copy of this TableStyler instance.
387
+ * @returns A new TableStyler instance with the same properties
388
+ */
389
+ TableStyler.prototype.copy = function () {
390
+ return new TableStyler(this.dataFrame, this.font, this.border, this.background, this.dimension, this.padding, this.margin, this.errors);
391
+ };
392
+ /**
393
+ * Creates a new TableStyler with updated properties.
394
+ * @param properties Partial properties to update
395
+ * @returns A new TableStyler instance with updated properties
396
+ */
397
+ TableStyler.prototype.update = function (properties) {
398
+ var _a = properties.dataFrame, dataFrame = _a === void 0 ? this.dataFrame : _a, _b = properties.font, font = _b === void 0 ? this.font : _b, _c = properties.border, border = _c === void 0 ? this.border : _c, _d = properties.background, background = _d === void 0 ? this.background : _d, _e = properties.dimension, dimension = _e === void 0 ? this.dimension : _e, _f = properties.padding, padding = _f === void 0 ? this.padding : _f, _g = properties.margin, margin = _g === void 0 ? this.margin : _g;
399
+ return new TableStyler(dataFrame, font, border, background, dimension, padding, margin, this.errors);
400
+ };
401
+ TableStyler.prototype.withTableFont = function (font) {
402
+ var builder = this.copy();
403
+ builder.font = __assign(__assign({}, stylings_1.defaultTableFont), font);
404
+ return builder;
405
+ };
406
+ /**
407
+ * Sets the background for the table.
408
+ * @param background The background settings to apply
409
+ * @returns A new TableStyler instance with the updated background
410
+ */
411
+ TableStyler.prototype.withTableBackground = function (background) {
412
+ var builder = this.copy();
413
+ builder.background = __assign(__assign({}, builder.background), background);
414
+ return builder;
415
+ };
416
+ /**
417
+ * Sets the border for the table.
418
+ * @param border The border settings to apply
419
+ * @returns A new TableStyler instance with the updated border
420
+ */
421
+ TableStyler.prototype.withBorder = function (border) {
422
+ var builder = this.copy();
423
+ builder.border = __assign(__assign({}, builder.border), border);
424
+ return builder;
425
+ };
426
+ /**
427
+ * Sets the dimensions for the table.
428
+ * @param width The width of the table
429
+ * @param height The height of the table
430
+ * @returns A new TableStyler instance with the updated dimensions
431
+ */
432
+ TableStyler.prototype.withDimensions = function (width, height) {
433
+ var builder = this.copy();
434
+ builder.dimension = { width: width, height: height };
435
+ return builder;
436
+ };
437
+ /**
438
+ * Sets the padding for the table.
439
+ * @param padding The padding settings to apply
440
+ * @returns A new TableStyler instance with the updated padding
441
+ */
442
+ TableStyler.prototype.withPadding = function (padding) {
443
+ var builder = this.copy();
444
+ builder.padding = __assign(__assign({}, builder.padding), padding);
445
+ return builder;
446
+ };
447
+ /**
448
+ * Sets the margin for the table.
449
+ * @param margin The margin settings to apply
450
+ * @returns A new TableStyler instance with the updated margin
451
+ */
452
+ TableStyler.prototype.withMargin = function (margin) {
453
+ var builder = this.copy();
454
+ builder.margin = __assign(__assign({}, builder.margin), margin);
455
+ return builder;
456
+ };
457
+ /**
458
+ * Tags a row with a style.
459
+ * @param rowIndex The index of the row to tag
460
+ * @param tagStyleType The type of style to apply
461
+ * @param style The style value to apply
462
+ * @returns A Result containing a new TableStyler with the tagged row, or an error message
463
+ * @private
464
+ */
465
+ TableStyler.prototype.tagRow = function (rowIndex, tagStyleType, style) {
466
+ var _this = this;
467
+ return this.dataFrame.tagRow(rowIndex, tagStyleType, style)
468
+ // when successfully tagged, make an updated copy of this builder with the new data-frame
469
+ .map(function (df) { return _this.update({ dataFrame: df }); })
470
+ // when failed to tag, add to the errors
471
+ .onFailure(function (error) { return _this.errors.push(error); });
472
+ };
473
+ /**
474
+ * Tags a column with a style.
475
+ * @param columnIndex The index of the column to tag
476
+ * @param tagStyleType The type of style to apply
477
+ * @param style The style value to apply
478
+ * @returns A Result containing a new TableStyler with the tagged column, or an error message
479
+ * @private
480
+ */
481
+ TableStyler.prototype.tagColumn = function (columnIndex, tagStyleType, style) {
482
+ var _this = this;
483
+ return this.dataFrame.tagColumn(columnIndex, tagStyleType, style)
484
+ // when successfully tagged, make an updated copy of this builder with the new data-frame
485
+ .map(function (df) { return _this.update({ dataFrame: df }); })
486
+ // when failed to tag, add to the errors
487
+ .onFailure(function (error) { return _this.errors.push(error); });
488
+ };
489
+ /**
490
+ * Sets the style for the column header row.
491
+ * @param columnHeaderStyle The style to apply to the column header. Style properties that are not specified
492
+ * will be set to their default values.
493
+ * @param priority The priority of this style (higher values take precedence)
494
+ * @returns A new TableStyler instance with the column header style applied
495
+ */
496
+ TableStyler.prototype.withColumnHeaderStyle = function (columnHeaderStyle, priority) {
497
+ if (columnHeaderStyle === void 0) { columnHeaderStyle = stylings_1.defaultColumnHeaderStyle; }
498
+ if (priority === void 0) { priority = Infinity; }
499
+ if (!tableData_1.TableData.hasColumnHeader(this.dataFrame)) {
500
+ this.errors.push("The column header style can only be supplied when the table data has a column header");
501
+ return this;
502
+ }
503
+ // tag the row as a column header style, and if it fails, then return this (unmodified) builder
504
+ return this
505
+ .tagRow(0, stylings_1.TableStyleType.COLUMN_HEADER, (0, stylings_1.stylingFor)(columnHeaderStyle, stylings_1.defaultColumnHeaderStyle, priority))
506
+ .getOrElse(this);
507
+ };
508
+ /**
509
+ * Sets the style for the row header column.
510
+ * @param rowHeaderStyle The style to apply to the row header. Style properties that are not specified
511
+ * will be set to their default values.
512
+ * @param priority The priority of this style (higher values take precedence)
513
+ * @returns A new TableStyler instance with the row header style applied
514
+ */
515
+ TableStyler.prototype.withRowHeaderStyle = function (rowHeaderStyle, priority) {
516
+ if (priority === void 0) { priority = Infinity; }
517
+ if (!tableData_1.TableData.hasRowHeader(this.dataFrame)) {
518
+ this.errors.push("The row header style can only be supplied when the table data has row headers");
519
+ return this;
520
+ }
521
+ // tag the column with the row header style, and if it fails, then return this (unmodified) builder
522
+ return this
523
+ .tagColumn(0, stylings_1.TableStyleType.ROW_HEADER, (0, stylings_1.stylingFor)(rowHeaderStyle, stylings_1.defaultRowHeaderStyle, priority))
524
+ .getOrElse(this);
525
+ };
526
+ /**
527
+ * Sets the style for the footer row.
528
+ * @param footerStyle The style to apply to the footer. Style properties that are not specified
529
+ * will be set to their default values.
530
+ * @param priority The priority of this style (higher values take precedence)
531
+ * @returns A new TableStyler instance with the footer style applied
532
+ */
533
+ TableStyler.prototype.withFooterStyle = function (footerStyle, priority) {
534
+ if (priority === void 0) { priority = Infinity; }
535
+ if (!tableData_1.TableData.hasFooter(this.dataFrame)) {
536
+ this.errors.push("The footer style can only be supplied when the table data has a footer");
537
+ return this;
538
+ }
539
+ // tag the row the footer style, and if it fails, then return this (unmodified) builder
540
+ var footerIndex = tableData_1.TableData.tableRowCount(this.dataFrame) - 1;
541
+ return this
542
+ .tagRow(footerIndex, stylings_1.TableStyleType.FOOTER, (0, stylings_1.stylingFor)(footerStyle, stylings_1.defaultFooterStyle, priority))
543
+ .getOrElse(this);
544
+ };
545
+ /**
546
+ * Sets the style for a specific row.
547
+ * @param rowIndex The index of the row to style
548
+ * @param rowStyle The style to apply to the row. Style properties that are not specified
549
+ * will be set to their default values.
550
+ * @param priority The priority of this style (higher values take precedence)
551
+ * @returns A new TableStyler instance with the row style applied
552
+ */
553
+ TableStyler.prototype.withRowStyle = function (rowIndex, rowStyle, priority) {
554
+ if (priority === void 0) { priority = 0; }
555
+ if (rowIndex < 0 || rowIndex >= tableData_1.TableData.tableRowCount(this.dataFrame)) {
556
+ this.errors.push("The row index, when setting a row-style, must be between 0 and ".concat(tableData_1.TableData.tableRowCount(this.dataFrame) - 1));
557
+ return this;
558
+ }
559
+ // tag the row with a style, and if it fails, then return this (unmodified) builder
560
+ return this
561
+ .tagRow(rowIndex, stylings_1.TableStyleType.ROW, (0, stylings_1.stylingFor)(rowStyle, stylings_1.defaultRowStyle, priority))
562
+ .getOrElse(this);
563
+ };
564
+ TableStyler.prototype.withRowStyles = function (rowIndexes, rowStyle, priority) {
565
+ if (priority === void 0) { priority = 0; }
566
+ var indexes = rowIndexes.length > 0 ? rowIndexes : new Array(this.dataFrame.rowCount()).fill(0).map(function (_, i) { return i; });
567
+ return TableStyler.withRowStyles(this, indexes, rowStyle, priority);
568
+ };
569
+ TableStyler.withRowStyles = function (tableStyler, rowIndexes, rowStyle, priority) {
570
+ if (priority === void 0) { priority = 0; }
571
+ if (rowIndexes.length > 0) {
572
+ var rowIndex = rowIndexes.shift();
573
+ if (rowIndex != null) {
574
+ var styler = tableStyler.withRowStyle(rowIndex, rowStyle, priority);
575
+ return TableStyler.withRowStyles(styler, rowIndexes, rowStyle, priority);
576
+ }
577
+ }
578
+ return tableStyler;
579
+ };
580
+ /**
581
+ * Sets the style for a specific column.
582
+ * @param columnIndex The index of the column to style
583
+ * @param columnStyle The style to apply to the column. Style properties that are not specified
584
+ * will be set to their default values.
585
+ * @param priority The priority of this style (higher values take precedence)
586
+ * @returns A new TableStyler instance with the column style applied
587
+ */
588
+ TableStyler.prototype.withColumnStyle = function (columnIndex, columnStyle, priority) {
589
+ if (priority === void 0) { priority = 0; }
590
+ if (columnIndex < 0 || columnIndex >= tableData_1.TableData.tableColumnCount(this.dataFrame)) {
591
+ this.errors.push("The column index, when setting a column-style, must be between 0 and ".concat(tableData_1.TableData.tableColumnCount(this.dataFrame) - 1));
592
+ return this;
593
+ }
594
+ // tag the row with a style, and if it fails, then return this (unmodified) builder
595
+ return this
596
+ .tagColumn(columnIndex, stylings_1.TableStyleType.COLUMN, (0, stylings_1.stylingFor)(columnStyle, stylings_1.defaultColumnStyle, priority))
597
+ .getOrElse(this);
598
+ };
599
+ TableStyler.prototype.withColumnStyles = function (columnIndexes, columnStyle, priority) {
600
+ if (priority === void 0) { priority = 0; }
601
+ var indexes = columnIndexes.length > 0 ? columnIndexes : new Array(this.dataFrame.columnCount()).fill(0).map(function (_, i) { return i; });
602
+ return TableStyler.withColumnStyles(this, indexes, columnStyle, priority);
603
+ };
604
+ TableStyler.withColumnStyles = function (tableStyler, columnIndexes, columnStyle, priority) {
605
+ if (priority === void 0) { priority = 0; }
606
+ if (columnIndexes.length > 0) {
607
+ var columnIndex = columnIndexes.shift();
608
+ if (columnIndex != null) {
609
+ var styler = tableStyler.withColumnStyle(columnIndex, columnStyle, priority);
610
+ return TableStyler.withColumnStyles(styler, columnIndexes, columnStyle, priority);
611
+ }
612
+ }
613
+ return tableStyler;
614
+ };
615
+ /**
616
+ * Sets the style for a specific cell.
617
+ * @param rowIndex The row index of the cell to style
618
+ * @param columnIndex The column index of the cell to style
619
+ * @param cellStyle The style to apply to the cell. Style properties that are not specified
620
+ * will be set to their default values.
621
+ * @param priority The priority of this style (higher values take precedence)
622
+ * @returns A new TableStyler instance with the cell style applied
623
+ */
624
+ TableStyler.prototype.withCellStyle = function (rowIndex, columnIndex, cellStyle, priority) {
625
+ var _this = this;
626
+ if (priority === void 0) { priority = 0; }
627
+ if (rowIndex < 0 || rowIndex >= tableData_1.TableData.tableRowCount(this.dataFrame) ||
628
+ columnIndex < 0 || columnIndex >= tableData_1.TableData.tableColumnCount(this.dataFrame)) {
629
+ this.errors.push("The (row, column) indices, when setting a cell-style, must be in " +
630
+ "([0, ".concat(tableData_1.TableData.tableRowCount(this.dataFrame), "), [0, ").concat(tableData_1.TableData.tableColumnCount(this.dataFrame), "))"));
631
+ return this;
632
+ }
633
+ // tag the cell with the cell-style
634
+ return this.dataFrame
635
+ .tagCell(rowIndex, columnIndex, stylings_1.TableStyleType.CELL, (0, stylings_1.stylingFor)(cellStyle, stylings_1.defaultCellStyle, priority))
636
+ // when successfully tagged, make an updated copy of this builder with the new data-frame
637
+ .map(function (df) { return _this.update({ dataFrame: df }); })
638
+ // when failed to tag, add to the errors
639
+ .onFailure(function (error) { return _this.errors.push(error); })
640
+ // when failed, return this (unmodified) builder
641
+ .getOrElse(this);
642
+ };
643
+ TableStyler.prototype.withCellStyleWhen = function (predicate, cellStyle, priority) {
644
+ var _this = this;
645
+ if (priority === void 0) { priority = 0; }
646
+ return this.dataFrame
647
+ .tagCellWhen(predicate, stylings_1.TableStyleType.CELL, (0, stylings_1.stylingFor)(cellStyle, stylings_1.defaultCellStyle, priority))
648
+ // when successfully tagged, make an updated copy of this builder with the new data-frame
649
+ .map(function (df) { return _this.update({ dataFrame: df }); })
650
+ // when failed to tag, add to the errors
651
+ .onFailure(function (error) { return _this.errors.push(error); })
652
+ // when failed, return this (unmodified) builder
653
+ .getOrElse(this);
654
+ };
655
+ /**
656
+ * Finalizes the styling process and creates a StyledTable instance.
657
+ * @returns A StyledTable instance with all the applied styles
658
+ */
659
+ TableStyler.prototype.styleTable = function () {
660
+ return new StyledTable(this.dataFrame, this.font, this.border, this.background, this.dimension, this.padding, this.margin);
661
+ };
662
+ return TableStyler;
663
+ }());
664
+ exports.TableStyler = TableStyler;
665
+ //# sourceMappingURL=tableStyler.js.map