@pdfme/schemas 3.2.3 → 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,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMultiTables = exports.createSingleTable = void 0;
4
+ const common_1 = require("@pdfme/common");
5
+ const utils_1 = require("../utils");
6
+ const classes_1 = require("./classes");
7
+ function parseSection(sectionName, sectionRows, columns, styleProps, fallbackFontName) {
8
+ const rowSpansLeftForColumn = {};
9
+ const result = sectionRows.map((rawRow, rowIndex) => {
10
+ let skippedRowForRowSpans = 0;
11
+ const cells = {};
12
+ let colSpansAdded = 0;
13
+ let columnSpansLeft = 0;
14
+ for (const column of columns) {
15
+ if (rowSpansLeftForColumn[column.index] == null ||
16
+ rowSpansLeftForColumn[column.index].left === 0) {
17
+ if (columnSpansLeft === 0) {
18
+ let rawCell;
19
+ if (Array.isArray(rawRow)) {
20
+ rawCell = rawRow[column.index - colSpansAdded - skippedRowForRowSpans];
21
+ }
22
+ else {
23
+ rawCell = rawRow[column.index];
24
+ }
25
+ const styles = cellStyles(sectionName, column, rowIndex, styleProps, fallbackFontName);
26
+ const cell = new classes_1.Cell(rawCell, styles, sectionName);
27
+ cells[column.index] = cell;
28
+ columnSpansLeft = 0;
29
+ rowSpansLeftForColumn[column.index] = {
30
+ left: 0,
31
+ times: columnSpansLeft,
32
+ };
33
+ }
34
+ else {
35
+ columnSpansLeft--;
36
+ colSpansAdded++;
37
+ }
38
+ }
39
+ else {
40
+ rowSpansLeftForColumn[column.index].left--;
41
+ columnSpansLeft = rowSpansLeftForColumn[column.index].times;
42
+ skippedRowForRowSpans++;
43
+ }
44
+ }
45
+ return new classes_1.Row(rawRow, rowIndex, sectionName, cells);
46
+ });
47
+ return result;
48
+ }
49
+ function parseContent4Table(input, fallbackFontName) {
50
+ const content = input.content;
51
+ const columns = content.columns.map((index) => new classes_1.Column(index));
52
+ const styles = input.styles;
53
+ return {
54
+ columns,
55
+ head: parseSection('head', content.head, columns, styles, fallbackFontName),
56
+ body: parseSection('body', content.body, columns, styles, fallbackFontName),
57
+ };
58
+ }
59
+ function cellStyles(sectionName, column, rowIndex, styles, fallbackFontName) {
60
+ let sectionStyles;
61
+ if (sectionName === 'head') {
62
+ sectionStyles = styles.headStyles;
63
+ }
64
+ else if (sectionName === 'body') {
65
+ sectionStyles = styles.bodyStyles;
66
+ }
67
+ const otherStyles = Object.assign({}, styles.styles, sectionStyles);
68
+ const colStyles = styles.columnStyles[column.index] || styles.columnStyles[column.index] || {};
69
+ const rowStyles = sectionName === 'body' && rowIndex % 2 === 0
70
+ ? Object.assign({}, styles.alternateRowStyles)
71
+ : {};
72
+ const defaultStyle = {
73
+ fontName: fallbackFontName,
74
+ backgroundColor: '',
75
+ textColor: '#000000',
76
+ lineHeight: 1,
77
+ characterSpacing: 0,
78
+ alignment: 'left',
79
+ verticalAlignment: 'middle',
80
+ fontSize: 10,
81
+ cellPadding: 5,
82
+ lineColor: '#000000',
83
+ lineWidth: 0,
84
+ minCellHeight: 0,
85
+ minCellWidth: 0,
86
+ };
87
+ return Object.assign(defaultStyle, otherStyles, rowStyles, colStyles);
88
+ }
89
+ function mapCellStyle(style) {
90
+ return {
91
+ fontName: style.fontName,
92
+ alignment: style.alignment,
93
+ verticalAlignment: style.verticalAlignment,
94
+ fontSize: style.fontSize,
95
+ lineHeight: style.lineHeight,
96
+ characterSpacing: style.characterSpacing,
97
+ backgroundColor: style.backgroundColor,
98
+ // ---
99
+ textColor: style.fontColor,
100
+ lineColor: style.borderColor,
101
+ lineWidth: style.borderWidth,
102
+ cellPadding: style.padding,
103
+ };
104
+ }
105
+ function createTableWithAvailableHeight(tableBody, availableHeight, args) {
106
+ let limit = availableHeight;
107
+ const newTableBody = [];
108
+ let index = 0;
109
+ while (limit > 0 && index < tableBody.length) {
110
+ const row = tableBody.slice(0, index + 1).pop();
111
+ if (!row)
112
+ break;
113
+ const rowHeight = row.height;
114
+ if (limit - rowHeight < 0) {
115
+ break;
116
+ }
117
+ newTableBody.push(row.raw);
118
+ limit -= rowHeight;
119
+ index++;
120
+ }
121
+ return createSingleTable(newTableBody, args);
122
+ }
123
+ function getTableOptions(schema, body) {
124
+ const columnStylesWidth = schema.headWidthPercentages.reduce((acc, cur, i) => ({ ...acc, [i]: { cellWidth: schema.width * (cur / 100) } }), {});
125
+ const columnStylesAlignment = Object.entries(schema.columnStyles.alignment || {}).reduce((acc, [key, value]) => ({ ...acc, [key]: { alignment: value } }), {});
126
+ const allKeys = new Set([
127
+ ...Object.keys(columnStylesWidth).map(Number),
128
+ ...Object.keys(columnStylesAlignment).map(Number),
129
+ ]);
130
+ const columnStyles = Array.from(allKeys).reduce((acc, key) => {
131
+ const widthStyle = columnStylesWidth[key] || {};
132
+ const alignmentStyle = columnStylesAlignment[key] || {};
133
+ return { ...acc, [key]: { ...widthStyle, ...alignmentStyle } };
134
+ }, {});
135
+ return {
136
+ head: [schema.head],
137
+ body,
138
+ showHead: schema.showHead,
139
+ startY: schema.position.y,
140
+ tableWidth: schema.width,
141
+ tableLineColor: schema.tableStyles.borderColor,
142
+ tableLineWidth: schema.tableStyles.borderWidth,
143
+ headStyles: mapCellStyle(schema.headStyles),
144
+ bodyStyles: mapCellStyle(schema.bodyStyles),
145
+ alternateRowStyles: { backgroundColor: schema.bodyStyles.alternateBackgroundColor },
146
+ columnStyles,
147
+ margin: { top: 0, right: 0, left: schema.position.x, bottom: 0 },
148
+ };
149
+ }
150
+ function parseStyles(cInput) {
151
+ const styleOptions = {
152
+ styles: {},
153
+ headStyles: {},
154
+ bodyStyles: {},
155
+ alternateRowStyles: {},
156
+ columnStyles: {},
157
+ };
158
+ for (const prop of Object.keys(styleOptions)) {
159
+ if (prop === 'columnStyles') {
160
+ const current = cInput[prop];
161
+ styleOptions.columnStyles = Object.assign({}, current);
162
+ }
163
+ else {
164
+ const allOptions = [cInput];
165
+ const styles = allOptions.map((opts) => opts[prop] || {});
166
+ styleOptions[prop] = Object.assign({}, styles[0], styles[1], styles[2]);
167
+ }
168
+ }
169
+ return styleOptions;
170
+ }
171
+ function parseContent4Input(options) {
172
+ const head = options.head || [];
173
+ const body = options.body || [];
174
+ const columns = (head[0] || body[0] || []).map((_, index) => index);
175
+ return { columns, head, body };
176
+ }
177
+ function parseInput(schema, body) {
178
+ const options = getTableOptions(schema, body);
179
+ const styles = parseStyles(options);
180
+ const settings = {
181
+ startY: options.startY,
182
+ margin: options.margin,
183
+ tableWidth: options.tableWidth,
184
+ showHead: options.showHead,
185
+ tableLineWidth: options.tableLineWidth ?? 0,
186
+ tableLineColor: options.tableLineColor ?? '',
187
+ };
188
+ const content = parseContent4Input(options);
189
+ return { content, styles, settings };
190
+ }
191
+ function createSingleTable(body, args) {
192
+ const { options, _cache, basePdf } = args;
193
+ if (!(0, common_1.isBlankPdf)(basePdf))
194
+ throw new Error('[@pdfme/schema/table] Blank PDF is not supported');
195
+ const input = parseInput(args.schema, body);
196
+ const font = options.font || (0, common_1.getDefaultFont)();
197
+ const fallbackFontName = (0, common_1.getFallbackFontName)(font);
198
+ const content = parseContent4Table(input, fallbackFontName);
199
+ return classes_1.Table.create({ input, content, font, _cache });
200
+ }
201
+ exports.createSingleTable = createSingleTable;
202
+ async function createMultiTables(body, args) {
203
+ const { basePdf, schema } = args;
204
+ if (!(0, common_1.isBlankPdf)(basePdf))
205
+ throw new Error('[@pdfme/schema/table] Blank PDF is not supported');
206
+ const pageHeight = basePdf.height;
207
+ const paddingBottom = basePdf.padding[2];
208
+ const paddingTop = basePdf.padding[0];
209
+ let availableHeight = pageHeight - paddingBottom - schema.position.y;
210
+ const testTable = await createSingleTable(body, args);
211
+ let remainingBody = testTable.body;
212
+ const tables = [];
213
+ while (remainingBody.length > 0) {
214
+ const tableHeight = tables.length === 0
215
+ ? availableHeight - testTable.getHeadHeight()
216
+ : availableHeight - paddingTop;
217
+ const table = await createTableWithAvailableHeight(remainingBody, tableHeight, args);
218
+ tables.push(table);
219
+ remainingBody = remainingBody.slice(table.body.length);
220
+ if (remainingBody.length > 0) {
221
+ const _schema = (0, utils_1.cloneDeep)(schema);
222
+ _schema.showHead = false;
223
+ _schema.position.y = paddingTop;
224
+ args.schema = _schema;
225
+ availableHeight = pageHeight - paddingTop - paddingBottom;
226
+ }
227
+ }
228
+ return tables;
229
+ }
230
+ exports.createMultiTables = createMultiTables;
231
+ //# sourceMappingURL=tableHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableHelper.js","sourceRoot":"","sources":["../../../../src/tables/table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M,KAAK,GAAG,MAAM,8BAA8B,CAAC,aAAa,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAErF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEnB,aAAa,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEvD,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,OAAO,GAAG,IAAA,iBAAS,EAAC,MAAM,CAAC,CAAC;YAClC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;YACzB,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC;YAChC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;YAEtB,eAAe,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;SAC3D;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AApCD,8CAoCC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/tables/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,321 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.uiRender = void 0;
7
+ const tableHelper_js_1 = require("./tableHelper.js");
8
+ const helper_js_1 = require("./helper.js");
9
+ const cell_js_1 = __importDefault(require("./cell.js"));
10
+ const utils_1 = require("../utils");
11
+ const cellUiRender = cell_js_1.default.ui;
12
+ const convertToCellStyle = (styles) => ({
13
+ fontName: styles.fontName,
14
+ alignment: styles.alignment,
15
+ verticalAlignment: styles.verticalAlignment,
16
+ fontSize: styles.fontSize,
17
+ lineHeight: styles.lineHeight,
18
+ characterSpacing: styles.characterSpacing,
19
+ backgroundColor: styles.backgroundColor,
20
+ // ---
21
+ fontColor: styles.textColor,
22
+ borderColor: styles.lineColor,
23
+ borderWidth: styles.lineWidth,
24
+ padding: styles.cellPadding,
25
+ });
26
+ const calcResizedHeadWidthPercentages = (arg) => {
27
+ const { currentHeadWidthPercentages, currentHeadWidths, changedHeadWidth, changedHeadIndex } = arg;
28
+ const headWidthPercentages = [...currentHeadWidthPercentages];
29
+ const totalWidth = currentHeadWidths.reduce((a, b) => a + b, 0);
30
+ const changedWidthPercentage = (changedHeadWidth / totalWidth) * 100;
31
+ const originalNextWidthPercentage = headWidthPercentages[changedHeadIndex + 1] ?? 0;
32
+ const adjustment = headWidthPercentages[changedHeadIndex] - changedWidthPercentage;
33
+ headWidthPercentages[changedHeadIndex] = changedWidthPercentage;
34
+ if (changedHeadIndex + 1 < headWidthPercentages.length) {
35
+ headWidthPercentages[changedHeadIndex + 1] = originalNextWidthPercentage + adjustment;
36
+ }
37
+ return headWidthPercentages;
38
+ };
39
+ const renderRowUi = (args) => {
40
+ const { rows, arg, onChangeEditingPosition, offsetY = 0, editingPosition } = args;
41
+ const value = JSON.parse(arg.value || '[]');
42
+ // TODO Need to adjust the inner size when the outer border increases
43
+ // Want to have the same style as border-collapse: collapse; (overlapping borders should merge into one)
44
+ // This should apply to the table itself as well as the cells, which should behave similarly.
45
+ let rowOffsetY = offsetY;
46
+ rows.forEach((row, rowIndex) => {
47
+ const { cells, height, section } = row;
48
+ let colWidth = 0;
49
+ Object.values(cells).forEach((cell, colIndex) => {
50
+ const div = document.createElement('div');
51
+ div.style.position = 'absolute';
52
+ div.style.top = `${rowOffsetY}mm`;
53
+ div.style.left = `${colWidth}mm`;
54
+ div.style.width = `${cell.width}mm`;
55
+ div.style.height = `${cell.height}mm`;
56
+ div.style.cursor =
57
+ arg.mode === 'designer' || (arg.mode === 'form' && section === 'body') ? 'text' : 'default';
58
+ div.addEventListener('click', () => {
59
+ if (arg.mode === 'viewer')
60
+ return;
61
+ onChangeEditingPosition({ rowIndex, colIndex });
62
+ });
63
+ arg.rootElement.appendChild(div);
64
+ const isEditing = editingPosition.rowIndex === rowIndex && editingPosition.colIndex === colIndex;
65
+ let mode = 'viewer';
66
+ if (arg.mode === 'form') {
67
+ mode = section === 'body' && isEditing ? 'designer' : 'viewer';
68
+ }
69
+ else if (arg.mode === 'designer') {
70
+ mode = isEditing ? 'designer' : 'form';
71
+ }
72
+ void cellUiRender({
73
+ ...arg,
74
+ stopEditing: () => {
75
+ if (arg.mode === 'form') {
76
+ resetEditingPosition();
77
+ }
78
+ },
79
+ mode,
80
+ onChange: (v) => {
81
+ if (!arg.onChange)
82
+ return;
83
+ const newValue = (Array.isArray(v) ? v[0].value : v.value);
84
+ if (section === 'body') {
85
+ const startRange = arg.schema.__bodyRange?.start ?? 0;
86
+ value[rowIndex + startRange][colIndex] = newValue;
87
+ // TODO Calling onChange triggers re-rendering, causing the focus to be lost
88
+ arg.onChange({ key: 'content', value: JSON.stringify(value) });
89
+ }
90
+ else {
91
+ const newHead = [...arg.schema.head];
92
+ newHead[colIndex] = newValue;
93
+ arg.onChange({ key: 'head', value: newHead });
94
+ }
95
+ },
96
+ value: cell.raw,
97
+ placeholder: '',
98
+ rootElement: div,
99
+ schema: {
100
+ type: 'cell',
101
+ content: cell.raw,
102
+ position: { x: colWidth, y: rowOffsetY },
103
+ width: cell.width,
104
+ height: cell.height,
105
+ ...convertToCellStyle(cell.styles),
106
+ },
107
+ });
108
+ colWidth += cell.width;
109
+ });
110
+ rowOffsetY += height;
111
+ });
112
+ };
113
+ const headEditingPosition = { rowIndex: -1, colIndex: -1 };
114
+ const bodyEditingPosition = { rowIndex: -1, colIndex: -1 };
115
+ const resetEditingPosition = () => {
116
+ headEditingPosition.rowIndex = -1;
117
+ headEditingPosition.colIndex = -1;
118
+ bodyEditingPosition.rowIndex = -1;
119
+ bodyEditingPosition.colIndex = -1;
120
+ };
121
+ const uiRender = async (arg) => {
122
+ const { rootElement, onChange, schema, value, mode } = arg;
123
+ const body = (0, helper_js_1.getBody)(value);
124
+ const bodyWidthRange = (0, helper_js_1.getBodyWithRange)(value, schema.__bodyRange);
125
+ const table = await (0, tableHelper_js_1.createSingleTable)(bodyWidthRange, arg);
126
+ rootElement.innerHTML = '';
127
+ rootElement.style.borderColor = schema.tableStyles.borderColor;
128
+ rootElement.style.borderWidth = String(schema.tableStyles.borderWidth) + 'mm';
129
+ rootElement.style.borderStyle = 'solid';
130
+ rootElement.style.boxSizing = 'border-box';
131
+ const handleChangeEditingPosition = (newPosition, editingPosition) => {
132
+ resetEditingPosition();
133
+ editingPosition.rowIndex = newPosition.rowIndex;
134
+ editingPosition.colIndex = newPosition.colIndex;
135
+ void (0, exports.uiRender)(arg);
136
+ };
137
+ if (schema.showHead) {
138
+ renderRowUi({
139
+ rows: table.head,
140
+ arg,
141
+ editingPosition: headEditingPosition,
142
+ onChangeEditingPosition: (p) => handleChangeEditingPosition(p, headEditingPosition),
143
+ });
144
+ }
145
+ const offsetY = schema.showHead ? table.getHeadHeight() : 0;
146
+ renderRowUi({
147
+ rows: table.body,
148
+ arg,
149
+ editingPosition: bodyEditingPosition,
150
+ onChangeEditingPosition: (p) => {
151
+ handleChangeEditingPosition(p, bodyEditingPosition);
152
+ },
153
+ offsetY,
154
+ });
155
+ if (mode === 'form' && onChange) {
156
+ if (schema.__bodyRange?.end === undefined ||
157
+ schema.__bodyRange.end >= JSON.parse(value || '[]').length) {
158
+ const addRowButton = document.createElement('button');
159
+ addRowButton.style.width = '30px';
160
+ addRowButton.style.height = '30px';
161
+ addRowButton.style.position = 'absolute';
162
+ addRowButton.style.top = `${table.getHeight()}mm`;
163
+ addRowButton.style.left = 'calc(50% - 15px)';
164
+ addRowButton.innerText = '+';
165
+ addRowButton.onclick = () => {
166
+ const newRow = Array(schema.head.length).fill('');
167
+ onChange({ key: 'content', value: JSON.stringify(body.concat([newRow])) });
168
+ };
169
+ rootElement.appendChild(addRowButton);
170
+ }
171
+ let offsetY = schema.showHead ? table.getHeadHeight() : 0;
172
+ table.body.forEach((row, i) => {
173
+ offsetY = offsetY + row.height;
174
+ const removeRowButton = document.createElement('button');
175
+ removeRowButton.style.width = '30px';
176
+ removeRowButton.style.height = '30px';
177
+ removeRowButton.style.position = 'absolute';
178
+ removeRowButton.style.top = `${offsetY - (0, utils_1.px2mm)(30)}mm`;
179
+ removeRowButton.style.right = '-30px';
180
+ removeRowButton.innerText = '-';
181
+ removeRowButton.onclick = () => {
182
+ const newTableBody = body.filter((_, j) => j !== i + (schema.__bodyRange?.start ?? 0));
183
+ onChange({ key: 'content', value: JSON.stringify(newTableBody) });
184
+ };
185
+ rootElement.appendChild(removeRowButton);
186
+ });
187
+ }
188
+ if (mode === 'designer' && onChange) {
189
+ const addColumnButton = document.createElement('button');
190
+ addColumnButton.style.width = '30px';
191
+ addColumnButton.style.height = '30px';
192
+ addColumnButton.style.position = 'absolute';
193
+ addColumnButton.style.top = `${table.getHeadHeight() - (0, utils_1.px2mm)(30)}mm`;
194
+ addColumnButton.style.right = '-30px';
195
+ addColumnButton.innerText = '+';
196
+ addColumnButton.onclick = (e) => {
197
+ e.preventDefault();
198
+ const newColumnWidthPercentage = 25;
199
+ const totalCurrentWidth = schema.headWidthPercentages.reduce((acc, width) => acc + width, 0);
200
+ const scalingRatio = (100 - newColumnWidthPercentage) / totalCurrentWidth;
201
+ const scaledWidths = schema.headWidthPercentages.map((width) => width * scalingRatio);
202
+ onChange([
203
+ { key: 'head', value: schema.head.concat(`Head ${schema.head.length + 1}`) },
204
+ { key: 'headWidthPercentages', value: scaledWidths.concat(newColumnWidthPercentage) },
205
+ {
206
+ key: 'content',
207
+ value: JSON.stringify(bodyWidthRange.map((row, i) => row.concat(`Row ${i + 1}`))),
208
+ },
209
+ ]);
210
+ };
211
+ rootElement.appendChild(addColumnButton);
212
+ let offsetX = 0;
213
+ table.columns.forEach((column, i) => {
214
+ offsetX = offsetX + column.width;
215
+ const removeColumnButton = document.createElement('button');
216
+ removeColumnButton.style.width = '30px';
217
+ removeColumnButton.style.height = '30px';
218
+ removeColumnButton.style.position = 'absolute';
219
+ removeColumnButton.style.top = '-30px';
220
+ removeColumnButton.style.left = `${offsetX - (0, utils_1.px2mm)(30)}mm`;
221
+ removeColumnButton.innerText = '-';
222
+ removeColumnButton.onclick = (e) => {
223
+ e.preventDefault();
224
+ const totalWidthMinusRemoved = schema.headWidthPercentages.reduce((sum, width, j) => (j !== i ? sum + width : sum), 0);
225
+ // TODO Should also remove the deleted columnStyles when deleting
226
+ onChange([
227
+ { key: 'head', value: schema.head.filter((_, j) => j !== i) },
228
+ {
229
+ key: 'headWidthPercentages',
230
+ value: schema.headWidthPercentages
231
+ .filter((_, j) => j !== i)
232
+ .map((width) => (width / totalWidthMinusRemoved) * 100),
233
+ },
234
+ {
235
+ key: 'content',
236
+ value: JSON.stringify(bodyWidthRange.map((row) => row.filter((_, j) => j !== i))),
237
+ },
238
+ ]);
239
+ };
240
+ rootElement.appendChild(removeColumnButton);
241
+ if (i === table.columns.length - 1)
242
+ return;
243
+ const dragHandle = document.createElement('div');
244
+ const lineWidth = 5;
245
+ dragHandle.style.width = `${lineWidth}px`;
246
+ dragHandle.style.height = '100%';
247
+ dragHandle.style.backgroundColor = '#eee';
248
+ dragHandle.style.opacity = '0.5';
249
+ dragHandle.style.cursor = 'col-resize';
250
+ dragHandle.style.position = 'absolute';
251
+ dragHandle.style.zIndex = '10';
252
+ dragHandle.style.left = `${offsetX - (0, utils_1.px2mm)(lineWidth) / 2}mm`;
253
+ dragHandle.style.top = '0';
254
+ const setColor = (e) => {
255
+ const handle = e.target;
256
+ handle.style.backgroundColor = '#2196f3';
257
+ };
258
+ const resetColor = (e) => {
259
+ const handle = e.target;
260
+ handle.style.backgroundColor = '#eee';
261
+ };
262
+ dragHandle.addEventListener('mouseover', setColor);
263
+ dragHandle.addEventListener('mouseout', resetColor);
264
+ const prevColumnLeft = offsetX - column.width;
265
+ const nextColumnRight = offsetX - (0, utils_1.px2mm)(lineWidth) + table.columns[i + 1].width;
266
+ dragHandle.addEventListener('mousedown', (e) => {
267
+ resetEditingPosition();
268
+ const handle = e.target;
269
+ dragHandle.removeEventListener('mouseover', setColor);
270
+ dragHandle.removeEventListener('mouseout', resetColor);
271
+ let move = 0;
272
+ const mouseMove = (e) => {
273
+ // TODO There is an issue where newLeft gets displaced with drag & drop
274
+ let moveX = e.movementX;
275
+ const currentLeft = Number(handle.style.left.replace('mm', ''));
276
+ let newLeft = currentLeft + moveX;
277
+ if (newLeft < prevColumnLeft) {
278
+ newLeft = prevColumnLeft;
279
+ moveX = newLeft - currentLeft;
280
+ }
281
+ if (newLeft >= nextColumnRight) {
282
+ newLeft = nextColumnRight;
283
+ moveX = newLeft - currentLeft;
284
+ }
285
+ handle.style.left = `${newLeft}mm`;
286
+ move += moveX;
287
+ };
288
+ rootElement.addEventListener('mousemove', mouseMove);
289
+ const commitResize = () => {
290
+ if (move !== 0) {
291
+ const newHeadWidthPercentages = calcResizedHeadWidthPercentages({
292
+ currentHeadWidthPercentages: schema.headWidthPercentages,
293
+ currentHeadWidths: table.columns.map((column) => column.width),
294
+ changedHeadWidth: table.columns[i].width + move,
295
+ changedHeadIndex: i,
296
+ });
297
+ onChange({ key: 'headWidthPercentages', value: newHeadWidthPercentages });
298
+ }
299
+ move = 0;
300
+ dragHandle.addEventListener('mouseover', setColor);
301
+ dragHandle.addEventListener('mouseout', resetColor);
302
+ rootElement.removeEventListener('mousemove', mouseMove);
303
+ rootElement.removeEventListener('mouseup', commitResize);
304
+ };
305
+ rootElement.addEventListener('mouseup', commitResize);
306
+ });
307
+ rootElement.appendChild(dragHandle);
308
+ });
309
+ }
310
+ if (mode === 'viewer') {
311
+ resetEditingPosition();
312
+ }
313
+ if (mode !== 'form') {
314
+ const tableHeight = schema.showHead ? table.getHeight() : table.getBodyHeight();
315
+ if (schema.height !== tableHeight && onChange) {
316
+ onChange({ key: 'height', value: tableHeight });
317
+ }
318
+ }
319
+ };
320
+ exports.uiRender = uiRender;
321
+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B,EAAE,CAAC;KACxB;IAED,IAAI,IAAI,KAAK,MAAM,EAAE;QACnB,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QAChF,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,QAAQ,EAAE;YAC7C,QAAQ,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;SACjD;KACF;AACH,CAAC,CAAC;AA/NW,QAAA,QAAQ,YA+NnB"}
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.calculateDynamicFontSize = exports.getSplittedLines = exports.getFontKitFont = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getFontDescentInPt = exports.getBrowserVerticalFontAdjustments = void 0;
26
+ exports.splitTextToSize = exports.calculateDynamicFontSize = exports.getSplittedLines = exports.getFontKitFont = exports.widthOfTextAtSize = exports.heightOfFontAtSize = exports.getFontDescentInPt = exports.getBrowserVerticalFontAdjustments = void 0;
27
27
  const fontkit = __importStar(require("fontkit"));
28
28
  const common_1 = require("@pdfme/common");
29
29
  const buffer_1 = require("buffer");
@@ -89,13 +89,13 @@ const getFallbackFont = (font) => {
89
89
  return font[fallbackFontName];
90
90
  };
91
91
  const getCacheKey = (fontName) => `getFontKitFont-${fontName}`;
92
- const getFontKitFont = async (textSchema, font, _cache) => {
93
- const fontName = textSchema.fontName || (0, common_1.getFallbackFontName)(font);
94
- const cacheKey = getCacheKey(fontName);
92
+ const getFontKitFont = async (fontName, font, _cache) => {
93
+ const fntNm = fontName || (0, common_1.getFallbackFontName)(font);
94
+ const cacheKey = getCacheKey(fntNm);
95
95
  if (_cache.has(cacheKey)) {
96
96
  return _cache.get(cacheKey);
97
97
  }
98
- const currentFont = font[fontName] || getFallbackFont(font) || (0, common_1.getDefaultFont)()[common_1.DEFAULT_FONT_NAME];
98
+ const currentFont = font[fntNm] || getFallbackFont(font) || (0, common_1.getDefaultFont)()[common_1.DEFAULT_FONT_NAME];
99
99
  let fontData = currentFont.data;
100
100
  if (typeof fontData === 'string') {
101
101
  fontData = fontData.startsWith('http')
@@ -174,7 +174,7 @@ const calculateDynamicFontSize = async ({ textSchema, font, value, startingFontS
174
174
  if (dynamicFontSizeSetting.max < dynamicFontSizeSetting.min)
175
175
  return fontSize;
176
176
  const characterSpacing = schemaCharacterSpacing ?? constants_js_1.DEFAULT_CHARACTER_SPACING;
177
- const fontKitFont = await (0, exports.getFontKitFont)(textSchema, font, _cache);
177
+ const fontKitFont = await (0, exports.getFontKitFont)(textSchema.fontName, font, _cache);
178
178
  const paragraphs = value.split('\n');
179
179
  let dynamicFontSize = fontSize;
180
180
  if (dynamicFontSize < dynamicFontSizeSetting.min) {
@@ -258,4 +258,19 @@ const calculateDynamicFontSize = async ({ textSchema, font, value, startingFontS
258
258
  return dynamicFontSize;
259
259
  };
260
260
  exports.calculateDynamicFontSize = calculateDynamicFontSize;
261
+ const splitTextToSize = (arg) => {
262
+ const { value, characterSpacing, fontSize, fontKitFont, boxWidthInPt } = arg;
263
+ const fontWidthCalcValues = {
264
+ font: fontKitFont,
265
+ fontSize,
266
+ characterSpacing,
267
+ boxWidthInPt,
268
+ };
269
+ let lines = [];
270
+ value.split(/\r\n|\r|\n|\f|\u000B/g).forEach((line) => {
271
+ lines = lines.concat((0, exports.getSplittedLines)(line, fontWidthCalcValues));
272
+ });
273
+ return lines;
274
+ };
275
+ exports.splitTextToSize = splitTextToSize;
261
276
  //# sourceMappingURL=helper.js.map