@pdfme/schemas 3.2.3-dev.1 → 4.0.0-alpha.0

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 (138) hide show
  1. package/dist/cjs/__tests__/text.test.js +5 -4
  2. package/dist/cjs/__tests__/text.test.js.map +1 -1
  3. package/dist/cjs/__tests__/utils.test.js +3 -0
  4. package/dist/cjs/__tests__/utils.test.js.map +1 -1
  5. package/dist/cjs/src/barcodes/propPanel.js +11 -11
  6. package/dist/cjs/src/barcodes/propPanel.js.map +1 -1
  7. package/dist/cjs/src/barcodes/uiRender.js +1 -1
  8. package/dist/cjs/src/barcodes/uiRender.js.map +1 -1
  9. package/dist/cjs/src/graphics/image.js +5 -11
  10. package/dist/cjs/src/graphics/image.js.map +1 -1
  11. package/dist/cjs/src/graphics/svg.js +2 -3
  12. package/dist/cjs/src/graphics/svg.js.map +1 -1
  13. package/dist/cjs/src/index.js +6 -1
  14. package/dist/cjs/src/index.js.map +1 -1
  15. package/dist/cjs/src/shapes/line.js +5 -9
  16. package/dist/cjs/src/shapes/line.js.map +1 -1
  17. package/dist/cjs/src/shapes/rectAndEllipse.js +3 -2
  18. package/dist/cjs/src/shapes/rectAndEllipse.js.map +1 -1
  19. package/dist/cjs/src/tables/cell.js +125 -0
  20. package/dist/cjs/src/tables/cell.js.map +1 -0
  21. package/dist/cjs/src/tables/classes.js +467 -0
  22. package/dist/cjs/src/tables/classes.js.map +1 -0
  23. package/dist/cjs/src/tables/dynamicTemplate.js +71 -0
  24. package/dist/cjs/src/tables/dynamicTemplate.js.map +1 -0
  25. package/dist/cjs/src/tables/helper.js +171 -0
  26. package/dist/cjs/src/tables/helper.js.map +1 -0
  27. package/dist/cjs/src/tables/index.js +12 -0
  28. package/dist/cjs/src/tables/index.js.map +1 -0
  29. package/dist/cjs/src/tables/pdfRender.js +95 -0
  30. package/dist/cjs/src/tables/pdfRender.js.map +1 -0
  31. package/dist/cjs/src/tables/propPanel.js +87 -0
  32. package/dist/cjs/src/tables/propPanel.js.map +1 -0
  33. package/dist/cjs/src/tables/tableHelper.js +231 -0
  34. package/dist/cjs/src/tables/tableHelper.js.map +1 -0
  35. package/dist/cjs/src/tables/types.js +3 -0
  36. package/dist/cjs/src/tables/types.js.map +1 -0
  37. package/dist/cjs/src/tables/uiRender.js +321 -0
  38. package/dist/cjs/src/tables/uiRender.js.map +1 -0
  39. package/dist/cjs/src/text/helper.js +21 -6
  40. package/dist/cjs/src/text/helper.js.map +1 -1
  41. package/dist/cjs/src/text/index.js +0 -1
  42. package/dist/cjs/src/text/index.js.map +1 -1
  43. package/dist/cjs/src/text/pdfRender.js +5 -8
  44. package/dist/cjs/src/text/pdfRender.js.map +1 -1
  45. package/dist/cjs/src/text/propPanel.js +6 -4
  46. package/dist/cjs/src/text/propPanel.js.map +1 -1
  47. package/dist/cjs/src/text/uiRender.js +18 -17
  48. package/dist/cjs/src/text/uiRender.js.map +1 -1
  49. package/dist/cjs/src/utils.js +9 -1
  50. package/dist/cjs/src/utils.js.map +1 -1
  51. package/dist/esm/__tests__/text.test.js +5 -4
  52. package/dist/esm/__tests__/text.test.js.map +1 -1
  53. package/dist/esm/__tests__/utils.test.js +3 -0
  54. package/dist/esm/__tests__/utils.test.js.map +1 -1
  55. package/dist/esm/src/barcodes/propPanel.js +11 -11
  56. package/dist/esm/src/barcodes/propPanel.js.map +1 -1
  57. package/dist/esm/src/barcodes/uiRender.js +1 -1
  58. package/dist/esm/src/barcodes/uiRender.js.map +1 -1
  59. package/dist/esm/src/graphics/image.js +4 -10
  60. package/dist/esm/src/graphics/image.js.map +1 -1
  61. package/dist/esm/src/graphics/svg.js +2 -3
  62. package/dist/esm/src/graphics/svg.js.map +1 -1
  63. package/dist/esm/src/index.js +3 -1
  64. package/dist/esm/src/index.js.map +1 -1
  65. package/dist/esm/src/shapes/line.js +5 -9
  66. package/dist/esm/src/shapes/line.js.map +1 -1
  67. package/dist/esm/src/shapes/rectAndEllipse.js +3 -2
  68. package/dist/esm/src/shapes/rectAndEllipse.js.map +1 -1
  69. package/dist/esm/src/tables/cell.js +120 -0
  70. package/dist/esm/src/tables/cell.js.map +1 -0
  71. package/dist/esm/src/tables/classes.js +460 -0
  72. package/dist/esm/src/tables/classes.js.map +1 -0
  73. package/dist/esm/src/tables/dynamicTemplate.js +66 -0
  74. package/dist/esm/src/tables/dynamicTemplate.js.map +1 -0
  75. package/dist/esm/src/tables/helper.js +163 -0
  76. package/dist/esm/src/tables/helper.js.map +1 -0
  77. package/dist/esm/src/tables/index.js +10 -0
  78. package/dist/esm/src/tables/index.js.map +1 -0
  79. package/dist/esm/src/tables/pdfRender.js +88 -0
  80. package/dist/esm/src/tables/pdfRender.js.map +1 -0
  81. package/dist/esm/src/tables/propPanel.js +84 -0
  82. package/dist/esm/src/tables/propPanel.js.map +1 -0
  83. package/dist/esm/src/tables/tableHelper.js +226 -0
  84. package/dist/esm/src/tables/tableHelper.js.map +1 -0
  85. package/dist/esm/src/tables/types.js +2 -0
  86. package/dist/esm/src/tables/types.js.map +1 -0
  87. package/dist/esm/src/tables/uiRender.js +314 -0
  88. package/dist/esm/src/tables/uiRender.js.map +1 -0
  89. package/dist/esm/src/text/helper.js +19 -5
  90. package/dist/esm/src/text/helper.js.map +1 -1
  91. package/dist/esm/src/text/index.js +0 -1
  92. package/dist/esm/src/text/index.js.map +1 -1
  93. package/dist/esm/src/text/pdfRender.js +6 -9
  94. package/dist/esm/src/text/pdfRender.js.map +1 -1
  95. package/dist/esm/src/text/propPanel.js +6 -4
  96. package/dist/esm/src/text/propPanel.js.map +1 -1
  97. package/dist/esm/src/text/uiRender.js +19 -18
  98. package/dist/esm/src/text/uiRender.js.map +1 -1
  99. package/dist/esm/src/utils.js +6 -0
  100. package/dist/esm/src/utils.js.map +1 -1
  101. package/dist/types/src/index.d.ts +3 -1
  102. package/dist/types/src/shapes/rectAndEllipse.d.ts +13 -27
  103. package/dist/types/src/tables/cell.d.ts +4 -0
  104. package/dist/types/src/tables/classes.d.ts +68 -0
  105. package/dist/types/src/tables/dynamicTemplate.d.ts +13 -0
  106. package/dist/types/src/tables/helper.d.ts +252 -0
  107. package/dist/types/src/tables/index.d.ts +4 -0
  108. package/dist/types/src/tables/pdfRender.d.ts +3 -0
  109. package/dist/types/src/tables/propPanel.d.ts +3 -0
  110. package/dist/types/src/tables/tableHelper.d.ts +11 -0
  111. package/dist/types/src/tables/types.d.ts +91 -0
  112. package/dist/types/src/tables/uiRender.d.ts +3 -0
  113. package/dist/types/src/text/helper.d.ts +8 -1
  114. package/dist/types/src/utils.d.ts +2 -0
  115. package/package.json +1 -1
  116. package/src/barcodes/propPanel.ts +12 -12
  117. package/src/barcodes/uiRender.ts +1 -1
  118. package/src/graphics/image.ts +6 -11
  119. package/src/graphics/svg.ts +2 -3
  120. package/src/index.ts +5 -0
  121. package/src/shapes/line.ts +4 -9
  122. package/src/shapes/rectAndEllipse.ts +4 -4
  123. package/src/tables/cell.ts +157 -0
  124. package/src/tables/classes.ts +398 -0
  125. package/src/tables/dynamicTemplate.ts +81 -0
  126. package/src/tables/helper.ts +198 -0
  127. package/src/tables/index.ts +12 -0
  128. package/src/tables/pdfRender.ts +115 -0
  129. package/src/tables/propPanel.ts +90 -0
  130. package/src/tables/tableHelper.ts +322 -0
  131. package/src/tables/types.ts +88 -0
  132. package/src/tables/uiRender.ts +362 -0
  133. package/src/text/helper.ts +30 -6
  134. package/src/text/index.ts +0 -1
  135. package/src/text/pdfRender.ts +7 -11
  136. package/src/text/propPanel.ts +6 -4
  137. package/src/text/uiRender.ts +18 -18
  138. package/src/utils.ts +8 -0
@@ -0,0 +1,460 @@
1
+ import { mm2pt, pt2mm } from '@pdfme/common';
2
+ import { splitTextToSize, getFontKitFont, widthOfTextAtSize } from '../text/helper';
3
+ export class Cell {
4
+ constructor(raw, styles, section) {
5
+ Object.defineProperty(this, "raw", {
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true,
9
+ value: void 0
10
+ });
11
+ Object.defineProperty(this, "text", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ Object.defineProperty(this, "styles", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "section", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: void 0
28
+ });
29
+ Object.defineProperty(this, "contentHeight", {
30
+ enumerable: true,
31
+ configurable: true,
32
+ writable: true,
33
+ value: 0
34
+ });
35
+ Object.defineProperty(this, "contentWidth", {
36
+ enumerable: true,
37
+ configurable: true,
38
+ writable: true,
39
+ value: 0
40
+ });
41
+ Object.defineProperty(this, "wrappedWidth", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: 0
46
+ });
47
+ Object.defineProperty(this, "minReadableWidth", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: 0
52
+ });
53
+ Object.defineProperty(this, "minWidth", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: 0
58
+ });
59
+ Object.defineProperty(this, "width", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: 0
64
+ });
65
+ Object.defineProperty(this, "height", {
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true,
69
+ value: 0
70
+ });
71
+ Object.defineProperty(this, "x", {
72
+ enumerable: true,
73
+ configurable: true,
74
+ writable: true,
75
+ value: 0
76
+ });
77
+ Object.defineProperty(this, "y", {
78
+ enumerable: true,
79
+ configurable: true,
80
+ writable: true,
81
+ value: 0
82
+ });
83
+ this.styles = styles;
84
+ this.section = section;
85
+ this.raw = raw;
86
+ const splitRegex = /\r\n|\r|\n/g;
87
+ this.text = raw.split(splitRegex);
88
+ }
89
+ getContentHeight() {
90
+ const lineCount = Array.isArray(this.text) ? this.text.length : 1;
91
+ const lineHeight = pt2mm(this.styles.fontSize) * this.styles.lineHeight;
92
+ const vPadding = this.padding('top') + this.padding('bottom');
93
+ const height = lineCount * lineHeight + vPadding;
94
+ return Math.max(height, this.styles.minCellHeight);
95
+ }
96
+ padding(name) {
97
+ return this.styles.cellPadding[name];
98
+ }
99
+ }
100
+ export class Column {
101
+ constructor(index) {
102
+ Object.defineProperty(this, "index", {
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true,
106
+ value: void 0
107
+ });
108
+ Object.defineProperty(this, "wrappedWidth", {
109
+ enumerable: true,
110
+ configurable: true,
111
+ writable: true,
112
+ value: 0
113
+ });
114
+ Object.defineProperty(this, "minReadableWidth", {
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true,
118
+ value: 0
119
+ });
120
+ Object.defineProperty(this, "minWidth", {
121
+ enumerable: true,
122
+ configurable: true,
123
+ writable: true,
124
+ value: 0
125
+ });
126
+ Object.defineProperty(this, "width", {
127
+ enumerable: true,
128
+ configurable: true,
129
+ writable: true,
130
+ value: 0
131
+ });
132
+ this.index = index;
133
+ }
134
+ getMaxCustomCellWidth(table) {
135
+ let max = 0;
136
+ for (const row of table.allRows()) {
137
+ const cell = row.cells[this.index];
138
+ max = Math.max(max, cell.styles.cellWidth);
139
+ }
140
+ return max;
141
+ }
142
+ }
143
+ export class Row {
144
+ constructor(raw, index, section, cells) {
145
+ Object.defineProperty(this, "raw", {
146
+ enumerable: true,
147
+ configurable: true,
148
+ writable: true,
149
+ value: void 0
150
+ });
151
+ Object.defineProperty(this, "index", {
152
+ enumerable: true,
153
+ configurable: true,
154
+ writable: true,
155
+ value: void 0
156
+ });
157
+ Object.defineProperty(this, "section", {
158
+ enumerable: true,
159
+ configurable: true,
160
+ writable: true,
161
+ value: void 0
162
+ });
163
+ Object.defineProperty(this, "cells", {
164
+ enumerable: true,
165
+ configurable: true,
166
+ writable: true,
167
+ value: void 0
168
+ });
169
+ Object.defineProperty(this, "height", {
170
+ enumerable: true,
171
+ configurable: true,
172
+ writable: true,
173
+ value: 0
174
+ });
175
+ this.raw = raw;
176
+ this.index = index;
177
+ this.section = section;
178
+ this.cells = cells;
179
+ }
180
+ getMaxCellHeight(columns) {
181
+ return columns.reduce((acc, column) => Math.max(acc, this.cells[column.index]?.height || 0), 0);
182
+ }
183
+ getMinimumRowHeight(columns) {
184
+ return columns.reduce((acc, column) => {
185
+ const cell = this.cells[column.index];
186
+ if (!cell)
187
+ return 0;
188
+ const vPadding = cell.padding('top') + cell.padding('bottom');
189
+ const oneRowHeight = vPadding + cell.styles.lineHeight;
190
+ return oneRowHeight > acc ? oneRowHeight : acc;
191
+ }, 0);
192
+ }
193
+ }
194
+ export class Table {
195
+ constructor(input, content) {
196
+ Object.defineProperty(this, "settings", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: void 0
201
+ });
202
+ Object.defineProperty(this, "styles", {
203
+ enumerable: true,
204
+ configurable: true,
205
+ writable: true,
206
+ value: void 0
207
+ });
208
+ Object.defineProperty(this, "columns", {
209
+ enumerable: true,
210
+ configurable: true,
211
+ writable: true,
212
+ value: void 0
213
+ });
214
+ Object.defineProperty(this, "head", {
215
+ enumerable: true,
216
+ configurable: true,
217
+ writable: true,
218
+ value: void 0
219
+ });
220
+ Object.defineProperty(this, "body", {
221
+ enumerable: true,
222
+ configurable: true,
223
+ writable: true,
224
+ value: void 0
225
+ });
226
+ this.settings = input.settings;
227
+ this.styles = input.styles;
228
+ this.columns = content.columns;
229
+ this.head = content.head;
230
+ this.body = content.body;
231
+ }
232
+ static async create(arg) {
233
+ const { input, content, font, _cache } = arg;
234
+ const table = new Table(input, content);
235
+ await calculateWidths({ table, font, _cache });
236
+ return table;
237
+ }
238
+ getHeadHeight() {
239
+ return this.head.reduce((acc, row) => acc + row.getMaxCellHeight(this.columns), 0);
240
+ }
241
+ getBodyHeight() {
242
+ return this.body.reduce((acc, row) => acc + row.getMaxCellHeight(this.columns), 0);
243
+ }
244
+ allRows() {
245
+ return this.head.concat(this.body);
246
+ }
247
+ getWidth() {
248
+ return this.settings.tableWidth;
249
+ }
250
+ getHeight() {
251
+ return (this.settings.showHead ? this.getHeadHeight() : 0) + this.getBodyHeight();
252
+ }
253
+ }
254
+ async function calculateWidths(arg) {
255
+ const { table, font, _cache } = arg;
256
+ const getFontKitFontByFontName = (fontName) => getFontKitFont(fontName, font, _cache);
257
+ await calculate(table, getFontKitFontByFontName);
258
+ const resizableColumns = [];
259
+ let initialTableWidth = 0;
260
+ table.columns.forEach((column) => {
261
+ const customWidth = column.getMaxCustomCellWidth(table);
262
+ if (customWidth) {
263
+ // final column width
264
+ column.width = customWidth;
265
+ }
266
+ else {
267
+ // initial column width (will be resized)
268
+ column.width = column.wrappedWidth;
269
+ resizableColumns.push(column);
270
+ }
271
+ initialTableWidth += column.width;
272
+ });
273
+ // width difference that needs to be distributed
274
+ let resizeWidth = table.getWidth() - initialTableWidth;
275
+ // first resize attempt: with respect to minReadableWidth and minWidth
276
+ if (resizeWidth) {
277
+ resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) => Math.max(column.minReadableWidth, column.minWidth));
278
+ }
279
+ // second resize attempt: ignore minReadableWidth but respect minWidth
280
+ if (resizeWidth) {
281
+ resizeWidth = resizeColumns(resizableColumns, resizeWidth, (column) => column.minWidth);
282
+ }
283
+ resizeWidth = Math.abs(resizeWidth);
284
+ applyColSpans(table);
285
+ await fitContent(table, getFontKitFontByFontName);
286
+ applyRowSpans(table);
287
+ }
288
+ function applyRowSpans(table) {
289
+ const rowSpanCells = {};
290
+ let colRowSpansLeft = 1;
291
+ const all = table.allRows();
292
+ for (let rowIndex = 0; rowIndex < all.length; rowIndex++) {
293
+ const row = all[rowIndex];
294
+ for (const column of table.columns) {
295
+ const data = rowSpanCells[column.index];
296
+ if (colRowSpansLeft > 1) {
297
+ colRowSpansLeft--;
298
+ delete row.cells[column.index];
299
+ }
300
+ else if (data) {
301
+ data.cell.height += row.height;
302
+ colRowSpansLeft = 1;
303
+ delete row.cells[column.index];
304
+ data.left--;
305
+ if (data.left <= 1) {
306
+ delete rowSpanCells[column.index];
307
+ }
308
+ }
309
+ else {
310
+ const cell = row.cells[column.index];
311
+ if (!cell) {
312
+ continue;
313
+ }
314
+ cell.height = row.height;
315
+ }
316
+ }
317
+ }
318
+ }
319
+ function applyColSpans(table) {
320
+ const all = table.allRows();
321
+ for (let rowIndex = 0; rowIndex < all.length; rowIndex++) {
322
+ const row = all[rowIndex];
323
+ let colSpanCell = null;
324
+ let combinedColSpanWidth = 0;
325
+ let colSpansLeft = 0;
326
+ for (let columnIndex = 0; columnIndex < table.columns.length; columnIndex++) {
327
+ const column = table.columns[columnIndex];
328
+ // Width and colspan
329
+ colSpansLeft -= 1;
330
+ if (colSpansLeft > 1 && table.columns[columnIndex + 1]) {
331
+ combinedColSpanWidth += column.width;
332
+ delete row.cells[column.index];
333
+ }
334
+ else if (colSpanCell) {
335
+ const cell = colSpanCell;
336
+ delete row.cells[column.index];
337
+ colSpanCell = null;
338
+ cell.width = column.width + combinedColSpanWidth;
339
+ }
340
+ else {
341
+ const cell = row.cells[column.index];
342
+ if (!cell)
343
+ continue;
344
+ colSpansLeft = 1;
345
+ combinedColSpanWidth = 0;
346
+ cell.width = column.width + combinedColSpanWidth;
347
+ }
348
+ }
349
+ }
350
+ }
351
+ async function fitContent(table, getFontKitFontByFontName) {
352
+ const rowSpanHeight = { count: 0, height: 0 };
353
+ for (const row of table.allRows()) {
354
+ for (const column of table.columns) {
355
+ const cell = row.cells[column.index];
356
+ if (!cell)
357
+ continue;
358
+ const fontKitFont = await getFontKitFontByFontName(cell.styles.fontName);
359
+ cell.text = splitTextToSize({
360
+ value: cell.raw,
361
+ characterSpacing: cell.styles.characterSpacing,
362
+ boxWidthInPt: mm2pt(cell.width),
363
+ fontSize: cell.styles.fontSize,
364
+ fontKitFont,
365
+ });
366
+ cell.contentHeight = cell.getContentHeight();
367
+ let realContentHeight = cell.contentHeight;
368
+ if (rowSpanHeight && rowSpanHeight.count > 0) {
369
+ if (rowSpanHeight.height > realContentHeight) {
370
+ realContentHeight = rowSpanHeight.height;
371
+ }
372
+ }
373
+ if (realContentHeight > row.height) {
374
+ row.height = realContentHeight;
375
+ }
376
+ }
377
+ rowSpanHeight.count--;
378
+ }
379
+ }
380
+ function resizeColumns(columns, resizeWidth, getMinWidth) {
381
+ const initialResizeWidth = resizeWidth;
382
+ const sumWrappedWidth = columns.reduce((acc, column) => acc + column.wrappedWidth, 0);
383
+ for (let i = 0; i < columns.length; i++) {
384
+ const column = columns[i];
385
+ const ratio = column.wrappedWidth / sumWrappedWidth;
386
+ const suggestedChange = initialResizeWidth * ratio;
387
+ const suggestedWidth = column.width + suggestedChange;
388
+ const minWidth = getMinWidth(column);
389
+ const newWidth = suggestedWidth < minWidth ? minWidth : suggestedWidth;
390
+ resizeWidth -= newWidth - column.width;
391
+ column.width = newWidth;
392
+ }
393
+ resizeWidth = Math.round(resizeWidth * 1e10) / 1e10;
394
+ // Run the resizer again if there's remaining width needs
395
+ // to be distributed and there're columns that can be resized
396
+ if (resizeWidth) {
397
+ const resizableColumns = columns.filter((column) => {
398
+ return resizeWidth < 0
399
+ ? column.width > getMinWidth(column) // check if column can shrink
400
+ : true; // check if column can grow
401
+ });
402
+ if (resizableColumns.length) {
403
+ resizeWidth = resizeColumns(resizableColumns, resizeWidth, getMinWidth);
404
+ }
405
+ }
406
+ return resizeWidth;
407
+ }
408
+ async function calculate(table, getFontKitFontByFontName) {
409
+ for (const row of table.allRows()) {
410
+ for (const column of table.columns) {
411
+ const cell = row.cells[column.index];
412
+ if (!cell)
413
+ continue;
414
+ const hPadding = cell.padding('right') + cell.padding('left');
415
+ const fontKitFont = await getFontKitFontByFontName(cell.styles.fontName);
416
+ cell.contentWidth = getStringWidth(cell, fontKitFont) + hPadding;
417
+ const longestWordWidth = getStringWidth(Object.assign(cell, { text: cell.text.join(' ').split(/\s+/) }), fontKitFont);
418
+ cell.minReadableWidth = longestWordWidth + hPadding;
419
+ cell.minWidth = cell.styles.cellWidth;
420
+ cell.wrappedWidth = cell.styles.cellWidth;
421
+ }
422
+ }
423
+ for (const row of table.allRows()) {
424
+ for (const column of table.columns) {
425
+ const cell = row.cells[column.index];
426
+ // For now we ignore the minWidth and wrappedWidth of colspan cells when calculating colspan widths.
427
+ // Could probably be improved upon however.
428
+ if (cell) {
429
+ column.wrappedWidth = Math.max(column.wrappedWidth, cell.wrappedWidth);
430
+ column.minWidth = Math.max(column.minWidth, cell.minWidth);
431
+ column.minReadableWidth = Math.max(column.minReadableWidth, cell.minReadableWidth);
432
+ }
433
+ else {
434
+ // Respect cellWidth set in columnStyles even if there is no cells for this column
435
+ // or if the column only have colspan cells. Since the width of colspan cells
436
+ // does not affect the width of columns, setting columnStyles cellWidth enables the
437
+ // user to at least do it manually.
438
+ // Note that this is not perfect for now since for example row and table styles are
439
+ // not accounted for
440
+ const columnStyles = table.styles.columnStyles[column.index] || {};
441
+ const cellWidth = columnStyles.cellWidth || columnStyles.minCellWidth;
442
+ if (cellWidth) {
443
+ column.minWidth = cellWidth;
444
+ column.wrappedWidth = cellWidth;
445
+ }
446
+ }
447
+ }
448
+ }
449
+ }
450
+ function getStringWidth(cell, fontKitFont) {
451
+ const text = cell.text;
452
+ const textArr = Array.isArray(text) ? text : [text];
453
+ const fontSize = cell.styles.fontSize;
454
+ const characterSpacing = cell.styles.characterSpacing;
455
+ const widestLineWidth = textArr
456
+ .map((text) => widthOfTextAtSize(text, fontKitFont, fontSize, characterSpacing))
457
+ .reduce((a, b) => Math.max(a, b), 0);
458
+ return widestLineWidth;
459
+ }
460
+ //# sourceMappingURL=classes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"classes.js","sourceRoot":"","sources":["../../../../src/tables/classes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKpF,MAAM,OAAO,IAAI;IAgBf,YAAY,GAAW,EAAE,MAAc,EAAE,OAAg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AAC;IAEvC,OAAO,eAAe,CAAC;AACzB,CAAC"}
@@ -0,0 +1,66 @@
1
+ import { createMultiTables, createSingleTable } from './tableHelper';
2
+ import { cloneDeep } from '../utils';
3
+ import { getBodyWithRange, getBody } from './helper.js';
4
+ export const modifyTemplateForTable = async (arg) => {
5
+ const { template: t, input, options, _cache } = arg;
6
+ const template = Object.assign(cloneDeep(t), { schemas: [] });
7
+ let pageIndex = 0;
8
+ for (const schemaObj of t.schemas) {
9
+ const additionalSchemaObjs = [];
10
+ for (const [key, schema] of Object.entries(schemaObj)) {
11
+ if (schema.type === 'table') {
12
+ schema.__bodyRange = undefined;
13
+ const body = JSON.parse(input?.[key] || '[]');
14
+ const tables = await createMultiTables(body, {
15
+ schema,
16
+ basePdf: template.basePdf,
17
+ options,
18
+ _cache,
19
+ });
20
+ if (tables.length > 1) {
21
+ const firstTable = tables[0];
22
+ schema.__bodyRange = { start: 0, end: firstTable.body.length };
23
+ const allBodies = tables.map((table) => table.body);
24
+ const from2ndTable = tables.slice(1);
25
+ from2ndTable.forEach((table, i) => {
26
+ const additionalPageIndex = pageIndex + i + 1;
27
+ const additionalSchemaObj = {
28
+ [key]: {
29
+ ...schema,
30
+ position: { x: schema.position.x, y: table.settings.startY },
31
+ height: table.getHeight(),
32
+ showHead: false,
33
+ __bodyRange: {
34
+ start: allBodies.slice(0, i + 1).reduce((acc, cur) => acc + cur.length, 0),
35
+ end: allBodies.slice(0, i + 2).reduce((acc, cur) => acc + cur.length, 0),
36
+ },
37
+ content: input[key],
38
+ },
39
+ };
40
+ additionalSchemaObjs[additionalPageIndex] = additionalSchemaObj;
41
+ });
42
+ }
43
+ }
44
+ }
45
+ template.schemas.push(schemaObj);
46
+ additionalSchemaObjs.forEach((obj, index) => {
47
+ if (!template.schemas[index]) {
48
+ template.schemas[index] = obj;
49
+ }
50
+ else {
51
+ template.schemas[index] = { ...template.schemas[index], ...obj };
52
+ }
53
+ });
54
+ pageIndex++;
55
+ }
56
+ return template;
57
+ };
58
+ export const getDynamicHeightForTable = async (value, args) => {
59
+ if (args.schema.type !== 'table')
60
+ return Promise.resolve(args.schema.height);
61
+ const schema = args.schema;
62
+ const body = schema.__bodyRange?.start === 0 ? getBody(value) : getBodyWithRange(value, schema.__bodyRange);
63
+ const table = await createSingleTable(body, args);
64
+ return table.getHeight();
65
+ };
66
+ //# sourceMappingURL=dynamicTemplate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dynamicTemplate.js","sourceRoot":"","sources":["../../../../src/tables/dynamicTemplate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,GAK5C,EAAqB,EAAE;IACtB,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACpD,MAAM,QAAQ,GAAa,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IACxE,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,MAAM,SAAS,IAAI,CAAC,CAAC,OAAO,EAAE;QACjC,MAAM,oBAAoB,GAAyB,EAAE,CAAC;QACtD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;YACrD,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC3B,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC;gBAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,CAAe,CAA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