@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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -0
  3. package/dist/anchors.d.ts +13 -0
  4. package/dist/anchors.d.ts.map +1 -0
  5. package/dist/anchors.js +37 -0
  6. package/dist/anchors.js.map +1 -0
  7. package/dist/band-expander.d.ts +25 -0
  8. package/dist/band-expander.d.ts.map +1 -0
  9. package/dist/band-expander.js +193 -0
  10. package/dist/band-expander.js.map +1 -0
  11. package/dist/bookmarks.d.ts +22 -0
  12. package/dist/bookmarks.d.ts.map +1 -0
  13. package/dist/bookmarks.js +78 -0
  14. package/dist/bookmarks.js.map +1 -0
  15. package/dist/columns.d.ts +18 -0
  16. package/dist/columns.d.ts.map +1 -0
  17. package/dist/columns.js +31 -0
  18. package/dist/columns.js.map +1 -0
  19. package/dist/context.d.ts +8 -0
  20. package/dist/context.d.ts.map +1 -0
  21. package/dist/context.js +38 -0
  22. package/dist/context.js.map +1 -0
  23. package/dist/coordinate.d.ts +14 -0
  24. package/dist/coordinate.d.ts.map +1 -0
  25. package/dist/coordinate.js +16 -0
  26. package/dist/coordinate.js.map +1 -0
  27. package/dist/data.d.ts +18 -0
  28. package/dist/data.d.ts.map +1 -0
  29. package/dist/data.js +56 -0
  30. package/dist/data.js.map +1 -0
  31. package/dist/expression.d.ts +13 -0
  32. package/dist/expression.d.ts.map +1 -0
  33. package/dist/expression.js +90 -0
  34. package/dist/expression.js.map +1 -0
  35. package/dist/font-loader.d.ts +8 -0
  36. package/dist/font-loader.d.ts.map +1 -0
  37. package/dist/font-loader.js +29 -0
  38. package/dist/font-loader.js.map +1 -0
  39. package/dist/fonts.d.ts +19 -0
  40. package/dist/fonts.d.ts.map +1 -0
  41. package/dist/fonts.js +124 -0
  42. package/dist/fonts.js.map +1 -0
  43. package/dist/footnotes.d.ts +34 -0
  44. package/dist/footnotes.d.ts.map +1 -0
  45. package/dist/footnotes.js +103 -0
  46. package/dist/footnotes.js.map +1 -0
  47. package/dist/gradient.d.ts +19 -0
  48. package/dist/gradient.d.ts.map +1 -0
  49. package/dist/gradient.js +176 -0
  50. package/dist/gradient.js.map +1 -0
  51. package/dist/index.d.ts +11 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +10 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/layout.d.ts +54 -0
  56. package/dist/layout.d.ts.map +1 -0
  57. package/dist/layout.js +680 -0
  58. package/dist/layout.js.map +1 -0
  59. package/dist/renderer.d.ts +19 -0
  60. package/dist/renderer.d.ts.map +1 -0
  61. package/dist/renderer.js +570 -0
  62. package/dist/renderer.js.map +1 -0
  63. package/dist/style-resolver.d.ts +15 -0
  64. package/dist/style-resolver.d.ts.map +1 -0
  65. package/dist/style-resolver.js +39 -0
  66. package/dist/style-resolver.js.map +1 -0
  67. package/package.json +29 -0
@@ -0,0 +1,176 @@
1
+ import { PDFName, PDFNumber, PDFArray, PDFRawStream } from 'pdf-lib';
2
+ import { parseColor } from '@jsonpdf/core';
3
+ /**
4
+ * Draw a gradient-filled rectangle on a PDF page.
5
+ *
6
+ * Uses PDF shading patterns (Type 2 axial for linear, Type 3 radial for radial).
7
+ * The gradient is clipped to the specified rectangle.
8
+ *
9
+ * @param page - The pdf-lib page
10
+ * @param doc - The pdf-lib document
11
+ * @param x - Left edge in pdf-lib coordinates
12
+ * @param y - Bottom edge in pdf-lib coordinates (NOT top)
13
+ * @param width - Rectangle width
14
+ * @param height - Rectangle height
15
+ * @param gradient - The gradient definition
16
+ * @param opacity - Optional opacity (0-1)
17
+ */
18
+ export function drawGradientRect(page, doc, x, y, width, height, gradient, opacity) {
19
+ const context = doc.context;
20
+ // Build the color function from stops
21
+ const colorFunction = buildColorFunction(context, gradient.stops);
22
+ // Build the shading dictionary
23
+ let shadingDict;
24
+ if (gradient.type === 'linear') {
25
+ shadingDict = buildAxialShading(context, gradient, x, y, width, height, colorFunction);
26
+ }
27
+ else {
28
+ shadingDict = buildRadialShading(context, gradient, x, y, width, height, colorFunction);
29
+ }
30
+ const shadingRef = context.register(shadingDict);
31
+ // Generate unique name for this shading resource
32
+ const shadingName = `Sh${String(shadingRef.objectNumber)}`;
33
+ // Add shading to page resources
34
+ const pageDict = page.node;
35
+ let resources = pageDict.get(PDFName.of('Resources'));
36
+ if (!resources) {
37
+ resources = context.obj({});
38
+ pageDict.set(PDFName.of('Resources'), resources);
39
+ }
40
+ let shadingResources = resources.get(PDFName.of('Shading'));
41
+ if (!shadingResources) {
42
+ shadingResources = context.obj({});
43
+ resources.set(PDFName.of('Shading'), shadingResources);
44
+ }
45
+ shadingResources.set(PDFName.of(shadingName), shadingRef);
46
+ // Build graphics state for opacity if needed
47
+ let gsName;
48
+ if (opacity !== undefined && opacity < 1) {
49
+ const gsDict = context.obj({
50
+ Type: 'ExtGState',
51
+ ca: PDFNumber.of(opacity),
52
+ CA: PDFNumber.of(opacity),
53
+ });
54
+ const gsRef = context.register(gsDict);
55
+ gsName = `GS${String(gsRef.objectNumber)}`;
56
+ let extGState = resources.get(PDFName.of('ExtGState'));
57
+ if (!extGState) {
58
+ extGState = context.obj({});
59
+ resources.set(PDFName.of('ExtGState'), extGState);
60
+ }
61
+ extGState.set(PDFName.of(gsName), gsRef);
62
+ }
63
+ // Build content stream operators:
64
+ // q (save state) → clip to rect → optional gs → sh (paint shading) → Q (restore)
65
+ const ops = [];
66
+ ops.push('q'); // save graphics state
67
+ // Clip to rectangle
68
+ ops.push(`${n(x)} ${n(y)} ${n(width)} ${n(height)} re W n`);
69
+ // Apply opacity graphics state if needed
70
+ if (gsName) {
71
+ ops.push(`/${gsName} gs`);
72
+ }
73
+ // Paint the shading
74
+ ops.push(`/${shadingName} sh`);
75
+ ops.push('Q'); // restore graphics state
76
+ // Inject the operators into the page content stream
77
+ const stream = PDFRawStream.of(context.obj({}), new TextEncoder().encode(ops.join('\n')));
78
+ const streamRef = context.register(stream);
79
+ // Append to page contents
80
+ const currentContents = pageDict.get(PDFName.of('Contents'));
81
+ if (currentContents instanceof PDFArray) {
82
+ currentContents.push(streamRef);
83
+ }
84
+ else if (currentContents) {
85
+ const newArray = PDFArray.withContext(context);
86
+ newArray.push(currentContents);
87
+ newArray.push(streamRef);
88
+ pageDict.set(PDFName.of('Contents'), newArray);
89
+ }
90
+ else {
91
+ pageDict.set(PDFName.of('Contents'), streamRef);
92
+ }
93
+ }
94
+ /** Format a number for PDF operators (avoid scientific notation). */
95
+ function n(v) {
96
+ return Number(v.toFixed(4)).toString();
97
+ }
98
+ /**
99
+ * Build a PDF Function object for gradient color interpolation.
100
+ * Two stops → Type 2 exponential. More → Type 3 stitching.
101
+ */
102
+ function buildColorFunction(context, stops) {
103
+ if (stops.length === 2) {
104
+ const c0 = parseColor(stops[0].color);
105
+ const c1 = parseColor(stops[1].color);
106
+ return context.obj({
107
+ FunctionType: 2,
108
+ Domain: [0, 1],
109
+ C0: [c0.r, c0.g, c0.b],
110
+ C1: [c1.r, c1.g, c1.b],
111
+ N: 1,
112
+ });
113
+ }
114
+ // Multi-stop: Type 3 stitching function
115
+ const functions = [];
116
+ const bounds = [];
117
+ const encode = [];
118
+ for (let i = 0; i < stops.length - 1; i++) {
119
+ const c0 = parseColor(stops[i].color);
120
+ const c1 = parseColor(stops[i + 1].color);
121
+ functions.push(context.obj({
122
+ FunctionType: 2,
123
+ Domain: [0, 1],
124
+ C0: [c0.r, c0.g, c0.b],
125
+ C1: [c1.r, c1.g, c1.b],
126
+ N: 1,
127
+ }));
128
+ if (i > 0) {
129
+ bounds.push(stops[i].position);
130
+ }
131
+ encode.push(0, 1);
132
+ }
133
+ return context.obj({
134
+ FunctionType: 3,
135
+ Domain: [0, 1],
136
+ Functions: functions,
137
+ Bounds: bounds,
138
+ Encode: encode,
139
+ });
140
+ }
141
+ /** Build a Type 2 (axial/linear) shading dictionary. */
142
+ function buildAxialShading(context, gradient, x, y, width, height, colorFunction) {
143
+ // Convert angle to start/end coordinates
144
+ const angleRad = (gradient.angle * Math.PI) / 180;
145
+ const cos = Math.cos(angleRad);
146
+ const sin = Math.sin(angleRad);
147
+ // Project the rectangle corners onto the gradient direction
148
+ const cx = x + width / 2;
149
+ const cy = y + height / 2;
150
+ const halfDiag = Math.abs((cos * width) / 2) + Math.abs((sin * height) / 2);
151
+ const x0 = cx - cos * halfDiag;
152
+ const y0 = cy + sin * halfDiag; // PDF Y is upward, angle 90 = top-to-bottom = -Y
153
+ const x1 = cx + cos * halfDiag;
154
+ const y1 = cy - sin * halfDiag;
155
+ return context.obj({
156
+ ShadingType: 2,
157
+ ColorSpace: 'DeviceRGB',
158
+ Coords: [x0, y0, x1, y1],
159
+ Function: colorFunction,
160
+ Extend: [true, true],
161
+ });
162
+ }
163
+ /** Build a Type 3 (radial) shading dictionary. */
164
+ function buildRadialShading(context, gradient, x, y, width, height, colorFunction) {
165
+ const cx = x + (gradient.cx ?? 0.5) * width;
166
+ const cy = y + (gradient.cy ?? 0.5) * height;
167
+ const r = (gradient.radius ?? 0.5) * Math.min(width, height);
168
+ return context.obj({
169
+ ShadingType: 3,
170
+ ColorSpace: 'DeviceRGB',
171
+ Coords: [cx, cy, 0, cx, cy, r],
172
+ Function: colorFunction,
173
+ Extend: [true, true],
174
+ });
175
+ }
176
+ //# sourceMappingURL=gradient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gradient.js","sourceRoot":"","sources":["../src/gradient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAW,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAa,EACb,GAAgB,EAChB,CAAS,EACT,CAAS,EACT,KAAa,EACb,MAAc,EACd,QAAkB,EAClB,OAAgB;IAEhB,MAAM,OAAO,GAAG,GAA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AO,OAAO,CAAC,GAAG,CAAC;QACjB,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,WAAW;QACvB,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9B,QAAQ,EAAE,aAAa;QACvB,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;KACrB,CAAuB,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,11 @@
1
+ export { renderPdf, type RenderOptions, type RenderResult } from './renderer.js';
2
+ export { createExpressionEngine, type ExpressionEngine } from './expression.js';
3
+ export { validateData, resolveDotPath, buildScope } from './data.js';
4
+ export { mergePageConfig, type LayoutBand, type LayoutPage, type LayoutResult } from './layout.js';
5
+ export type { BandInstance, ExpandedSection } from './band-expander.js';
6
+ export { embedFonts, collectFontSpecs, mapWeight, type FontSpec } from './fonts.js';
7
+ export { initBrowser } from '@jsonpdf/plugins';
8
+ export { collectAnchors } from './anchors.js';
9
+ export { buildPdfOutline, type BookmarkEntry } from './bookmarks.js';
10
+ export { computeColumnLayout, type ColumnLayout } from './columns.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AACnG,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { renderPdf } from './renderer.js';
2
+ export { createExpressionEngine } from './expression.js';
3
+ export { validateData, resolveDotPath, buildScope } from './data.js';
4
+ export { mergePageConfig } from './layout.js';
5
+ export { embedFonts, collectFontSpecs, mapWeight } from './fonts.js';
6
+ export { initBrowser } from '@jsonpdf/plugins';
7
+ export { collectAnchors } from './anchors.js';
8
+ export { buildPdfOutline } from './bookmarks.js';
9
+ export { computeColumnLayout } from './columns.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyC,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAyB,MAAM,iBAAiB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,eAAe,EAAuD,MAAM,aAAa,CAAC;AAEnG,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAiB,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAsB,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAqB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { PDFDocument } from 'pdf-lib';
2
+ import type { Template, Band, PageConfig } from '@jsonpdf/core';
3
+ import type { FontMap, Plugin, ImageCache } from '@jsonpdf/plugins';
4
+ import type { ExpressionEngine } from './expression.js';
5
+ /** Maximum nesting depth for container elements to prevent infinite recursion. */
6
+ export declare const MAX_CONTAINER_DEPTH = 10;
7
+ export interface LayoutBand {
8
+ band: Band;
9
+ offsetY: number;
10
+ measuredHeight: number;
11
+ elementHeights: Map<string, number>;
12
+ scope: Record<string, unknown>;
13
+ /** Column index (0-based). Undefined for full-width bands. */
14
+ columnIndex?: number;
15
+ /** X-offset from left margin for this column. */
16
+ columnOffsetX?: number;
17
+ /** Width of this column in points. */
18
+ columnWidth?: number;
19
+ }
20
+ export interface LayoutPage {
21
+ sectionIndex: number;
22
+ pageIndex: number;
23
+ bands: LayoutBand[];
24
+ /** Computed page height when autoHeight is enabled. */
25
+ computedHeight?: number;
26
+ }
27
+ /** A bookmark entry collected during layout for TOC generation. */
28
+ export interface BookmarkLayoutEntry {
29
+ /** Display title. */
30
+ title: string;
31
+ /** 1-based page number. */
32
+ pageNumber: number;
33
+ /** Nesting level: 0 = section, 1 = band. */
34
+ level: number;
35
+ /** Anchor ID for internal links (derived from section/band id). */
36
+ anchorId: string;
37
+ }
38
+ export interface LayoutResult {
39
+ pages: LayoutPage[];
40
+ totalPages: number;
41
+ /** Bookmarks collected during layout (for _bookmarks data source). */
42
+ bookmarks: BookmarkLayoutEntry[];
43
+ }
44
+ /** Merge section-level page config overrides with the template-level defaults. */
45
+ export declare function mergePageConfig(base: PageConfig, override?: Partial<PageConfig>): PageConfig;
46
+ /**
47
+ * Layout a template across multiple pages.
48
+ *
49
+ * Handles all 13 band types, multi-section support, page breaks,
50
+ * and content overflow. Each LayoutBand carries its Liquid scope
51
+ * for expression resolution during rendering.
52
+ */
53
+ export declare function layoutTemplate(template: Template, fonts: FontMap, getPlugin: (type: string) => Plugin, engine: ExpressionEngine, data: Record<string, unknown>, totalPagesHint: number, pdfDoc: PDFDocument, imageCache: ImageCache): Promise<LayoutResult>;
54
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAW,QAAQ,EAAE,IAAI,EAAY,UAAU,EAAkB,MAAM,eAAe,CAAC;AACnG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKxD,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAQD,MAAM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,mEAAmE;AACnE,MAAM,WAAW,mBAAmB;IAClC,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C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