@pdfme/common 5.5.7-dev.2 → 5.5.7-dev.4
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.
- package/dist/cjs/__tests__/dynamicTemplate.test.js +74 -12
- package/dist/cjs/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/cjs/src/dynamicTemplate.js +200 -256
- package/dist/cjs/src/dynamicTemplate.js.map +1 -1
- package/dist/esm/__tests__/dynamicTemplate.test.js +74 -12
- package/dist/esm/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/esm/src/dynamicTemplate.js +200 -256
- package/dist/esm/src/dynamicTemplate.js.map +1 -1
- package/dist/node/__tests__/dynamicTemplate.test.js +74 -12
- package/dist/node/__tests__/dynamicTemplate.test.js.map +1 -1
- package/dist/node/src/dynamicTemplate.js +200 -256
- package/dist/node/src/dynamicTemplate.js.map +1 -1
- package/dist/types/src/dynamicTemplate.d.ts +12 -0
- package/package.json +1 -1
- package/src/dynamicTemplate.ts +251 -281
|
@@ -2,283 +2,227 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDynamicTemplate = void 0;
|
|
4
4
|
const helper_js_1 = require("./helper.js");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Object.defineProperty(this, "width", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: 0
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "height", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: 0
|
|
36
|
-
});
|
|
37
|
-
Object.defineProperty(this, "padding", {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
configurable: true,
|
|
40
|
-
writable: true,
|
|
41
|
-
value: [0, 0, 0, 0]
|
|
42
|
-
});
|
|
43
|
-
Object.defineProperty(this, "position", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true,
|
|
47
|
-
value: { x: 0, y: 0 }
|
|
5
|
+
/** Floating point tolerance for comparisons */
|
|
6
|
+
const EPSILON = 0.01;
|
|
7
|
+
/** Calculate the content height of a page (drawable area excluding padding) */
|
|
8
|
+
const getContentHeight = (basePdf) => basePdf.height - basePdf.padding[0] - basePdf.padding[2];
|
|
9
|
+
/** Get the input value for a schema */
|
|
10
|
+
const getSchemaValue = (schema, input) => (schema.readOnly ? schema.content : input?.[schema.name]) || '';
|
|
11
|
+
/**
|
|
12
|
+
* Normalize schemas within a single page into layout items.
|
|
13
|
+
* Returns items sorted by Y coordinate with their order preserved.
|
|
14
|
+
*/
|
|
15
|
+
function normalizePageSchemas(pageSchemas, paddingTop) {
|
|
16
|
+
const items = [];
|
|
17
|
+
const orderMap = new Map();
|
|
18
|
+
pageSchemas.forEach((schema, index) => {
|
|
19
|
+
const localY = schema.position.y - paddingTop;
|
|
20
|
+
items.push({
|
|
21
|
+
schema: (0, helper_js_1.cloneDeep)(schema),
|
|
22
|
+
baseY: localY,
|
|
23
|
+
height: schema.height,
|
|
24
|
+
dynamicHeights: [schema.height], // Will be updated later
|
|
48
25
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
setSchema(schema) {
|
|
56
|
-
this.schema = schema;
|
|
57
|
-
}
|
|
58
|
-
setWidth(width) {
|
|
59
|
-
this.width = width;
|
|
60
|
-
}
|
|
61
|
-
setHeight(height) {
|
|
62
|
-
this.height = height;
|
|
63
|
-
}
|
|
64
|
-
setPadding(padding) {
|
|
65
|
-
this.padding = padding;
|
|
66
|
-
}
|
|
67
|
-
setPosition(position) {
|
|
68
|
-
this.position = position;
|
|
69
|
-
}
|
|
70
|
-
insertChild(child) {
|
|
71
|
-
const index = this.getChildCount();
|
|
72
|
-
child.setIndex(index);
|
|
73
|
-
this.children.splice(index, 0, child);
|
|
74
|
-
}
|
|
75
|
-
getChildCount() {
|
|
76
|
-
return this.children.length;
|
|
77
|
-
}
|
|
78
|
-
getChild(index) {
|
|
79
|
-
return this.children[index];
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function createPage(basePdf) {
|
|
83
|
-
const page = new LayoutNode({ ...basePdf });
|
|
84
|
-
page.setPadding(basePdf.padding);
|
|
85
|
-
return page;
|
|
86
|
-
}
|
|
87
|
-
function createNode(arg) {
|
|
88
|
-
const { position, width, height, schema } = arg;
|
|
89
|
-
const node = new LayoutNode({ width, height });
|
|
90
|
-
node.setPosition(position);
|
|
91
|
-
node.setSchema(schema);
|
|
92
|
-
return node;
|
|
93
|
-
}
|
|
94
|
-
function resortChildren(page, orderMap) {
|
|
95
|
-
page.children = page.children
|
|
96
|
-
.sort((a, b) => {
|
|
97
|
-
const orderA = orderMap.get(a.schema?.name ?? '');
|
|
98
|
-
const orderB = orderMap.get(b.schema?.name ?? '');
|
|
99
|
-
if (orderA === undefined || orderB === undefined) {
|
|
100
|
-
throw new Error('[@pdfme/common] order is not defined');
|
|
26
|
+
orderMap.set(schema.name, index);
|
|
27
|
+
});
|
|
28
|
+
// Sort by Y coordinate (preserve original order for same position)
|
|
29
|
+
items.sort((a, b) => {
|
|
30
|
+
if (Math.abs(a.baseY - b.baseY) > EPSILON) {
|
|
31
|
+
return a.baseY - b.baseY;
|
|
101
32
|
}
|
|
102
|
-
return
|
|
103
|
-
})
|
|
104
|
-
.map((child, index) => {
|
|
105
|
-
child.setIndex(index);
|
|
106
|
-
return child;
|
|
33
|
+
return (orderMap.get(a.schema.name) ?? 0) - (orderMap.get(b.schema.name) ?? 0);
|
|
107
34
|
});
|
|
35
|
+
return { items, orderMap };
|
|
108
36
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Place rows on pages, splitting across pages as needed.
|
|
39
|
+
* @returns The final global Y coordinate after placement
|
|
40
|
+
*/
|
|
41
|
+
function placeRowsOnPages(schema, dynamicHeights, startGlobalY, contentHeight, paddingTop, pages) {
|
|
42
|
+
let currentRowIndex = 0;
|
|
43
|
+
let currentPageIndex = Math.floor(startGlobalY / contentHeight);
|
|
44
|
+
let currentYInPage = startGlobalY % contentHeight;
|
|
45
|
+
if (currentYInPage < 0)
|
|
46
|
+
currentYInPage = 0;
|
|
47
|
+
let actualGlobalEndY = 0;
|
|
48
|
+
const isSplittable = dynamicHeights.length > 1;
|
|
49
|
+
while (currentRowIndex < dynamicHeights.length) {
|
|
50
|
+
// Ensure page exists
|
|
51
|
+
while (pages.length <= currentPageIndex)
|
|
52
|
+
pages.push([]);
|
|
53
|
+
const spaceLeft = contentHeight - currentYInPage;
|
|
54
|
+
const rowHeight = dynamicHeights[currentRowIndex];
|
|
55
|
+
// If row doesn't fit, move to next page
|
|
56
|
+
if (rowHeight > spaceLeft + EPSILON) {
|
|
57
|
+
const isAtPageStart = Math.abs(spaceLeft - contentHeight) <= EPSILON;
|
|
58
|
+
if (!isAtPageStart) {
|
|
59
|
+
currentPageIndex++;
|
|
60
|
+
currentYInPage = 0;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
// Force placement for oversized rows that don't fit even on a fresh page
|
|
124
64
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
65
|
+
// Pack as many rows as possible on this page
|
|
66
|
+
let chunkHeight = 0;
|
|
67
|
+
const startRowIndex = currentRowIndex;
|
|
68
|
+
while (currentRowIndex < dynamicHeights.length) {
|
|
69
|
+
const h = dynamicHeights[currentRowIndex];
|
|
70
|
+
if (currentYInPage + chunkHeight + h <= contentHeight + EPSILON) {
|
|
71
|
+
chunkHeight += h;
|
|
72
|
+
currentRowIndex++;
|
|
131
73
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
page.insertChild(node);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
const pageHeight = Math.max(...schemaPositions, basePdf.height - basePdf.padding[2]);
|
|
138
|
-
page.setHeight(pageHeight);
|
|
139
|
-
resortChildren(page, orderMap);
|
|
140
|
-
return page;
|
|
141
|
-
}
|
|
142
|
-
function breakIntoPages(arg) {
|
|
143
|
-
const { longPage, orderMap, basePdf } = arg;
|
|
144
|
-
const pages = [createPage(basePdf)];
|
|
145
|
-
const [paddingTop, , paddingBottom] = basePdf.padding;
|
|
146
|
-
const yAdjustments = [];
|
|
147
|
-
const getPageHeight = (pageIndex) => basePdf.height - paddingBottom - (pageIndex > 0 ? paddingTop : 0);
|
|
148
|
-
const calculateNewY = (y, pageIndex) => {
|
|
149
|
-
const newY = y - pageIndex * (basePdf.height - paddingTop - paddingBottom);
|
|
150
|
-
while (pages.length <= pageIndex) {
|
|
151
|
-
if (!pages[pageIndex]) {
|
|
152
|
-
pages.push(createPage(basePdf));
|
|
153
|
-
yAdjustments.push({ page: pageIndex, value: (newY - paddingTop) * -1 });
|
|
74
|
+
else {
|
|
75
|
+
break;
|
|
154
76
|
}
|
|
155
77
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
78
|
+
// Don't leave header alone on a page without any data rows
|
|
79
|
+
// If only header fits and there are data rows remaining, move everything to next page
|
|
80
|
+
// BUT: if already at page top, don't move (prevents infinite loop when data row is too large)
|
|
81
|
+
const isAtPageTop = currentYInPage <= EPSILON;
|
|
82
|
+
if (isSplittable &&
|
|
83
|
+
startRowIndex === 0 &&
|
|
84
|
+
currentRowIndex === 1 &&
|
|
85
|
+
dynamicHeights.length > 1 &&
|
|
86
|
+
!isAtPageTop) {
|
|
87
|
+
currentRowIndex = 0;
|
|
88
|
+
currentPageIndex++;
|
|
89
|
+
currentYInPage = 0;
|
|
90
|
+
continue;
|
|
168
91
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const { schema, position, height, width } = children[i];
|
|
174
|
-
const { y, x } = position;
|
|
175
|
-
let targetPageIndex = calculateTargetPageIndex(y);
|
|
176
|
-
if (targetPageIndex < currentPageIndex) {
|
|
177
|
-
targetPageIndex = currentPageIndex;
|
|
92
|
+
// Force at least one row to prevent infinite loop
|
|
93
|
+
if (currentRowIndex === startRowIndex) {
|
|
94
|
+
chunkHeight += dynamicHeights[currentRowIndex];
|
|
95
|
+
currentRowIndex++;
|
|
178
96
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
97
|
+
// Create schema for this chunk
|
|
98
|
+
const newSchema = {
|
|
99
|
+
...schema,
|
|
100
|
+
height: chunkHeight,
|
|
101
|
+
position: { ...schema.position, y: currentYInPage + paddingTop },
|
|
102
|
+
};
|
|
103
|
+
// Set bodyRange for splittable elements
|
|
104
|
+
// dynamicHeights[0] = header row, dynamicHeights[1] = body[0]
|
|
105
|
+
// So subtract 1 to convert to body index
|
|
106
|
+
if (isSplittable) {
|
|
107
|
+
newSchema.__bodyRange = {
|
|
108
|
+
start: startRowIndex === 0 ? 0 : startRowIndex - 1,
|
|
109
|
+
end: currentRowIndex - 1,
|
|
110
|
+
};
|
|
111
|
+
newSchema.__isSplit = startRowIndex > 0;
|
|
112
|
+
}
|
|
113
|
+
pages[currentPageIndex].push(newSchema);
|
|
114
|
+
// Update position
|
|
115
|
+
currentYInPage += chunkHeight;
|
|
116
|
+
if (currentYInPage >= contentHeight - EPSILON) {
|
|
117
|
+
currentPageIndex++;
|
|
118
|
+
currentYInPage = 0;
|
|
189
119
|
}
|
|
190
|
-
|
|
191
|
-
if (!schema)
|
|
192
|
-
throw new Error('[@pdfme/common] schema is undefined');
|
|
193
|
-
const clonedElement = createNode({ schema, position: { x, y: newY }, width, height });
|
|
194
|
-
pages[targetPageIndex].insertChild(clonedElement);
|
|
120
|
+
actualGlobalEndY = currentPageIndex * contentHeight + currentYInPage;
|
|
195
121
|
}
|
|
196
|
-
|
|
197
|
-
return pages;
|
|
122
|
+
return actualGlobalEndY;
|
|
198
123
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
};
|
|
204
|
-
const nameToSchemas = new Map();
|
|
205
|
-
(0, helper_js_1.cloneDeep)(pages).forEach((page, pageIndex) => {
|
|
206
|
-
page.children.forEach((child) => {
|
|
207
|
-
const { schema } = child;
|
|
208
|
-
if (!schema)
|
|
209
|
-
throw new Error('[@pdfme/common] schema is undefined');
|
|
210
|
-
const name = schema.name;
|
|
211
|
-
if (!nameToSchemas.has(name)) {
|
|
212
|
-
nameToSchemas.set(name, []);
|
|
213
|
-
}
|
|
214
|
-
nameToSchemas.get(name).push(child);
|
|
215
|
-
const sameNameSchemas = page.children.filter((c) => c.schema?.name === name);
|
|
216
|
-
const start = nameToSchemas.get(name).length - sameNameSchemas.length;
|
|
217
|
-
if (sameNameSchemas.length > 0) {
|
|
218
|
-
if (!sameNameSchemas[0].schema) {
|
|
219
|
-
throw new Error('[@pdfme/common] schema is undefined');
|
|
220
|
-
}
|
|
221
|
-
// Use the first schema to get the schema and position
|
|
222
|
-
const schema = sameNameSchemas[0].schema;
|
|
223
|
-
const height = sameNameSchemas.reduce((acc, cur) => acc + cur.height, 0);
|
|
224
|
-
const position = sameNameSchemas[0].position;
|
|
225
|
-
// Currently, __bodyRange exists for table schemas, but if we make it more abstract,
|
|
226
|
-
// it could be used for other schemas as well to render schemas that have been split by page breaks, starting from the middle.
|
|
227
|
-
schema.__bodyRange = {
|
|
228
|
-
start: Math.max(start - 1, 0),
|
|
229
|
-
end: start + sameNameSchemas.length - 1,
|
|
230
|
-
};
|
|
231
|
-
// Currently, this is used to determine whether to display the header when a table is split.
|
|
232
|
-
schema.__isSplit = start > 0;
|
|
233
|
-
const newSchema = Object.assign({}, schema, { position, height });
|
|
234
|
-
const index = newTemplate.schemas[pageIndex].findIndex((s) => s.name === name);
|
|
235
|
-
if (index !== -1) {
|
|
236
|
-
newTemplate.schemas[pageIndex][index] = newSchema;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
newTemplate.schemas[pageIndex].push(newSchema);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
});
|
|
124
|
+
/** Sort elements within each page by their original order */
|
|
125
|
+
function sortPagesByOrder(pages, orderMap) {
|
|
126
|
+
pages.forEach((page) => {
|
|
127
|
+
page.sort((a, b) => (orderMap.get(a.name) ?? 0) - (orderMap.get(b.name) ?? 0));
|
|
243
128
|
});
|
|
244
|
-
return newTemplate;
|
|
245
129
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const getPageHeight = (pageIndex) => basePdf.height - paddingBottom - (pageIndex > 0 ? paddingTop : 0);
|
|
252
|
-
let yOffset = 0;
|
|
253
|
-
templateSchemas.forEach((schemaPage, pageIndex) => {
|
|
254
|
-
if (pageIndex > 0)
|
|
255
|
-
yOffset += getPageHeight(pageIndex - 1);
|
|
256
|
-
schemaPage.forEach((schema) => {
|
|
257
|
-
const clonedSchema = (0, helper_js_1.cloneDeep)(schema);
|
|
258
|
-
clonedSchema.position = { ...clonedSchema.position, y: clonedSchema.position.y + yOffset };
|
|
259
|
-
flatSchemas.push(clonedSchema);
|
|
260
|
-
if (!orderMap.has(schema.name)) {
|
|
261
|
-
orderMap.set(schema.name, globalOrder++);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
return { flatSchemas, orderMap };
|
|
130
|
+
/** Remove trailing empty pages */
|
|
131
|
+
function removeTrailingEmptyPages(pages) {
|
|
132
|
+
while (pages.length > 1 && pages[pages.length - 1].length === 0) {
|
|
133
|
+
pages.pop();
|
|
134
|
+
}
|
|
266
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Process a single template page that has dynamic content.
|
|
138
|
+
* Uses the same layout algorithm as the original implementation,
|
|
139
|
+
* but scoped to a single page's schemas.
|
|
140
|
+
*/
|
|
141
|
+
function processDynamicPage(items, orderMap, contentHeight, paddingTop) {
|
|
142
|
+
const pages = [];
|
|
143
|
+
let totalYOffset = 0;
|
|
144
|
+
for (const item of items) {
|
|
145
|
+
const currentGlobalStartY = item.baseY + totalYOffset;
|
|
146
|
+
const actualGlobalEndY = placeRowsOnPages(item.schema, item.dynamicHeights, currentGlobalStartY, contentHeight, paddingTop, pages);
|
|
147
|
+
// Update offset: difference between actual and original end position
|
|
148
|
+
const originalGlobalEndY = item.baseY + item.height;
|
|
149
|
+
totalYOffset = actualGlobalEndY - originalGlobalEndY;
|
|
150
|
+
}
|
|
151
|
+
sortPagesByOrder(pages, orderMap);
|
|
152
|
+
removeTrailingEmptyPages(pages);
|
|
153
|
+
return pages;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Process a template containing tables with dynamic heights
|
|
157
|
+
* and generate a new template with proper page breaks.
|
|
158
|
+
*
|
|
159
|
+
* Processing is done page-by-page:
|
|
160
|
+
* - Pages with height changes are processed with full layout calculations
|
|
161
|
+
* - Pages without height changes are copied as-is (no offset propagation between pages)
|
|
162
|
+
*
|
|
163
|
+
* This reduces computation cost by:
|
|
164
|
+
* 1. Limiting layout calculations to pages that need them
|
|
165
|
+
* 2. Avoiding cross-page offset propagation for static pages
|
|
166
|
+
*/
|
|
267
167
|
const getDynamicTemplate = async (arg) => {
|
|
268
|
-
const { template,
|
|
168
|
+
const { template, input, options, _cache, getDynamicHeights } = arg;
|
|
269
169
|
const basePdf = template.basePdf;
|
|
270
170
|
if (!(0, helper_js_1.isBlankPdf)(basePdf)) {
|
|
271
171
|
return template;
|
|
272
172
|
}
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
173
|
+
const contentHeight = getContentHeight(basePdf);
|
|
174
|
+
const paddingTop = basePdf.padding[0];
|
|
175
|
+
const resultPages = [];
|
|
176
|
+
const PARALLEL_LIMIT = 10;
|
|
177
|
+
// Process each template page independently
|
|
178
|
+
for (let pageIndex = 0; pageIndex < template.schemas.length; pageIndex++) {
|
|
179
|
+
const pageSchemas = template.schemas[pageIndex];
|
|
180
|
+
// Normalize this page's schemas
|
|
181
|
+
const { items, orderMap } = normalizePageSchemas(pageSchemas, paddingTop);
|
|
182
|
+
// Calculate dynamic heights for this page's schemas with concurrency limit
|
|
183
|
+
for (let i = 0; i < items.length; i += PARALLEL_LIMIT) {
|
|
184
|
+
const chunk = items.slice(i, i + PARALLEL_LIMIT);
|
|
185
|
+
const chunkResults = await Promise.all(chunk.map((item) => {
|
|
186
|
+
const value = getSchemaValue(item.schema, input);
|
|
187
|
+
return getDynamicHeights(value, {
|
|
188
|
+
schema: item.schema,
|
|
189
|
+
basePdf,
|
|
190
|
+
options,
|
|
191
|
+
_cache,
|
|
192
|
+
}).then((heights) => (heights.length === 0 ? [0] : heights));
|
|
193
|
+
}));
|
|
194
|
+
// Update items with calculated heights
|
|
195
|
+
for (let j = 0; j < chunkResults.length; j++) {
|
|
196
|
+
items[i + j].dynamicHeights = chunkResults[j];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Process all pages independently (no cross-page offset propagation)
|
|
200
|
+
const processedPages = processDynamicPage(items, orderMap, contentHeight, paddingTop);
|
|
201
|
+
resultPages.push(...processedPages);
|
|
202
|
+
}
|
|
203
|
+
removeTrailingEmptyPages(resultPages);
|
|
204
|
+
// Check if anything changed - return original template if not
|
|
205
|
+
if (resultPages.length === template.schemas.length) {
|
|
206
|
+
let unchanged = true;
|
|
207
|
+
for (let i = 0; i < resultPages.length && unchanged; i++) {
|
|
208
|
+
if (resultPages[i].length !== template.schemas[i].length) {
|
|
209
|
+
unchanged = false;
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
for (let j = 0; j < resultPages[i].length && unchanged; j++) {
|
|
213
|
+
const orig = template.schemas[i][j];
|
|
214
|
+
const result = resultPages[i][j];
|
|
215
|
+
if (Math.abs(orig.height - result.height) > EPSILON ||
|
|
216
|
+
Math.abs(orig.position.y - result.position.y) > EPSILON) {
|
|
217
|
+
unchanged = false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (unchanged) {
|
|
222
|
+
return template;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return { basePdf, schemas: resultPages };
|
|
282
226
|
};
|
|
283
227
|
exports.getDynamicTemplate = getDynamicTemplate;
|
|
284
228
|
//# sourceMappingURL=dynamicTemplate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicTemplate.js","sourceRoot":"","sources":["../../../src/dynamicTemplate.ts"],"names":[],"mappings":";;;AACA,2CAAoD;AAkBpD,MAAM,UAAU;IAYd,YAAY,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE;QAX1C;;;;mBAAQ,CAAC;WAAC;QAEV;;;;;WAAgB;QAEhB;;;;mBAAyB,EAAE;WAAC;QAE5B;;;;mBAAQ,CAAC;WAAC;QACV;;;;mBAAS,CAAC;WAAC;QACX;;;;mBAA4C,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CA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G,KAAK,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;AAC3C,CAAC,CAAC;AA1EW,QAAA,kBAAkB,sBA0E7B"}
|
|
@@ -79,7 +79,9 @@ describe('getDynamicTemplate', () => {
|
|
|
79
79
|
expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
|
|
80
80
|
expect(dynamicTemplate.schemas[0][1]).toBeUndefined();
|
|
81
81
|
expect(dynamicTemplate.schemas[1][0].name).toEqual('b');
|
|
82
|
-
|
|
82
|
+
// b maintains its relative offset from a's end position
|
|
83
|
+
// a ends at y=90 (page content), b was 20 units below a, so b is at y=10 in page coords + padding = 20
|
|
84
|
+
expect(dynamicTemplate.schemas[1][0].position.y).toEqual(padding + padding);
|
|
83
85
|
expect(dynamicTemplate.schemas[1][1]).toBeUndefined();
|
|
84
86
|
});
|
|
85
87
|
test('should handle page break with a on page 1 and 2, b on page 2', async () => {
|
|
@@ -174,9 +176,12 @@ describe('getDynamicTemplate', () => {
|
|
|
174
176
|
const dynamicTemplate = await getDynamicTemplate(createGetDynamicTemplateArg(increaseHeights));
|
|
175
177
|
verifyBasicStructure(dynamicTemplate);
|
|
176
178
|
expect(dynamicTemplate.schemas.length).toBe(1);
|
|
179
|
+
// Both schemas are placed; 'a' with height 0, 'b' follows
|
|
177
180
|
expect(dynamicTemplate.schemas[0][0]).toBeDefined();
|
|
178
|
-
expect(dynamicTemplate.schemas[0][0].name).toEqual('
|
|
179
|
-
expect(dynamicTemplate.schemas[0][
|
|
181
|
+
expect(dynamicTemplate.schemas[0][0].name).toEqual('a');
|
|
182
|
+
expect(dynamicTemplate.schemas[0][0].height).toEqual(0);
|
|
183
|
+
expect(dynamicTemplate.schemas[0][1]).toBeDefined();
|
|
184
|
+
expect(dynamicTemplate.schemas[0][1].name).toEqual('b');
|
|
180
185
|
});
|
|
181
186
|
test('should handle very large increase heights', async () => {
|
|
182
187
|
const increaseHeights = [1000, 1000];
|
|
@@ -186,7 +191,10 @@ describe('getDynamicTemplate', () => {
|
|
|
186
191
|
});
|
|
187
192
|
});
|
|
188
193
|
describe('Long page flow (cross-template-page)', () => {
|
|
189
|
-
test('should
|
|
194
|
+
test('should process pages independently - static pages are added as-is without offset propagation', async () => {
|
|
195
|
+
// New behavior: pages without dynamic content are added as-is,
|
|
196
|
+
// without being affected by previous page's table expansion.
|
|
197
|
+
// This reduces computation cost by skipping layout calculations for static pages.
|
|
190
198
|
const templateWithTwoPages = {
|
|
191
199
|
schemas: [
|
|
192
200
|
[
|
|
@@ -219,21 +227,75 @@ describe('getDynamicTemplate', () => {
|
|
|
219
227
|
_cache: new Map(),
|
|
220
228
|
getDynamicHeights: async (value, args) => {
|
|
221
229
|
if (args.schema.type === 'table') {
|
|
222
|
-
return [10, 10, 10, 10];
|
|
230
|
+
return [10, 10, 10, 10]; // 40 total height, will cause page break
|
|
223
231
|
}
|
|
224
232
|
return [args.schema.height];
|
|
225
233
|
},
|
|
226
234
|
});
|
|
227
235
|
verifyBasicStructure(dynamicTemplate);
|
|
228
|
-
|
|
236
|
+
// Page 1: table starts at y=60, with 40 height, will split across pages
|
|
237
|
+
// Page 2: table continuation
|
|
238
|
+
// Page 3: text from template page 2 (added as-is, no offset propagation)
|
|
239
|
+
expect(dynamicTemplate.schemas.length).toBe(3);
|
|
240
|
+
// First page has table
|
|
229
241
|
expect(dynamicTemplate.schemas[0].some((s) => s.name === 'table')).toBe(true);
|
|
242
|
+
// Second page has table continuation
|
|
230
243
|
expect(dynamicTemplate.schemas[1].some((s) => s.name === 'table')).toBe(true);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
expect(
|
|
236
|
-
expect(
|
|
244
|
+
// Third page has text (from template page 2, added as-is)
|
|
245
|
+
expect(dynamicTemplate.schemas[2].some((s) => s.name === 'text')).toBe(true);
|
|
246
|
+
// Text position should be unchanged from template (y=10)
|
|
247
|
+
const textOnPage3 = dynamicTemplate.schemas[2].find((s) => s.name === 'text');
|
|
248
|
+
expect(textOnPage3).toBeDefined();
|
|
249
|
+
expect(textOnPage3.position.y).toBe(10);
|
|
250
|
+
});
|
|
251
|
+
test('should keep static page schemas together with dynamic page when both on same template page', async () => {
|
|
252
|
+
// When table and text are on the SAME template page, they should be processed together
|
|
253
|
+
const templateWithOnePage = {
|
|
254
|
+
schemas: [
|
|
255
|
+
[
|
|
256
|
+
{
|
|
257
|
+
name: 'table',
|
|
258
|
+
content: 'table',
|
|
259
|
+
type: 'table',
|
|
260
|
+
position: { x: 10, y: 10 },
|
|
261
|
+
width: 80,
|
|
262
|
+
height: 10,
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'text',
|
|
266
|
+
content: 'text',
|
|
267
|
+
type: 'text',
|
|
268
|
+
position: { x: 10, y: 30 },
|
|
269
|
+
width: 80,
|
|
270
|
+
height: 10,
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
],
|
|
274
|
+
basePdf: { width: 100, height: 100, padding: [10, 10, 10, 10] },
|
|
275
|
+
};
|
|
276
|
+
const dynamicTemplate = await getDynamicTemplate({
|
|
277
|
+
template: templateWithOnePage,
|
|
278
|
+
input: { table: 'table', text: 'text' },
|
|
279
|
+
options: { font: getSampleFont() },
|
|
280
|
+
_cache: new Map(),
|
|
281
|
+
getDynamicHeights: async (value, args) => {
|
|
282
|
+
if (args.schema.type === 'table') {
|
|
283
|
+
return [10, 10, 10, 10]; // 40 total height
|
|
284
|
+
}
|
|
285
|
+
return [args.schema.height];
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
verifyBasicStructure(dynamicTemplate);
|
|
289
|
+
// Table expands from 10 to 40, pushing text down by 30
|
|
290
|
+
// Both should still fit on one page (table ends at 50, text at 70)
|
|
291
|
+
expect(dynamicTemplate.schemas.length).toBe(1);
|
|
292
|
+
expect(dynamicTemplate.schemas[0].some((s) => s.name === 'table')).toBe(true);
|
|
293
|
+
expect(dynamicTemplate.schemas[0].some((s) => s.name === 'text')).toBe(true);
|
|
294
|
+
const table = dynamicTemplate.schemas[0].find((s) => s.name === 'table');
|
|
295
|
+
const text = dynamicTemplate.schemas[0].find((s) => s.name === 'text');
|
|
296
|
+
expect(table.height).toBe(40);
|
|
297
|
+
// Text should be pushed down: original y=30 + (40-10) offset = 60
|
|
298
|
+
expect(text.position.y).toBe(60);
|
|
237
299
|
});
|
|
238
300
|
});
|
|
239
301
|
});
|