@lpdfio/lpdf 0.22.0 → 0.23.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.
- package/README.md +5 -5
- package/dist/L.d.ts +34 -33
- package/dist/L.js +2 -1
- package/dist/_shared.d.ts +4 -3
- package/dist/_shared.js +15 -0
- package/dist/attrs.d.ts +493 -0
- package/dist/attrs.js +4 -0
- package/dist/browser.js +47 -0
- package/dist/canvas.d.ts +24 -87
- package/dist/canvas.js +22 -134
- package/dist/constants.d.ts +50 -0
- package/dist/constants.js +50 -0
- package/dist/engine.js +19 -15
- package/dist/index.d.ts +5 -4
- package/dist/index.js +8 -1
- package/dist/kit.d.ts +19 -16
- package/dist/kit.js +10 -20
- package/dist/layout.d.ts +18 -203
- package/dist/layout.js +37 -92
- package/dist/wasm/lpdf_bg.wasm +0 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -392,6 +392,48 @@ async function __wbg_init(module_or_path) {
|
|
|
392
392
|
return __wbg_finalize_init(instance, module);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
// src/constants.ts
|
|
396
|
+
var FieldType = {
|
|
397
|
+
Text: "text",
|
|
398
|
+
Checkbox: "checkbox",
|
|
399
|
+
Dropdown: "dropdown",
|
|
400
|
+
Radio: "radio",
|
|
401
|
+
Button: "button"
|
|
402
|
+
};
|
|
403
|
+
var Pin = {
|
|
404
|
+
Top: "top",
|
|
405
|
+
Bottom: "bottom",
|
|
406
|
+
Left: "left",
|
|
407
|
+
Right: "right"
|
|
408
|
+
};
|
|
409
|
+
var Orientation = {
|
|
410
|
+
Portrait: "portrait",
|
|
411
|
+
Landscape: "landscape"
|
|
412
|
+
};
|
|
413
|
+
var BuiltinFont = {
|
|
414
|
+
Courier: "Courier",
|
|
415
|
+
CourierBold: "Courier-Bold",
|
|
416
|
+
CourierOblique: "Courier-Oblique",
|
|
417
|
+
CourierBoldOblique: "Courier-BoldOblique",
|
|
418
|
+
Helvetica: "Helvetica",
|
|
419
|
+
HelveticaBold: "Helvetica-Bold",
|
|
420
|
+
HelveticaOblique: "Helvetica-Oblique",
|
|
421
|
+
HelveticaBoldOblique: "Helvetica-BoldOblique",
|
|
422
|
+
TimesRoman: "Times-Roman",
|
|
423
|
+
TimesBold: "Times-Bold",
|
|
424
|
+
TimesItalic: "Times-Italic",
|
|
425
|
+
TimesBoldItalic: "Times-BoldItalic",
|
|
426
|
+
Symbol: "Symbol",
|
|
427
|
+
ZapfDingbats: "ZapfDingbats"
|
|
428
|
+
};
|
|
429
|
+
var PageScope = {
|
|
430
|
+
Each: "each",
|
|
431
|
+
First: "first",
|
|
432
|
+
Last: "last",
|
|
433
|
+
Odd: "odd",
|
|
434
|
+
Even: "even"
|
|
435
|
+
};
|
|
436
|
+
|
|
395
437
|
// src/browser.ts
|
|
396
438
|
var NoAttr = null;
|
|
397
439
|
function nowUnix() {
|
|
@@ -443,6 +485,11 @@ async function initLpdf(wasmSource, licenseKey = "") {
|
|
|
443
485
|
};
|
|
444
486
|
}
|
|
445
487
|
export {
|
|
488
|
+
BuiltinFont,
|
|
489
|
+
FieldType,
|
|
446
490
|
NoAttr,
|
|
491
|
+
Orientation,
|
|
492
|
+
PageScope,
|
|
493
|
+
Pin,
|
|
447
494
|
initLpdf
|
|
448
495
|
};
|
package/dist/canvas.d.ts
CHANGED
|
@@ -1,57 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
stroke?: string;
|
|
8
|
-
strokeWidth?: number;
|
|
9
|
-
strokeDash?: number[];
|
|
10
|
-
borderRadius?: number;
|
|
11
|
-
opacity?: number;
|
|
12
|
-
anchor?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface CanvasLineStyle {
|
|
15
|
-
stroke?: string;
|
|
16
|
-
strokeWidth?: number;
|
|
17
|
-
strokeDash?: number[];
|
|
18
|
-
lineCap?: LineCap;
|
|
19
|
-
lineJoin?: LineJoin;
|
|
20
|
-
}
|
|
21
|
-
export interface CanvasEllipseStyle {
|
|
22
|
-
fill?: string;
|
|
23
|
-
stroke?: string;
|
|
24
|
-
strokeWidth?: number;
|
|
25
|
-
strokeDash?: number[];
|
|
26
|
-
opacity?: number;
|
|
27
|
-
anchor?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface CanvasPathStyle {
|
|
30
|
-
fill?: string;
|
|
31
|
-
stroke?: string;
|
|
32
|
-
strokeWidth?: number;
|
|
33
|
-
strokeDash?: number[];
|
|
34
|
-
fillRuleEvenodd?: boolean;
|
|
35
|
-
lineCap?: LineCap;
|
|
36
|
-
lineJoin?: LineJoin;
|
|
37
|
-
opacity?: number;
|
|
38
|
-
}
|
|
39
|
-
export interface CanvasTextStyle {
|
|
40
|
-
font?: string;
|
|
41
|
-
size?: number;
|
|
42
|
-
color?: string;
|
|
43
|
-
align?: TextAlign;
|
|
44
|
-
lineHeight?: number;
|
|
45
|
-
width?: number;
|
|
46
|
-
opacity?: number;
|
|
47
|
-
anchor?: string;
|
|
48
|
-
}
|
|
49
|
-
export interface CanvasRun {
|
|
50
|
-
text: string;
|
|
51
|
-
font?: string;
|
|
52
|
-
size?: number;
|
|
53
|
-
color?: string;
|
|
54
|
-
}
|
|
1
|
+
import type { RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, CanvasTextAttr, CanvasImgAttr, LayerAttr } from './attrs';
|
|
2
|
+
import type { LpdfSpanNode } from './layout';
|
|
3
|
+
/**
|
|
4
|
+
* Builds the `transform` string of a layer. `String(CanvasTransform.rotate(45))` is
|
|
5
|
+
* `matrix(...)`, which a layer's `transform` attribute accepts like `rotate(45)`.
|
|
6
|
+
*/
|
|
55
7
|
export declare class CanvasTransform {
|
|
56
8
|
readonly matrix: number[];
|
|
57
9
|
constructor(matrix: number[]);
|
|
@@ -66,67 +18,52 @@ export declare class CanvasTransform {
|
|
|
66
18
|
* Equivalent to matrix multiplication: this × other.
|
|
67
19
|
*/
|
|
68
20
|
then(other: CanvasTransform): CanvasTransform;
|
|
69
|
-
/**
|
|
21
|
+
/** The `"matrix(a,b,c,d,e,f)"` form of the transform. */
|
|
70
22
|
toString(): string;
|
|
71
23
|
}
|
|
72
24
|
export interface LpdfCanvasRectNode {
|
|
73
|
-
type: '
|
|
25
|
+
type: 'rect';
|
|
74
26
|
attrs: Record<string, string>;
|
|
75
27
|
}
|
|
76
28
|
export interface LpdfCanvasLineNode {
|
|
77
|
-
type: '
|
|
29
|
+
type: 'line';
|
|
78
30
|
attrs: Record<string, string>;
|
|
79
31
|
}
|
|
80
32
|
export interface LpdfCanvasEllipseNode {
|
|
81
|
-
type: '
|
|
33
|
+
type: 'ellipse';
|
|
82
34
|
attrs: Record<string, string>;
|
|
83
35
|
}
|
|
84
36
|
export interface LpdfCanvasCircleNode {
|
|
85
|
-
type: '
|
|
37
|
+
type: 'circle';
|
|
86
38
|
attrs: Record<string, string>;
|
|
87
39
|
}
|
|
88
40
|
export interface LpdfCanvasPathNode {
|
|
89
|
-
type: '
|
|
41
|
+
type: 'path';
|
|
90
42
|
attrs: Record<string, string>;
|
|
91
43
|
}
|
|
92
44
|
export interface LpdfCanvasTextNode {
|
|
93
|
-
type: '
|
|
94
|
-
text: string;
|
|
45
|
+
type: 'text';
|
|
95
46
|
attrs: Record<string, string>;
|
|
96
|
-
|
|
97
|
-
text: string;
|
|
98
|
-
attrs: {
|
|
99
|
-
font?: string;
|
|
100
|
-
'font-size'?: string;
|
|
101
|
-
color?: string;
|
|
102
|
-
};
|
|
103
|
-
}[];
|
|
47
|
+
nodes: (string | LpdfSpanNode)[];
|
|
104
48
|
}
|
|
105
49
|
export interface LpdfCanvasImgNode {
|
|
106
|
-
type: '
|
|
50
|
+
type: 'img';
|
|
107
51
|
attrs: Record<string, string>;
|
|
108
52
|
}
|
|
109
53
|
export type LpdfCanvasPrimitiveNode = LpdfCanvasRectNode | LpdfCanvasLineNode | LpdfCanvasEllipseNode | LpdfCanvasCircleNode | LpdfCanvasPathNode | LpdfCanvasTextNode | LpdfCanvasImgNode;
|
|
110
|
-
/** @deprecated Use {@link LayerAttr} */
|
|
111
|
-
export type CanvasLayerOptions = LayerAttr;
|
|
112
|
-
export interface LayerAttr {
|
|
113
|
-
page?: PageScope | string;
|
|
114
|
-
opacity?: number;
|
|
115
|
-
transform?: CanvasTransform;
|
|
116
|
-
}
|
|
117
54
|
export interface LpdfCanvasLayerNode {
|
|
118
|
-
type: '
|
|
55
|
+
type: 'layer';
|
|
119
56
|
attrs: Record<string, string>;
|
|
120
57
|
nodes: LpdfCanvasPrimitiveNode[];
|
|
121
58
|
}
|
|
122
|
-
declare function rect(
|
|
123
|
-
declare function line(
|
|
124
|
-
declare function ellipse(
|
|
125
|
-
declare function circle(
|
|
126
|
-
declare function path(
|
|
127
|
-
declare function textAt(
|
|
128
|
-
declare function imgAt(
|
|
129
|
-
declare function layer(attrs: LayerAttr | null, nodes
|
|
59
|
+
declare function rect(attrs: RectAttr): LpdfCanvasRectNode;
|
|
60
|
+
declare function line(attrs: LineAttr): LpdfCanvasLineNode;
|
|
61
|
+
declare function ellipse(attrs: EllipseAttr): LpdfCanvasEllipseNode;
|
|
62
|
+
declare function circle(attrs: CircleAttr): LpdfCanvasCircleNode;
|
|
63
|
+
declare function path(attrs: PathAttr): LpdfCanvasPathNode;
|
|
64
|
+
declare function textAt(attrs: CanvasTextAttr, nodes?: (string | LpdfSpanNode)[]): LpdfCanvasTextNode;
|
|
65
|
+
declare function imgAt(attrs: CanvasImgAttr): LpdfCanvasImgNode;
|
|
66
|
+
declare function layer(attrs: LayerAttr | null, nodes?: LpdfCanvasPrimitiveNode[]): LpdfCanvasLayerNode;
|
|
130
67
|
export declare const LpdfCanvas: Readonly<{
|
|
131
68
|
rect: typeof rect;
|
|
132
69
|
line: typeof line;
|
package/dist/canvas.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LpdfCanvas = exports.CanvasTransform = void 0;
|
|
4
|
+
const _shared_1 = require("./_shared");
|
|
4
5
|
// ── CanvasTransform ───────────────────────────────────────────────────────────
|
|
6
|
+
/**
|
|
7
|
+
* Builds the `transform` string of a layer. `String(CanvasTransform.rotate(45))` is
|
|
8
|
+
* `matrix(...)`, which a layer's `transform` attribute accepts like `rotate(45)`.
|
|
9
|
+
*/
|
|
5
10
|
class CanvasTransform {
|
|
6
11
|
constructor(matrix) {
|
|
7
12
|
this.matrix = matrix;
|
|
@@ -39,153 +44,36 @@ class CanvasTransform {
|
|
|
39
44
|
b1 * e2 + d1 * f2 + f1,
|
|
40
45
|
]);
|
|
41
46
|
}
|
|
42
|
-
/**
|
|
47
|
+
/** The `"matrix(a,b,c,d,e,f)"` form of the transform. */
|
|
43
48
|
toString() {
|
|
44
49
|
return `matrix(${this.matrix.join(',')})`;
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
52
|
exports.CanvasTransform = CanvasTransform;
|
|
48
53
|
// ── LpdfCanvas factory ────────────────────────────────────────────────────────
|
|
49
|
-
function rect(
|
|
50
|
-
|
|
51
|
-
x: String(x), y: String(y), w: String(w), h: String(h),
|
|
52
|
-
};
|
|
53
|
-
if (style?.fill !== undefined)
|
|
54
|
-
attrs['fill'] = style.fill;
|
|
55
|
-
if (style?.stroke !== undefined)
|
|
56
|
-
attrs['stroke'] = style.stroke;
|
|
57
|
-
if (style?.strokeWidth !== undefined)
|
|
58
|
-
attrs['stroke-width'] = String(style.strokeWidth);
|
|
59
|
-
if (style?.strokeDash !== undefined)
|
|
60
|
-
attrs['stroke-dash'] = style.strokeDash.join(' ');
|
|
61
|
-
if (style?.borderRadius !== undefined)
|
|
62
|
-
attrs['radius'] = String(style.borderRadius);
|
|
63
|
-
if (style?.opacity !== undefined)
|
|
64
|
-
attrs['opacity'] = String(style.opacity);
|
|
65
|
-
if (style?.anchor !== undefined)
|
|
66
|
-
attrs['anchor'] = style.anchor;
|
|
67
|
-
return { type: 'canvas-rect', attrs };
|
|
54
|
+
function rect(attrs) {
|
|
55
|
+
return { type: 'rect', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
68
56
|
}
|
|
69
|
-
function line(
|
|
70
|
-
|
|
71
|
-
x1: String(x1), y1: String(y1), x2: String(x2), y2: String(y2),
|
|
72
|
-
};
|
|
73
|
-
if (style?.stroke !== undefined)
|
|
74
|
-
attrs['stroke'] = style.stroke;
|
|
75
|
-
if (style?.strokeWidth !== undefined)
|
|
76
|
-
attrs['stroke-width'] = String(style.strokeWidth);
|
|
77
|
-
if (style?.strokeDash !== undefined)
|
|
78
|
-
attrs['stroke-dash'] = style.strokeDash.join(' ');
|
|
79
|
-
if (style?.lineCap !== undefined)
|
|
80
|
-
attrs['line-cap'] = style.lineCap;
|
|
81
|
-
if (style?.lineJoin !== undefined)
|
|
82
|
-
attrs['line-join'] = style.lineJoin;
|
|
83
|
-
return { type: 'canvas-line', attrs };
|
|
57
|
+
function line(attrs) {
|
|
58
|
+
return { type: 'line', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
84
59
|
}
|
|
85
|
-
function ellipse(
|
|
86
|
-
|
|
87
|
-
cx: String(cx), cy: String(cy), rx: String(rx), ry: String(ry),
|
|
88
|
-
};
|
|
89
|
-
if (style?.fill !== undefined)
|
|
90
|
-
attrs['fill'] = style.fill;
|
|
91
|
-
if (style?.stroke !== undefined)
|
|
92
|
-
attrs['stroke'] = style.stroke;
|
|
93
|
-
if (style?.strokeWidth !== undefined)
|
|
94
|
-
attrs['stroke-width'] = String(style.strokeWidth);
|
|
95
|
-
if (style?.strokeDash !== undefined)
|
|
96
|
-
attrs['stroke-dash'] = style.strokeDash.join(' ');
|
|
97
|
-
if (style?.opacity !== undefined)
|
|
98
|
-
attrs['opacity'] = String(style.opacity);
|
|
99
|
-
if (style?.anchor !== undefined)
|
|
100
|
-
attrs['anchor'] = style.anchor;
|
|
101
|
-
return { type: 'canvas-ellipse', attrs };
|
|
60
|
+
function ellipse(attrs) {
|
|
61
|
+
return { type: 'ellipse', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
102
62
|
}
|
|
103
|
-
function circle(
|
|
104
|
-
|
|
105
|
-
cx: String(cx), cy: String(cy), r: String(r),
|
|
106
|
-
};
|
|
107
|
-
if (style?.fill !== undefined)
|
|
108
|
-
attrs['fill'] = style.fill;
|
|
109
|
-
if (style?.stroke !== undefined)
|
|
110
|
-
attrs['stroke'] = style.stroke;
|
|
111
|
-
if (style?.strokeWidth !== undefined)
|
|
112
|
-
attrs['stroke-width'] = String(style.strokeWidth);
|
|
113
|
-
if (style?.strokeDash !== undefined)
|
|
114
|
-
attrs['stroke-dash'] = style.strokeDash.join(' ');
|
|
115
|
-
if (style?.opacity !== undefined)
|
|
116
|
-
attrs['opacity'] = String(style.opacity);
|
|
117
|
-
if (style?.anchor !== undefined)
|
|
118
|
-
attrs['anchor'] = style.anchor;
|
|
119
|
-
return { type: 'canvas-circle', attrs };
|
|
63
|
+
function circle(attrs) {
|
|
64
|
+
return { type: 'circle', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
120
65
|
}
|
|
121
|
-
function path(
|
|
122
|
-
|
|
123
|
-
if (style?.fill !== undefined)
|
|
124
|
-
attrs['fill'] = style.fill;
|
|
125
|
-
if (style?.stroke !== undefined)
|
|
126
|
-
attrs['stroke'] = style.stroke;
|
|
127
|
-
if (style?.strokeWidth !== undefined)
|
|
128
|
-
attrs['stroke-width'] = String(style.strokeWidth);
|
|
129
|
-
if (style?.strokeDash !== undefined)
|
|
130
|
-
attrs['stroke-dash'] = style.strokeDash.join(' ');
|
|
131
|
-
if (style?.fillRuleEvenodd !== undefined)
|
|
132
|
-
attrs['fill-rule'] = style.fillRuleEvenodd ? 'evenodd' : 'nonzero';
|
|
133
|
-
if (style?.lineCap !== undefined)
|
|
134
|
-
attrs['line-cap'] = style.lineCap;
|
|
135
|
-
if (style?.lineJoin !== undefined)
|
|
136
|
-
attrs['line-join'] = style.lineJoin;
|
|
137
|
-
if (style?.opacity !== undefined)
|
|
138
|
-
attrs['opacity'] = String(style.opacity);
|
|
139
|
-
return { type: 'canvas-path', attrs };
|
|
66
|
+
function path(attrs) {
|
|
67
|
+
return { type: 'path', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
140
68
|
}
|
|
141
|
-
function textAt(
|
|
142
|
-
|
|
143
|
-
if (style?.font !== undefined)
|
|
144
|
-
attrs['font'] = style.font;
|
|
145
|
-
if (style?.size !== undefined)
|
|
146
|
-
attrs['font-size'] = String(style.size);
|
|
147
|
-
if (style?.color !== undefined)
|
|
148
|
-
attrs['color'] = style.color;
|
|
149
|
-
if (style?.align !== undefined)
|
|
150
|
-
attrs['align'] = style.align;
|
|
151
|
-
if (style?.lineHeight !== undefined)
|
|
152
|
-
attrs['line-height'] = String(style.lineHeight);
|
|
153
|
-
if (style?.width !== undefined)
|
|
154
|
-
attrs['w'] = String(style.width);
|
|
155
|
-
if (style?.opacity !== undefined)
|
|
156
|
-
attrs['opacity'] = String(style.opacity);
|
|
157
|
-
if (style?.anchor !== undefined)
|
|
158
|
-
attrs['anchor'] = style.anchor;
|
|
159
|
-
const node = { type: 'canvas-text', text: content, attrs };
|
|
160
|
-
if (runs && runs.length > 0) {
|
|
161
|
-
node.runs = runs.map(r => {
|
|
162
|
-
const runAttrs = {};
|
|
163
|
-
if (r.font !== undefined)
|
|
164
|
-
runAttrs['font'] = r.font;
|
|
165
|
-
if (r.size !== undefined)
|
|
166
|
-
runAttrs['font-size'] = String(r.size);
|
|
167
|
-
if (r.color !== undefined)
|
|
168
|
-
runAttrs['color'] = r.color;
|
|
169
|
-
return { text: r.text, attrs: runAttrs };
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return node;
|
|
69
|
+
function textAt(attrs, nodes = []) {
|
|
70
|
+
return { type: 'text', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
|
|
173
71
|
}
|
|
174
|
-
function imgAt(
|
|
175
|
-
|
|
176
|
-
if (anchor !== undefined)
|
|
177
|
-
attrs['anchor'] = anchor;
|
|
178
|
-
return { type: 'canvas-img', attrs };
|
|
72
|
+
function imgAt(attrs) {
|
|
73
|
+
return { type: 'img', attrs: (0, _shared_1.buildAttrs)(attrs) };
|
|
179
74
|
}
|
|
180
|
-
function layer(attrs, nodes) {
|
|
181
|
-
|
|
182
|
-
if (attrs?.page !== undefined)
|
|
183
|
-
a['page'] = attrs.page;
|
|
184
|
-
if (attrs?.opacity !== undefined)
|
|
185
|
-
a['opacity'] = String(attrs.opacity);
|
|
186
|
-
if (attrs?.transform !== undefined)
|
|
187
|
-
a['transform'] = attrs.transform.toString();
|
|
188
|
-
return { type: 'canvas-layer', attrs: a, nodes };
|
|
75
|
+
function layer(attrs, nodes = []) {
|
|
76
|
+
return { type: 'layer', attrs: (0, _shared_1.buildAttrs)(attrs), nodes };
|
|
189
77
|
}
|
|
190
78
|
exports.LpdfCanvas = Object.freeze({
|
|
191
79
|
rect,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** The values of the `type` attribute of a field. */
|
|
2
|
+
export declare const FieldType: {
|
|
3
|
+
readonly Text: "text";
|
|
4
|
+
readonly Checkbox: "checkbox";
|
|
5
|
+
readonly Dropdown: "dropdown";
|
|
6
|
+
readonly Radio: "radio";
|
|
7
|
+
readonly Button: "button";
|
|
8
|
+
};
|
|
9
|
+
export type FieldType = (typeof FieldType)[keyof typeof FieldType];
|
|
10
|
+
/** The values of the `pin` attribute of a region. */
|
|
11
|
+
export declare const Pin: {
|
|
12
|
+
readonly Top: "top";
|
|
13
|
+
readonly Bottom: "bottom";
|
|
14
|
+
readonly Left: "left";
|
|
15
|
+
readonly Right: "right";
|
|
16
|
+
};
|
|
17
|
+
export type Pin = (typeof Pin)[keyof typeof Pin];
|
|
18
|
+
/** The values of the `orientation` attribute of a document or a section. */
|
|
19
|
+
export declare const Orientation: {
|
|
20
|
+
readonly Portrait: "portrait";
|
|
21
|
+
readonly Landscape: "landscape";
|
|
22
|
+
};
|
|
23
|
+
export type Orientation = (typeof Orientation)[keyof typeof Orientation];
|
|
24
|
+
/** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
|
|
25
|
+
export declare const BuiltinFont: {
|
|
26
|
+
readonly Courier: "Courier";
|
|
27
|
+
readonly CourierBold: "Courier-Bold";
|
|
28
|
+
readonly CourierOblique: "Courier-Oblique";
|
|
29
|
+
readonly CourierBoldOblique: "Courier-BoldOblique";
|
|
30
|
+
readonly Helvetica: "Helvetica";
|
|
31
|
+
readonly HelveticaBold: "Helvetica-Bold";
|
|
32
|
+
readonly HelveticaOblique: "Helvetica-Oblique";
|
|
33
|
+
readonly HelveticaBoldOblique: "Helvetica-BoldOblique";
|
|
34
|
+
readonly TimesRoman: "Times-Roman";
|
|
35
|
+
readonly TimesBold: "Times-Bold";
|
|
36
|
+
readonly TimesItalic: "Times-Italic";
|
|
37
|
+
readonly TimesBoldItalic: "Times-BoldItalic";
|
|
38
|
+
readonly Symbol: "Symbol";
|
|
39
|
+
readonly ZapfDingbats: "ZapfDingbats";
|
|
40
|
+
};
|
|
41
|
+
export type BuiltinFont = (typeof BuiltinFont)[keyof typeof BuiltinFont];
|
|
42
|
+
/** The named values of the `page` attribute of a layer or a region. A range such as 2-4 or 1,3-5 is a string. */
|
|
43
|
+
export declare const PageScope: {
|
|
44
|
+
readonly Each: "each";
|
|
45
|
+
readonly First: "first";
|
|
46
|
+
readonly Last: "last";
|
|
47
|
+
readonly Odd: "odd";
|
|
48
|
+
readonly Even: "even";
|
|
49
|
+
};
|
|
50
|
+
export type PageScope = (typeof PageScope)[keyof typeof PageScope];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Generated from lpdf.xsd by scripts/gen-sdk-api.mjs.
|
|
3
|
+
// Do not edit: change the schema and run `make gen-sdk-api`.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.PageScope = exports.BuiltinFont = exports.Orientation = exports.Pin = exports.FieldType = void 0;
|
|
6
|
+
/** The values of the `type` attribute of a field. */
|
|
7
|
+
exports.FieldType = {
|
|
8
|
+
Text: 'text',
|
|
9
|
+
Checkbox: 'checkbox',
|
|
10
|
+
Dropdown: 'dropdown',
|
|
11
|
+
Radio: 'radio',
|
|
12
|
+
Button: 'button',
|
|
13
|
+
};
|
|
14
|
+
/** The values of the `pin` attribute of a region. */
|
|
15
|
+
exports.Pin = {
|
|
16
|
+
Top: 'top',
|
|
17
|
+
Bottom: 'bottom',
|
|
18
|
+
Left: 'left',
|
|
19
|
+
Right: 'right',
|
|
20
|
+
};
|
|
21
|
+
/** The values of the `orientation` attribute of a document or a section. */
|
|
22
|
+
exports.Orientation = {
|
|
23
|
+
Portrait: 'portrait',
|
|
24
|
+
Landscape: 'landscape',
|
|
25
|
+
};
|
|
26
|
+
/** The values of the `core` attribute of a font: the built-in PDF fonts, which need no file. */
|
|
27
|
+
exports.BuiltinFont = {
|
|
28
|
+
Courier: 'Courier',
|
|
29
|
+
CourierBold: 'Courier-Bold',
|
|
30
|
+
CourierOblique: 'Courier-Oblique',
|
|
31
|
+
CourierBoldOblique: 'Courier-BoldOblique',
|
|
32
|
+
Helvetica: 'Helvetica',
|
|
33
|
+
HelveticaBold: 'Helvetica-Bold',
|
|
34
|
+
HelveticaOblique: 'Helvetica-Oblique',
|
|
35
|
+
HelveticaBoldOblique: 'Helvetica-BoldOblique',
|
|
36
|
+
TimesRoman: 'Times-Roman',
|
|
37
|
+
TimesBold: 'Times-Bold',
|
|
38
|
+
TimesItalic: 'Times-Italic',
|
|
39
|
+
TimesBoldItalic: 'Times-BoldItalic',
|
|
40
|
+
Symbol: 'Symbol',
|
|
41
|
+
ZapfDingbats: 'ZapfDingbats',
|
|
42
|
+
};
|
|
43
|
+
/** The named values of the `page` attribute of a layer or a region. A range such as 2-4 or 1,3-5 is a string. */
|
|
44
|
+
exports.PageScope = {
|
|
45
|
+
Each: 'each',
|
|
46
|
+
First: 'first',
|
|
47
|
+
Last: 'last',
|
|
48
|
+
Odd: 'odd',
|
|
49
|
+
Even: 'even',
|
|
50
|
+
};
|
package/dist/engine.js
CHANGED
|
@@ -153,10 +153,11 @@ class PdfEngine {
|
|
|
153
153
|
pdf = engine.render_pdf(xml, dataJson);
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
|
-
// JSON (Kit tree) path — pass JSON directly to render_tree_pdf.
|
|
156
|
+
// JSON (Kit tree) path — pass JSON directly to render_tree_pdf. Fonts and images the
|
|
157
|
+
// document declares with a src are read from there, as on the XML path.
|
|
157
158
|
const json = JSON.stringify(input);
|
|
158
159
|
const allFonts = new Map(this._fonts);
|
|
159
|
-
for (const [key, src] of
|
|
160
|
+
for (const [key, src] of assetSrcsOfDocument(input, 'fonts')) {
|
|
160
161
|
if (!allFonts.has(key)) {
|
|
161
162
|
try {
|
|
162
163
|
allFonts.set(key, (0, node_fs_1.readFileSync)(src));
|
|
@@ -167,7 +168,16 @@ class PdfEngine {
|
|
|
167
168
|
for (const [name, bytes] of allFonts) {
|
|
168
169
|
engine.load_font(name, bytes);
|
|
169
170
|
}
|
|
170
|
-
|
|
171
|
+
const allImages = new Map(this._images);
|
|
172
|
+
for (const [key, src] of assetSrcsOfDocument(input, 'images')) {
|
|
173
|
+
if (!allImages.has(key)) {
|
|
174
|
+
try {
|
|
175
|
+
allImages.set(key, (0, node_fs_1.readFileSync)(src));
|
|
176
|
+
}
|
|
177
|
+
catch { /* skip unresolvable image */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (const [name, bytes] of allImages) {
|
|
171
181
|
engine.load_image(name, bytes);
|
|
172
182
|
}
|
|
173
183
|
if (this._encrypt) {
|
|
@@ -203,19 +213,13 @@ function extractAssetSrcs(xml, tag) {
|
|
|
203
213
|
}
|
|
204
214
|
return result;
|
|
205
215
|
}
|
|
206
|
-
/**
|
|
207
|
-
function
|
|
216
|
+
/** The `ref ?? name → src` pairs of the fonts or images a document declares in `attrs.assets`. */
|
|
217
|
+
function assetSrcsOfDocument(document, kind) {
|
|
208
218
|
const result = new Map();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (def.src) {
|
|
214
|
-
const key = def.ref ?? name;
|
|
215
|
-
result.set(key, def.src);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
219
|
+
const declared = document.attrs['assets']?.[kind] ?? [];
|
|
220
|
+
for (const { name, ref, src } of declared) {
|
|
221
|
+
if (src)
|
|
222
|
+
result.set(ref ?? name, src);
|
|
218
223
|
}
|
|
219
|
-
catch { /* ignore */ }
|
|
220
224
|
return result;
|
|
221
225
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { PdfEngine, LpdfRenderError } from './engine';
|
|
2
2
|
export type { EncryptPermissions, EncryptOptions } from './engine';
|
|
3
|
-
export type { RenderOptions, EngineOptions
|
|
4
|
-
export
|
|
5
|
-
export type {
|
|
3
|
+
export type { RenderOptions, EngineOptions } from './_shared';
|
|
4
|
+
export { FieldType, Pin, Orientation, BuiltinFont, PageScope } from './constants';
|
|
5
|
+
export type { PdfDocument, LpdfSectionNode, LpdfLayoutBlock, LpdfCanvasBlock, DocumentTokens, DocumentAssets, DocumentMeta, SectionAttr, DocumentAttr, } from './kit';
|
|
6
|
+
export type { StackAttr, FlankAttr, SplitAttr, ClusterAttr, GridAttr, FrameAttr, LinkAttr, TableAttr, TheadAttr, TrAttr, TdAttr, TextAttr, SpanAttr, DividerAttr, ImgAttr, BarcodeAttr, RegionAttr, FieldAttr, LayerAttr, RectAttr, CircleAttr, EllipseAttr, LineAttr, PathAttr, CanvasTextAttr, CanvasImgAttr, FontAttr, ImageAttr, } from './attrs';
|
|
6
7
|
export type { LpdfNode, LpdfContainerNode, LpdfTextNode, LpdfSpanNode, LpdfDividerNode, LpdfImgNode, LpdfBarcodeNode, LpdfTableNode, LpdfTheadNode, LpdfTrNode, LpdfTdNode, LpdfRegionNode, LpdfFieldNode, } from './layout';
|
|
7
8
|
export { CanvasTransform } from './canvas';
|
|
8
|
-
export type {
|
|
9
|
+
export type { LpdfCanvasLayerNode, LpdfCanvasPrimitiveNode, LpdfCanvasRectNode, LpdfCanvasLineNode, LpdfCanvasEllipseNode, LpdfCanvasCircleNode, LpdfCanvasPathNode, LpdfCanvasTextNode, LpdfCanvasImgNode, } from './canvas';
|
|
9
10
|
export { L, NoAttr } from './L';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoAttr = exports.L = exports.CanvasTransform = exports.LpdfRenderError = exports.PdfEngine = void 0;
|
|
3
|
+
exports.NoAttr = exports.L = exports.CanvasTransform = exports.PageScope = exports.BuiltinFont = exports.Orientation = exports.Pin = exports.FieldType = exports.LpdfRenderError = exports.PdfEngine = void 0;
|
|
4
4
|
// ── Engine ────────────────────────────────────────────────────────────────────
|
|
5
5
|
var engine_1 = require("./engine");
|
|
6
6
|
Object.defineProperty(exports, "PdfEngine", { enumerable: true, get: function () { return engine_1.PdfEngine; } });
|
|
7
7
|
Object.defineProperty(exports, "LpdfRenderError", { enumerable: true, get: function () { return engine_1.LpdfRenderError; } });
|
|
8
|
+
// ── Constants for the schema's enumerations ───────────────────────────────────
|
|
9
|
+
var constants_1 = require("./constants");
|
|
10
|
+
Object.defineProperty(exports, "FieldType", { enumerable: true, get: function () { return constants_1.FieldType; } });
|
|
11
|
+
Object.defineProperty(exports, "Pin", { enumerable: true, get: function () { return constants_1.Pin; } });
|
|
12
|
+
Object.defineProperty(exports, "Orientation", { enumerable: true, get: function () { return constants_1.Orientation; } });
|
|
13
|
+
Object.defineProperty(exports, "BuiltinFont", { enumerable: true, get: function () { return constants_1.BuiltinFont; } });
|
|
14
|
+
Object.defineProperty(exports, "PageScope", { enumerable: true, get: function () { return constants_1.PageScope; } });
|
|
8
15
|
// ── Canvas types ──────────────────────────────────────────────────────────────
|
|
9
16
|
var canvas_1 = require("./canvas");
|
|
10
17
|
Object.defineProperty(exports, "CanvasTransform", { enumerable: true, get: function () { return canvas_1.CanvasTransform; } });
|
package/dist/kit.d.ts
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import type { LpdfNode } from './layout';
|
|
27
27
|
import type { LpdfCanvasLayerNode } from './canvas';
|
|
28
|
-
|
|
28
|
+
import type { FontAttr, ImageAttr } from './attrs';
|
|
29
|
+
export interface DocumentTokens {
|
|
29
30
|
colors?: Record<string, string>;
|
|
30
31
|
space?: Record<string, string>;
|
|
31
32
|
grid?: Record<string, string>;
|
|
@@ -33,16 +34,16 @@ export interface LpdfTokens {
|
|
|
33
34
|
radius?: Record<string, string>;
|
|
34
35
|
width?: Record<string, string>;
|
|
35
36
|
textSize?: Record<string, string>;
|
|
36
|
-
fonts?: Record<string, LpdfFontDef>;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
/**
|
|
39
|
+
* The fonts and images the document declares, as the `assets` element of the XML does. A font or image
|
|
40
|
+
* is picked by its `name`: text sets `font` to a font's name, an `img` sets `name` to an image's.
|
|
41
|
+
*/
|
|
42
|
+
export interface DocumentAssets {
|
|
43
|
+
fonts?: FontAttr[];
|
|
44
|
+
images?: ImageAttr[];
|
|
45
|
+
}
|
|
46
|
+
export interface DocumentMeta {
|
|
46
47
|
title?: string;
|
|
47
48
|
author?: string;
|
|
48
49
|
subject?: string;
|
|
@@ -62,8 +63,10 @@ export interface DocumentAttr {
|
|
|
62
63
|
orientation?: string;
|
|
63
64
|
margin?: string;
|
|
64
65
|
background?: string;
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
font?: string;
|
|
67
|
+
assets?: DocumentAssets;
|
|
68
|
+
tokens?: DocumentTokens;
|
|
69
|
+
meta?: DocumentMeta;
|
|
67
70
|
debug?: string;
|
|
68
71
|
}
|
|
69
72
|
/** A layout block — wraps an ordered list of layout nodes. */
|
|
@@ -87,10 +90,10 @@ export interface PdfDocument {
|
|
|
87
90
|
attrs: Record<string, unknown>;
|
|
88
91
|
nodes: LpdfSectionNode[];
|
|
89
92
|
}
|
|
90
|
-
declare function layout(_attrs: null, nodes
|
|
91
|
-
declare function canvas(_attrs: null, layers
|
|
92
|
-
declare function section(attrs: SectionAttr | null, nodes
|
|
93
|
-
declare function document(attrs: DocumentAttr | null, nodes
|
|
93
|
+
declare function layout(_attrs: null, nodes?: LpdfNode[]): LpdfLayoutBlock;
|
|
94
|
+
declare function canvas(_attrs: null, layers?: LpdfCanvasLayerNode[]): LpdfCanvasBlock;
|
|
95
|
+
declare function section(attrs: SectionAttr | null, nodes?: (LpdfLayoutBlock | LpdfCanvasBlock)[]): LpdfSectionNode;
|
|
96
|
+
declare function document(attrs: DocumentAttr | null, nodes?: LpdfSectionNode[]): PdfDocument;
|
|
94
97
|
export declare const LpdfKit: Readonly<{
|
|
95
98
|
layout: typeof layout;
|
|
96
99
|
canvas: typeof canvas;
|