@jsonpdf/renderer 0.1.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +57 -0
- package/dist/anchors.d.ts +13 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.js +37 -0
- package/dist/anchors.js.map +1 -0
- package/dist/band-expander.d.ts +25 -0
- package/dist/band-expander.d.ts.map +1 -0
- package/dist/band-expander.js +193 -0
- package/dist/band-expander.js.map +1 -0
- package/dist/bookmarks.d.ts +22 -0
- package/dist/bookmarks.d.ts.map +1 -0
- package/dist/bookmarks.js +78 -0
- package/dist/bookmarks.js.map +1 -0
- package/dist/columns.d.ts +18 -0
- package/dist/columns.d.ts.map +1 -0
- package/dist/columns.js +31 -0
- package/dist/columns.js.map +1 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +38 -0
- package/dist/context.js.map +1 -0
- package/dist/coordinate.d.ts +14 -0
- package/dist/coordinate.d.ts.map +1 -0
- package/dist/coordinate.js +16 -0
- package/dist/coordinate.js.map +1 -0
- package/dist/data.d.ts +18 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +56 -0
- package/dist/data.js.map +1 -0
- package/dist/expression.d.ts +13 -0
- package/dist/expression.d.ts.map +1 -0
- package/dist/expression.js +90 -0
- package/dist/expression.js.map +1 -0
- package/dist/font-loader.d.ts +8 -0
- package/dist/font-loader.d.ts.map +1 -0
- package/dist/font-loader.js +29 -0
- package/dist/font-loader.js.map +1 -0
- package/dist/fonts.d.ts +19 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +124 -0
- package/dist/fonts.js.map +1 -0
- package/dist/footnotes.d.ts +34 -0
- package/dist/footnotes.d.ts.map +1 -0
- package/dist/footnotes.js +103 -0
- package/dist/footnotes.js.map +1 -0
- package/dist/gradient.d.ts +19 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +176 -0
- package/dist/gradient.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +54 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +680 -0
- package/dist/layout.js.map +1 -0
- package/dist/renderer.d.ts +19 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +570 -0
- package/dist/renderer.js.map +1 -0
- package/dist/style-resolver.d.ts +15 -0
- package/dist/style-resolver.d.ts.map +1 -0
- package/dist/style-resolver.js +39 -0
- package/dist/style-resolver.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAqB,MAAM,cAAc,CAAC;AAEtE,kFAAkF;AAClF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAiDtC,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,IAAgB,EAAE,QAA8B;IAC9E,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO;QACL,GAAG,IAAI;QACP,GAAG,QAAQ;QACX,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE;KAC1D,CAAC;AACJ,CAAC;AAcD;;;GAGG;AACH,SAAS,uBAAuB,CAC9B,KAAc,EACd,MAA6B,EAC7B,YAAmB,EACnB,SAAmC,EACnC,MAAmB,EACnB,UAAsB,EACtB,IAAqB;IA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;QAC1F,CAAC;IACH,CAAC;IAED,qBAAqB;IACrB,MAAM,SAAS,GAAG,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAC/E,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC9B,YAAY,EAAE,CAAC;IAEf,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Template } from '@jsonpdf/core';
|
|
2
|
+
import { PluginRegistry } from '@jsonpdf/plugins';
|
|
3
|
+
export interface RenderOptions {
|
|
4
|
+
/** Skip template validation. */
|
|
5
|
+
skipValidation?: boolean;
|
|
6
|
+
/** Input data for template expressions. */
|
|
7
|
+
data?: Record<string, unknown>;
|
|
8
|
+
/** Custom plugin registry. If not provided, a default registry with built-in plugins is used. */
|
|
9
|
+
registry?: PluginRegistry;
|
|
10
|
+
}
|
|
11
|
+
export interface RenderResult {
|
|
12
|
+
/** PDF file bytes. */
|
|
13
|
+
bytes: Uint8Array;
|
|
14
|
+
/** Number of pages rendered. */
|
|
15
|
+
pageCount: number;
|
|
16
|
+
}
|
|
17
|
+
/** Render a template to PDF bytes. */
|
|
18
|
+
export declare function renderPdf(template: Template, options?: RenderOptions): Promise<RenderResult>;
|
|
19
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAA8C,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI1F,OAAO,EACL,cAAc,EAaf,MAAM,kBAAkB,CAAC;AAc1B,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,iGAAiG;IACjG,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC3B,sBAAsB;IACtB,KAAK,EAAE,UAAU,CAAC;IAClB,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB;AAsgBD,sCAAsC;AACtC,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CA2PvB"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
import { PDFDocument, rgb, pushGraphicsState, popGraphicsState, rotateDegrees, translate, } from 'pdf-lib';
|
|
2
|
+
import fontkit from '@pdf-lib/fontkit';
|
|
3
|
+
import { parseColor, isGradient, validateTemplateSchema } from '@jsonpdf/core';
|
|
4
|
+
import { PluginRegistry, textPlugin, linePlugin, listPlugin, shapePlugin, imagePlugin, containerPlugin, tablePlugin, barcodePlugin, chartPlugin, framePlugin, createImageCache, roundedRectPath, } from '@jsonpdf/plugins';
|
|
5
|
+
import { embedFonts, collectFontSpecs } from './fonts.js';
|
|
6
|
+
import { layoutTemplate, mergePageConfig, MAX_CONTAINER_DEPTH } from './layout.js';
|
|
7
|
+
import { createMeasureContext } from './context.js';
|
|
8
|
+
import { templateToPdf } from './coordinate.js';
|
|
9
|
+
import { createExpressionEngine } from './expression.js';
|
|
10
|
+
import { validateData, applySchemaDefaults } from './data.js';
|
|
11
|
+
import { expandBands } from './band-expander.js';
|
|
12
|
+
import { collectAnchors } from './anchors.js';
|
|
13
|
+
import { buildPdfOutline } from './bookmarks.js';
|
|
14
|
+
import { resolveElementStyle, resolveNamedStyle, normalizePadding } from './style-resolver.js';
|
|
15
|
+
import { drawGradientRect } from './gradient.js';
|
|
16
|
+
import { renderFootnotes, measureFootnoteHeight } from './footnotes.js';
|
|
17
|
+
/**
|
|
18
|
+
* Create a measureBands callback for frame elements during the render pass.
|
|
19
|
+
* Expands the frame's bands and measures each expanded content band.
|
|
20
|
+
*/
|
|
21
|
+
function createRenderMeasureBands(env, scope) {
|
|
22
|
+
return async (bands) => {
|
|
23
|
+
const pseudoSection = { id: '__frame', bands };
|
|
24
|
+
const totalPages = Number(scope._totalPages) || 0;
|
|
25
|
+
const expanded = await expandBands(pseudoSection, scope, env.engine, totalPages);
|
|
26
|
+
let totalHeight = 0;
|
|
27
|
+
for (const instance of expanded.contentBands) {
|
|
28
|
+
const m = await measureBandForFrame(instance.band, env, instance.scope);
|
|
29
|
+
totalHeight += m.height;
|
|
30
|
+
}
|
|
31
|
+
return { totalHeight };
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Measure a band's height for frame rendering (with expression resolution). */
|
|
35
|
+
async function measureBandForFrame(band, env, scope) {
|
|
36
|
+
const elementHeights = new Map();
|
|
37
|
+
let bandHeight = band.height;
|
|
38
|
+
if (band.autoHeight) {
|
|
39
|
+
let maxElementBottom = band.height;
|
|
40
|
+
for (const element of band.elements) {
|
|
41
|
+
const plugin = env.registry.get(element.type);
|
|
42
|
+
// Protect frame bands from Liquid resolution (same pattern as renderElementAtPosition)
|
|
43
|
+
let nestedFrameBands;
|
|
44
|
+
if (element.type === 'frame' && Array.isArray(element.properties.bands)) {
|
|
45
|
+
nestedFrameBands = element.properties.bands;
|
|
46
|
+
}
|
|
47
|
+
const resolvedProperties = await env.engine.resolveProps(element.properties, scope);
|
|
48
|
+
if (nestedFrameBands) {
|
|
49
|
+
resolvedProperties.bands = nestedFrameBands;
|
|
50
|
+
}
|
|
51
|
+
const props = plugin.resolveProps(resolvedProperties);
|
|
52
|
+
const measureCtx = createMeasureContext(element, env.fonts, env.styles, env.defaultStyle, env.doc, env.imageCache);
|
|
53
|
+
if (element.elements?.length) {
|
|
54
|
+
measureCtx.children = element.elements;
|
|
55
|
+
measureCtx.measureChild = createMeasureChildCallback(env, scope, 0);
|
|
56
|
+
}
|
|
57
|
+
if (element.type === 'frame') {
|
|
58
|
+
measureCtx.measureBands = createRenderMeasureBands(env, scope);
|
|
59
|
+
}
|
|
60
|
+
const measured = await plugin.measure(props, measureCtx);
|
|
61
|
+
const padding = normalizePadding(resolveElementStyle(element, env.styles, env.defaultStyle).padding);
|
|
62
|
+
const totalElementHeight = measured.height + padding.top + padding.bottom;
|
|
63
|
+
elementHeights.set(element.id, totalElementHeight);
|
|
64
|
+
const elementBottom = element.y + totalElementHeight;
|
|
65
|
+
maxElementBottom = Math.max(maxElementBottom, elementBottom);
|
|
66
|
+
}
|
|
67
|
+
bandHeight = maxElementBottom;
|
|
68
|
+
}
|
|
69
|
+
return { height: bandHeight, elementHeights };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a measureChild callback for container elements.
|
|
73
|
+
* Recursively supports nested containers.
|
|
74
|
+
*/
|
|
75
|
+
function createMeasureChildCallback(env, scope, depth) {
|
|
76
|
+
const callback = async (childEl) => {
|
|
77
|
+
if (depth + 1 > MAX_CONTAINER_DEPTH) {
|
|
78
|
+
throw new Error('Maximum container nesting depth exceeded');
|
|
79
|
+
}
|
|
80
|
+
const resolvedProperties = await env.engine.resolveProps(childEl.properties, scope);
|
|
81
|
+
const plugin = env.registry.get(childEl.type);
|
|
82
|
+
const props = plugin.resolveProps(resolvedProperties);
|
|
83
|
+
const measureCtx = createMeasureContext(childEl, env.fonts, env.styles, env.defaultStyle, env.doc, env.imageCache);
|
|
84
|
+
if (childEl.elements?.length) {
|
|
85
|
+
measureCtx.children = childEl.elements;
|
|
86
|
+
measureCtx.measureChild = createMeasureChildCallback(env, scope, depth + 1);
|
|
87
|
+
}
|
|
88
|
+
// Provide measureBands callback for frame elements
|
|
89
|
+
if (childEl.type === 'frame') {
|
|
90
|
+
measureCtx.measureBands = createRenderMeasureBands(env, scope);
|
|
91
|
+
}
|
|
92
|
+
return plugin.measure(props, measureCtx);
|
|
93
|
+
};
|
|
94
|
+
return callback;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Draw element-level background and borders.
|
|
98
|
+
* Called BEFORE plugin.render() so backgrounds/borders appear behind content.
|
|
99
|
+
*
|
|
100
|
+
* @param page - The pdf-lib page
|
|
101
|
+
* @param pdfX - Left edge in pdf-lib coordinates
|
|
102
|
+
* @param pdfY - Top edge in pdf-lib coordinates (Y increases upward)
|
|
103
|
+
* @param width - Element width
|
|
104
|
+
* @param height - Element height
|
|
105
|
+
* @param style - Resolved element style
|
|
106
|
+
*/
|
|
107
|
+
function drawElementBordersAndBackground(page, doc, pdfX, pdfY, width, height, style) {
|
|
108
|
+
const opacity = style.opacity;
|
|
109
|
+
const hasBorderRadius = (style.borderRadius ?? 0) > 0;
|
|
110
|
+
const hasIndividualBorders = !!(style.borderTop ||
|
|
111
|
+
style.borderRight ||
|
|
112
|
+
style.borderBottom ||
|
|
113
|
+
style.borderLeft);
|
|
114
|
+
// 1. Background
|
|
115
|
+
if (style.backgroundColor) {
|
|
116
|
+
if (isGradient(style.backgroundColor)) {
|
|
117
|
+
// Gradient fill — bottom-left coordinates for drawGradientRect
|
|
118
|
+
drawGradientRect(page, doc, pdfX, pdfY - height, width, height, style.backgroundColor, opacity);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const bg = parseColor(style.backgroundColor);
|
|
122
|
+
const bgColor = rgb(bg.r, bg.g, bg.b);
|
|
123
|
+
if (hasBorderRadius) {
|
|
124
|
+
const path = roundedRectPath(width, height, style.borderRadius ?? 0);
|
|
125
|
+
page.drawSvgPath(path, {
|
|
126
|
+
x: pdfX,
|
|
127
|
+
y: pdfY,
|
|
128
|
+
color: bgColor,
|
|
129
|
+
opacity,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
page.drawRectangle({
|
|
134
|
+
x: pdfX,
|
|
135
|
+
y: pdfY - height,
|
|
136
|
+
width,
|
|
137
|
+
height,
|
|
138
|
+
color: bgColor,
|
|
139
|
+
opacity,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// 2. Uniform border (skipped when individual borders are defined — they take precedence)
|
|
145
|
+
if ((style.borderWidth ?? 0) > 0 && !hasBorderRadius && !hasIndividualBorders) {
|
|
146
|
+
const borderColor = style.borderColor ? parseColor(style.borderColor) : { r: 0, g: 0, b: 0 };
|
|
147
|
+
page.drawRectangle({
|
|
148
|
+
x: pdfX,
|
|
149
|
+
y: pdfY - height,
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
borderColor: rgb(borderColor.r, borderColor.g, borderColor.b),
|
|
153
|
+
borderWidth: style.borderWidth,
|
|
154
|
+
opacity: 0,
|
|
155
|
+
borderOpacity: opacity,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
// 2b. Uniform border with borderRadius (skipped when individual borders are defined)
|
|
159
|
+
if ((style.borderWidth ?? 0) > 0 && hasBorderRadius && !hasIndividualBorders) {
|
|
160
|
+
const borderColor = style.borderColor ? parseColor(style.borderColor) : { r: 0, g: 0, b: 0 };
|
|
161
|
+
const path = roundedRectPath(width, height, style.borderRadius ?? 0);
|
|
162
|
+
page.drawSvgPath(path, {
|
|
163
|
+
x: pdfX,
|
|
164
|
+
y: pdfY,
|
|
165
|
+
borderColor: rgb(borderColor.r, borderColor.g, borderColor.b),
|
|
166
|
+
borderWidth: style.borderWidth,
|
|
167
|
+
borderOpacity: opacity,
|
|
168
|
+
opacity: 0,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// 3. Individual borders (skipped when borderRadius is set — CSS behavior)
|
|
172
|
+
if (!hasBorderRadius) {
|
|
173
|
+
const top = pdfY;
|
|
174
|
+
const bottom = pdfY - height;
|
|
175
|
+
const left = pdfX;
|
|
176
|
+
const right = pdfX + width;
|
|
177
|
+
if (style.borderTop && style.borderTop.width > 0) {
|
|
178
|
+
const c = parseColor(style.borderTop.color ?? style.borderColor ?? '#000000');
|
|
179
|
+
page.drawLine({
|
|
180
|
+
start: { x: left, y: top },
|
|
181
|
+
end: { x: right, y: top },
|
|
182
|
+
thickness: style.borderTop.width,
|
|
183
|
+
color: rgb(c.r, c.g, c.b),
|
|
184
|
+
opacity,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (style.borderBottom && style.borderBottom.width > 0) {
|
|
188
|
+
const c = parseColor(style.borderBottom.color ?? style.borderColor ?? '#000000');
|
|
189
|
+
page.drawLine({
|
|
190
|
+
start: { x: left, y: bottom },
|
|
191
|
+
end: { x: right, y: bottom },
|
|
192
|
+
thickness: style.borderBottom.width,
|
|
193
|
+
color: rgb(c.r, c.g, c.b),
|
|
194
|
+
opacity,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (style.borderLeft && style.borderLeft.width > 0) {
|
|
198
|
+
const c = parseColor(style.borderLeft.color ?? style.borderColor ?? '#000000');
|
|
199
|
+
page.drawLine({
|
|
200
|
+
start: { x: left, y: bottom },
|
|
201
|
+
end: { x: left, y: top },
|
|
202
|
+
thickness: style.borderLeft.width,
|
|
203
|
+
color: rgb(c.r, c.g, c.b),
|
|
204
|
+
opacity,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (style.borderRight && style.borderRight.width > 0) {
|
|
208
|
+
const c = parseColor(style.borderRight.color ?? style.borderColor ?? '#000000');
|
|
209
|
+
page.drawLine({
|
|
210
|
+
start: { x: right, y: bottom },
|
|
211
|
+
end: { x: right, y: top },
|
|
212
|
+
thickness: style.borderRight.width,
|
|
213
|
+
color: rgb(c.r, c.g, c.b),
|
|
214
|
+
opacity,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Render a single element at a given position in pdf-lib coordinates.
|
|
221
|
+
*
|
|
222
|
+
* Handles: condition evaluation, expression resolution, conditional styles,
|
|
223
|
+
* plugin resolution, child callbacks for containers, rotation, and rendering.
|
|
224
|
+
*
|
|
225
|
+
* @param pdfX - Left edge in pdf-lib coordinates (before element padding)
|
|
226
|
+
* @param pdfY - Top edge in pdf-lib coordinates (before element padding)
|
|
227
|
+
*/
|
|
228
|
+
async function renderElementAtPosition(element, scope, page, pdfX, pdfY, env, measuredHeight, depth = 0) {
|
|
229
|
+
if (depth > MAX_CONTAINER_DEPTH) {
|
|
230
|
+
throw new Error('Maximum container nesting depth exceeded');
|
|
231
|
+
}
|
|
232
|
+
// 1. Evaluate condition
|
|
233
|
+
if (element.condition) {
|
|
234
|
+
const show = await env.engine.evaluate(element.condition, scope);
|
|
235
|
+
if (!show)
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// 2. Resolve expressions in properties (protect frame bands from Liquid resolution)
|
|
239
|
+
let frameBands;
|
|
240
|
+
if (element.type === 'frame' && Array.isArray(element.properties.bands)) {
|
|
241
|
+
frameBands = element.properties.bands;
|
|
242
|
+
}
|
|
243
|
+
const resolvedProperties = await env.engine.resolveProps(element.properties, scope);
|
|
244
|
+
if (frameBands) {
|
|
245
|
+
resolvedProperties.bands = frameBands;
|
|
246
|
+
}
|
|
247
|
+
// 3. Apply conditional styles
|
|
248
|
+
let effectiveElement = element;
|
|
249
|
+
if (element.conditionalStyles?.length) {
|
|
250
|
+
let mergedOverrides = { ...(element.styleOverrides ?? {}) };
|
|
251
|
+
let mergedStyleName = element.style;
|
|
252
|
+
for (const cs of element.conditionalStyles) {
|
|
253
|
+
const matches = await env.engine.evaluate(cs.condition, scope);
|
|
254
|
+
if (matches) {
|
|
255
|
+
if (cs.style)
|
|
256
|
+
mergedStyleName = cs.style;
|
|
257
|
+
if (cs.styleOverrides)
|
|
258
|
+
mergedOverrides = { ...mergedOverrides, ...cs.styleOverrides };
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
effectiveElement = {
|
|
262
|
+
...element,
|
|
263
|
+
style: mergedStyleName,
|
|
264
|
+
styleOverrides: mergedOverrides,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
// 4. Plugin resolution and validation
|
|
268
|
+
const plugin = env.registry.get(effectiveElement.type);
|
|
269
|
+
const props = plugin.resolveProps(resolvedProperties);
|
|
270
|
+
const propErrors = plugin.validate(props);
|
|
271
|
+
if (propErrors.length > 0) {
|
|
272
|
+
const messages = propErrors.map((e) => `${e.path}: ${e.message}`).join('; ');
|
|
273
|
+
throw new Error(`Invalid properties for ${effectiveElement.type} element "${effectiveElement.id}": ${messages}`);
|
|
274
|
+
}
|
|
275
|
+
// 5. Compute style and padding
|
|
276
|
+
const elementStyle = resolveElementStyle(effectiveElement, env.styles, env.defaultStyle);
|
|
277
|
+
const padding = normalizePadding(elementStyle.padding);
|
|
278
|
+
const height = measuredHeight ?? effectiveElement.height;
|
|
279
|
+
// 6. Build render context
|
|
280
|
+
const renderCtx = {
|
|
281
|
+
fonts: env.fonts,
|
|
282
|
+
availableWidth: effectiveElement.width - padding.left - padding.right,
|
|
283
|
+
availableHeight: height - padding.top - padding.bottom,
|
|
284
|
+
resolveStyle: (name) => resolveNamedStyle(name, env.styles, env.defaultStyle),
|
|
285
|
+
elementStyle,
|
|
286
|
+
pdfDoc: env.doc,
|
|
287
|
+
imageCache: env.imageCache,
|
|
288
|
+
page,
|
|
289
|
+
x: pdfX + padding.left,
|
|
290
|
+
y: pdfY - padding.top,
|
|
291
|
+
width: effectiveElement.width - padding.left - padding.right,
|
|
292
|
+
height: height - padding.top - padding.bottom,
|
|
293
|
+
anchorPageMap: env.anchorPageMap,
|
|
294
|
+
opacity: elementStyle.opacity,
|
|
295
|
+
footnoteMarker: env.footnoteMarker,
|
|
296
|
+
};
|
|
297
|
+
// 7. Add child callbacks for container elements
|
|
298
|
+
if (effectiveElement.elements?.length) {
|
|
299
|
+
renderCtx.children = effectiveElement.elements;
|
|
300
|
+
renderCtx.measureChild = createMeasureChildCallback(env, scope, depth);
|
|
301
|
+
renderCtx.renderChild = async (childEl, offsetX, offsetY) => {
|
|
302
|
+
// Child position in pdf-lib coords relative to the container's content area
|
|
303
|
+
const childPdfX = renderCtx.x + offsetX;
|
|
304
|
+
const childPdfY = renderCtx.y - offsetY;
|
|
305
|
+
// Measure child for correct height (protect frame bands from Liquid resolution)
|
|
306
|
+
const childPlugin = env.registry.get(childEl.type);
|
|
307
|
+
let childFrameBands;
|
|
308
|
+
if (childEl.type === 'frame' && Array.isArray(childEl.properties.bands)) {
|
|
309
|
+
childFrameBands = childEl.properties.bands;
|
|
310
|
+
}
|
|
311
|
+
const childResolvedProps = await env.engine.resolveProps(childEl.properties, scope);
|
|
312
|
+
if (childFrameBands) {
|
|
313
|
+
childResolvedProps.bands = childFrameBands;
|
|
314
|
+
}
|
|
315
|
+
const childProps = childPlugin.resolveProps(childResolvedProps);
|
|
316
|
+
const childMeasureCtx = createMeasureContext(childEl, env.fonts, env.styles, env.defaultStyle, env.doc, env.imageCache);
|
|
317
|
+
if (childEl.elements?.length) {
|
|
318
|
+
childMeasureCtx.children = childEl.elements;
|
|
319
|
+
childMeasureCtx.measureChild = createMeasureChildCallback(env, scope, depth + 1);
|
|
320
|
+
}
|
|
321
|
+
if (childEl.type === 'frame') {
|
|
322
|
+
childMeasureCtx.measureBands = createRenderMeasureBands(env, scope);
|
|
323
|
+
}
|
|
324
|
+
const measured = await childPlugin.measure(childProps, childMeasureCtx);
|
|
325
|
+
const childPadding = normalizePadding(resolveElementStyle(childEl, env.styles, env.defaultStyle).padding);
|
|
326
|
+
const childMeasuredHeight = measured.height + childPadding.top + childPadding.bottom;
|
|
327
|
+
await renderElementAtPosition(childEl, scope, page, childPdfX, childPdfY, env, childMeasuredHeight, depth + 1);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
// 7b. Add frame callbacks for frame elements
|
|
331
|
+
if (effectiveElement.type === 'frame') {
|
|
332
|
+
renderCtx.measureBands = createRenderMeasureBands(env, scope);
|
|
333
|
+
renderCtx.renderBands = async (bands) => {
|
|
334
|
+
const pseudoSection = { id: '__frame', bands };
|
|
335
|
+
const totalPages = Number(scope._totalPages) || 0;
|
|
336
|
+
const expanded = await expandBands(pseudoSection, scope, env.engine, totalPages);
|
|
337
|
+
let cursorY = 0;
|
|
338
|
+
for (const instance of expanded.contentBands) {
|
|
339
|
+
const bandM = await measureBandForFrame(instance.band, env, instance.scope);
|
|
340
|
+
for (const el of instance.band.elements) {
|
|
341
|
+
const elMeasuredH = bandM.elementHeights.get(el.id);
|
|
342
|
+
const elPdfX = renderCtx.x + el.x;
|
|
343
|
+
const elPdfY = renderCtx.y - cursorY - el.y;
|
|
344
|
+
await renderElementAtPosition(el, instance.scope, page, elPdfX, elPdfY, env, elMeasuredH, depth + 1);
|
|
345
|
+
}
|
|
346
|
+
cursorY += bandM.height;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
// 8. Apply rotation transform
|
|
351
|
+
const rotation = effectiveElement.rotation;
|
|
352
|
+
if (rotation) {
|
|
353
|
+
const centerX = pdfX + effectiveElement.width / 2;
|
|
354
|
+
const centerY = pdfY - height / 2;
|
|
355
|
+
page.pushOperators(pushGraphicsState(), translate(centerX, centerY), rotateDegrees(-rotation), translate(-centerX, -centerY));
|
|
356
|
+
}
|
|
357
|
+
// 8b. Draw element-level background and borders (behind content)
|
|
358
|
+
drawElementBordersAndBackground(page, env.doc, pdfX, pdfY, effectiveElement.width, height, elementStyle);
|
|
359
|
+
// 9. Render
|
|
360
|
+
await plugin.render(props, renderCtx);
|
|
361
|
+
// 10. Restore graphics state
|
|
362
|
+
if (rotation) {
|
|
363
|
+
page.pushOperators(popGraphicsState());
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/** Memoize plugin schema list per registry so buildPluginAwareTemplateSchema cache hits. */
|
|
367
|
+
const registrySchemaCache = new WeakMap();
|
|
368
|
+
function getPluginSchemas(registry) {
|
|
369
|
+
let schemas = registrySchemaCache.get(registry);
|
|
370
|
+
if (!schemas) {
|
|
371
|
+
schemas = registry.getAll().map((p) => ({ type: p.type, propsSchema: p.propsSchema }));
|
|
372
|
+
registrySchemaCache.set(registry, schemas);
|
|
373
|
+
}
|
|
374
|
+
return schemas;
|
|
375
|
+
}
|
|
376
|
+
/** Create a default plugin registry with all built-in plugins. */
|
|
377
|
+
function createDefaultRegistry() {
|
|
378
|
+
const registry = new PluginRegistry();
|
|
379
|
+
registry.register(textPlugin);
|
|
380
|
+
registry.register(linePlugin);
|
|
381
|
+
registry.register(listPlugin);
|
|
382
|
+
registry.register(shapePlugin);
|
|
383
|
+
registry.register(imagePlugin);
|
|
384
|
+
registry.register(containerPlugin);
|
|
385
|
+
registry.register(tablePlugin);
|
|
386
|
+
registry.register(barcodePlugin);
|
|
387
|
+
registry.register(chartPlugin);
|
|
388
|
+
registry.register(framePlugin);
|
|
389
|
+
return registry;
|
|
390
|
+
}
|
|
391
|
+
/** Render a template to PDF bytes. */
|
|
392
|
+
export async function renderPdf(template, options) {
|
|
393
|
+
// 1. Set up plugin registry (needed for schema validation)
|
|
394
|
+
const registry = options?.registry ?? createDefaultRegistry();
|
|
395
|
+
// 2. Validate template schema (including plugin property schemas)
|
|
396
|
+
if (!options?.skipValidation) {
|
|
397
|
+
const pluginSchemas = getPluginSchemas(registry);
|
|
398
|
+
const validation = validateTemplateSchema(template, pluginSchemas);
|
|
399
|
+
if (!validation.valid) {
|
|
400
|
+
const messages = validation.errors.map((e) => ` ${e.path}: ${e.message}`).join('\n');
|
|
401
|
+
throw new Error(`Template validation failed:\n${messages}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
// 3. Validate data against dataSchema and apply defaults
|
|
405
|
+
let data = options?.data ?? {};
|
|
406
|
+
validateData(data, template.dataSchema);
|
|
407
|
+
data = applySchemaDefaults(data, template.dataSchema);
|
|
408
|
+
// 4. Create PDF document
|
|
409
|
+
const doc = await PDFDocument.create();
|
|
410
|
+
// 5. Register fontkit for custom font embedding
|
|
411
|
+
if (template.fonts.length > 0) {
|
|
412
|
+
doc.registerFontkit(fontkit);
|
|
413
|
+
}
|
|
414
|
+
// 6. Create expression engine
|
|
415
|
+
const engine = createExpressionEngine();
|
|
416
|
+
// 7. Collect and embed fonts
|
|
417
|
+
const fontSpecs = collectFontSpecs(template);
|
|
418
|
+
const fonts = await embedFonts(doc, fontSpecs, template.fonts);
|
|
419
|
+
// 8. Layout helpers
|
|
420
|
+
const getPlugin = (type) => registry.get(type);
|
|
421
|
+
const imageCache = createImageCache();
|
|
422
|
+
// 9. Pass 1: measure layout to determine total page count and anchors
|
|
423
|
+
const measureLayout = await layoutTemplate(template, fonts, getPlugin, engine, data, 0, doc, imageCache);
|
|
424
|
+
// 9b. Collect cross-reference anchors and register ref filter
|
|
425
|
+
const anchorMap = collectAnchors(measureLayout);
|
|
426
|
+
engine.registerFilter('ref', (anchorId) => {
|
|
427
|
+
return anchorMap.get(String(anchorId)) ?? '??';
|
|
428
|
+
});
|
|
429
|
+
// 9c. Inject _bookmarks from pass 1 for TOC data source
|
|
430
|
+
const dataWithBookmarks = {
|
|
431
|
+
...data,
|
|
432
|
+
_bookmarks: measureLayout.bookmarks,
|
|
433
|
+
};
|
|
434
|
+
// 10. Pass 2: layout with correct totalPages, _bookmarks, and ref filter
|
|
435
|
+
const layout = await layoutTemplate(template, fonts, getPlugin, engine, dataWithBookmarks, measureLayout.totalPages, doc, imageCache);
|
|
436
|
+
const pdfPages = [];
|
|
437
|
+
for (const layoutPage of layout.pages) {
|
|
438
|
+
const section = template.sections[layoutPage.sectionIndex];
|
|
439
|
+
const pageConfig = mergePageConfig(template.page, section.page);
|
|
440
|
+
const pageHeight = layoutPage.computedHeight ?? pageConfig.height;
|
|
441
|
+
const page = doc.addPage([pageConfig.width, pageHeight]);
|
|
442
|
+
pdfPages.push({ page, layoutPage, pageConfig, pageHeight });
|
|
443
|
+
}
|
|
444
|
+
// 11b. Build anchor-to-PDFPage map for internal links
|
|
445
|
+
// Uses pass 2 layout so page positions reflect expanded _bookmarks detail bands.
|
|
446
|
+
// Bookmark-derived anchors (from section/band ids) are merged for TOC links.
|
|
447
|
+
const linkAnchorMap = collectAnchors(layout, { warnOnDuplicates: true });
|
|
448
|
+
for (const bk of layout.bookmarks) {
|
|
449
|
+
if (!linkAnchorMap.has(bk.anchorId)) {
|
|
450
|
+
linkAnchorMap.set(bk.anchorId, bk.pageNumber);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const anchorPageMap = new Map();
|
|
454
|
+
for (const [anchorId, pageNum] of linkAnchorMap) {
|
|
455
|
+
anchorPageMap.set(anchorId, pdfPages[pageNum - 1].page);
|
|
456
|
+
}
|
|
457
|
+
// 12. Render pages
|
|
458
|
+
const env = {
|
|
459
|
+
engine,
|
|
460
|
+
registry,
|
|
461
|
+
fonts,
|
|
462
|
+
styles: template.styles,
|
|
463
|
+
defaultStyle: template.defaultStyle,
|
|
464
|
+
doc,
|
|
465
|
+
imageCache,
|
|
466
|
+
anchorPageMap,
|
|
467
|
+
};
|
|
468
|
+
const bookmarkEntries = [];
|
|
469
|
+
let lastSectionIndex = -1;
|
|
470
|
+
for (const { page, layoutPage, pageConfig, pageHeight } of pdfPages) {
|
|
471
|
+
// Set up per-page footnote collection
|
|
472
|
+
const pageFootnotes = [];
|
|
473
|
+
let footnoteCounter = 0;
|
|
474
|
+
env.footnoteMarker = (content) => {
|
|
475
|
+
footnoteCounter++;
|
|
476
|
+
pageFootnotes.push({ number: footnoteCounter, content });
|
|
477
|
+
return footnoteCounter;
|
|
478
|
+
};
|
|
479
|
+
// Section bookmark (only on first page of each section)
|
|
480
|
+
if (layoutPage.sectionIndex !== lastSectionIndex) {
|
|
481
|
+
const section = template.sections[layoutPage.sectionIndex];
|
|
482
|
+
if (section.bookmark) {
|
|
483
|
+
const scope = layoutPage.bands.length > 0 ? layoutPage.bands[0].scope : {};
|
|
484
|
+
const title = await engine.resolve(section.bookmark, scope);
|
|
485
|
+
bookmarkEntries.push({
|
|
486
|
+
title,
|
|
487
|
+
page,
|
|
488
|
+
top: pageHeight,
|
|
489
|
+
left: 0,
|
|
490
|
+
level: 0,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
lastSectionIndex = layoutPage.sectionIndex;
|
|
495
|
+
for (const layoutBand of layoutPage.bands) {
|
|
496
|
+
// Compute column-aware effective values
|
|
497
|
+
const effectiveMarginLeft = pageConfig.margins.left + (layoutBand.columnOffsetX ?? 0);
|
|
498
|
+
const effectiveContentWidth = layoutBand.columnWidth ??
|
|
499
|
+
pageConfig.width - pageConfig.margins.left - pageConfig.margins.right;
|
|
500
|
+
// Band bookmark
|
|
501
|
+
if (layoutBand.band.bookmark) {
|
|
502
|
+
const title = await engine.resolve(layoutBand.band.bookmark, layoutBand.scope);
|
|
503
|
+
const pdfY = pageHeight - pageConfig.margins.top - layoutBand.offsetY;
|
|
504
|
+
bookmarkEntries.push({
|
|
505
|
+
title,
|
|
506
|
+
page,
|
|
507
|
+
top: pdfY,
|
|
508
|
+
left: effectiveMarginLeft,
|
|
509
|
+
level: 1,
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
// Draw band background
|
|
513
|
+
if (layoutBand.band.backgroundColor) {
|
|
514
|
+
const bgY = pageHeight - pageConfig.margins.top - layoutBand.offsetY - layoutBand.measuredHeight;
|
|
515
|
+
if (isGradient(layoutBand.band.backgroundColor)) {
|
|
516
|
+
drawGradientRect(page, doc, effectiveMarginLeft, bgY, effectiveContentWidth, layoutBand.measuredHeight, layoutBand.band.backgroundColor);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
const bgColor = parseColor(layoutBand.band.backgroundColor);
|
|
520
|
+
page.drawRectangle({
|
|
521
|
+
x: effectiveMarginLeft,
|
|
522
|
+
y: bgY,
|
|
523
|
+
width: effectiveContentWidth,
|
|
524
|
+
height: layoutBand.measuredHeight,
|
|
525
|
+
color: rgb(bgColor.r, bgColor.g, bgColor.b),
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// Render elements
|
|
530
|
+
for (const element of layoutBand.band.elements) {
|
|
531
|
+
const measuredHeight = layoutBand.elementHeights.get(element.id);
|
|
532
|
+
const { x: pdfX, y: pdfY } = templateToPdf(element.x, layoutBand.offsetY + element.y, pageHeight, pageConfig.margins.top, effectiveMarginLeft);
|
|
533
|
+
await renderElementAtPosition(element, layoutBand.scope, page, pdfX, pdfY, env, measuredHeight);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// Render footnotes at page bottom (above page footer)
|
|
537
|
+
if (pageFootnotes.length > 0) {
|
|
538
|
+
// Find the lowest non-footer band to determine where footnotes start
|
|
539
|
+
// Footnotes render above the page footer area
|
|
540
|
+
const footerBandTypes = new Set(['pageFooter', 'lastPageFooter']);
|
|
541
|
+
let footerTopY = pageConfig.margins.bottom; // fallback: bottom margin
|
|
542
|
+
for (const lb of layoutPage.bands) {
|
|
543
|
+
if (footerBandTypes.has(lb.band.type)) {
|
|
544
|
+
const bandBottomPdf = pageHeight - pageConfig.margins.top - lb.offsetY;
|
|
545
|
+
if (bandBottomPdf > footerTopY) {
|
|
546
|
+
footerTopY = bandBottomPdf;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// Measure footnote height and position just above the footer
|
|
551
|
+
const footnoteStyle = { ...env.defaultStyle, fontSize: 12 };
|
|
552
|
+
const marginLeft = pageConfig.margins.left;
|
|
553
|
+
const contentWidth = pageConfig.width - pageConfig.margins.left - pageConfig.margins.right;
|
|
554
|
+
const fnHeight = measureFootnoteHeight(pageFootnotes, footnoteStyle, env.fonts, contentWidth);
|
|
555
|
+
const fnY = footerTopY + fnHeight;
|
|
556
|
+
renderFootnotes(page, pageFootnotes, marginLeft, fnY, contentWidth, footnoteStyle, env.fonts);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
// 12. Build PDF outline from collected bookmarks
|
|
560
|
+
if (bookmarkEntries.length > 0) {
|
|
561
|
+
buildPdfOutline(doc, bookmarkEntries);
|
|
562
|
+
}
|
|
563
|
+
// 13. Save
|
|
564
|
+
const bytes = await doc.save();
|
|
565
|
+
return {
|
|
566
|
+
bytes,
|
|
567
|
+
pageCount: layout.totalPages,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
//# sourceMappingURL=renderer.js.map
|