@lupinum/nuxt-pdf 0.3.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/API_REPORT.md +262 -0
- package/CHANGELOG.md +168 -0
- package/CONFORMANCE.md +496 -0
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/THIRD_PARTY_NOTICES.md +75 -0
- package/dist/module.d.mts +24 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +368 -0
- package/dist/runtime/authoring.d.ts +141 -0
- package/dist/runtime/authoring.js +25 -0
- package/dist/runtime/components/_props.d.ts +196 -0
- package/dist/runtime/components/_props.js +63 -0
- package/dist/runtime/components/document.d.ts +9 -0
- package/dist/runtime/components/document.js +26 -0
- package/dist/runtime/components/index.d.ts +4 -0
- package/dist/runtime/components/index.js +27 -0
- package/dist/runtime/components/svg.d.ts +17 -0
- package/dist/runtime/components/svg.js +50 -0
- package/dist/runtime/composables/index.d.ts +2 -0
- package/dist/runtime/composables/index.js +3 -0
- package/dist/runtime/composables/use-pdf-page-numbers.d.ts +39 -0
- package/dist/runtime/composables/use-pdf-page-numbers.js +17 -0
- package/dist/runtime/define-pdf.d.ts +6 -0
- package/dist/runtime/define-pdf.js +5 -0
- package/dist/runtime/fonts.d.ts +16 -0
- package/dist/runtime/fonts.js +0 -0
- package/dist/runtime/renderer/index.d.ts +3 -0
- package/dist/runtime/renderer/index.js +1 -0
- package/dist/runtime/renderer/node-ops.d.ts +5 -0
- package/dist/runtime/renderer/node-ops.js +281 -0
- package/dist/runtime/renderer/patch-prop.d.ts +3 -0
- package/dist/runtime/renderer/patch-prop.js +223 -0
- package/dist/runtime/renderer/render-component.d.ts +14 -0
- package/dist/runtime/renderer/render-component.js +201 -0
- package/dist/runtime/renderer/types.d.ts +33 -0
- package/dist/runtime/renderer/types.js +56 -0
- package/dist/runtime/renderer/validate-tree.d.ts +3 -0
- package/dist/runtime/renderer/validate-tree.js +428 -0
- package/dist/runtime/server/assets/errors.d.ts +12 -0
- package/dist/runtime/server/assets/errors.js +15 -0
- package/dist/runtime/server/assets/remote.d.ts +48 -0
- package/dist/runtime/server/assets/remote.js +234 -0
- package/dist/runtime/server/assets/resolve-asset.d.ts +53 -0
- package/dist/runtime/server/assets/resolve-asset.js +482 -0
- package/dist/runtime/server/engine/CONTRACTS.md +386 -0
- package/dist/runtime/server/engine/fonts.d.ts +8 -0
- package/dist/runtime/server/engine/fonts.js +19 -0
- package/dist/runtime/server/engine/layout-passes.d.ts +42 -0
- package/dist/runtime/server/engine/layout-passes.js +58 -0
- package/dist/runtime/server/engine/react-pdf-pdfkit.d.ts +7 -0
- package/dist/runtime/server/engine/render-document.d.ts +31 -0
- package/dist/runtime/server/engine/render-document.js +236 -0
- package/dist/runtime/server/index.d.ts +5 -0
- package/dist/runtime/server/index.js +9 -0
- package/dist/runtime/server/preview.d.ts +17 -0
- package/dist/runtime/server/preview.js +332 -0
- package/dist/runtime/server/registry.d.ts +41 -0
- package/dist/runtime/server/registry.js +270 -0
- package/dist/runtime/server/render-limits.d.ts +51 -0
- package/dist/runtime/server/render-limits.js +143 -0
- package/dist/runtime/server/result.d.ts +6 -0
- package/dist/runtime/server/result.js +81 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/shared/errors.d.ts +22 -0
- package/dist/runtime/shared/errors.js +22 -0
- package/dist/runtime/shared/index.d.ts +4 -0
- package/dist/runtime/shared/index.js +7 -0
- package/dist/runtime/shared/template.d.ts +63 -0
- package/dist/runtime/shared/template.js +1 -0
- package/dist/shared/nuxt-pdf.D2ZziYn4.mjs +1132 -0
- package/dist/test.d.mts +198 -0
- package/dist/test.mjs +696 -0
- package/dist/types.d.mts +13 -0
- package/package.json +135 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mountPdfComponent } from "./render-component.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RendererOptions } from 'vue';
|
|
2
|
+
import { type PdfHostElement, type PdfHostNode, type PdfRoot } from './types.js';
|
|
3
|
+
export declare const createPdfRoot: () => PdfRoot;
|
|
4
|
+
export type PdfHostErrorHandler = (error: unknown) => void;
|
|
5
|
+
export declare const createPdfNodeOps: (onError?: PdfHostErrorHandler) => RendererOptions<PdfHostNode, PdfHostElement>;
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { PDF_PRIMITIVES } from "../authoring.js";
|
|
2
|
+
import { NuxtPdfError, PDF_ERROR_CODES } from "../shared/errors.js";
|
|
3
|
+
import { patchPdfProp } from "./patch-prop.js";
|
|
4
|
+
import {
|
|
5
|
+
PDF_COMMENT,
|
|
6
|
+
PDF_PRIMITIVE_NAMES,
|
|
7
|
+
isPdfCommentNode,
|
|
8
|
+
isPdfElementNode,
|
|
9
|
+
isPdfElementType,
|
|
10
|
+
isPdfTextInstance
|
|
11
|
+
} from "./types.js";
|
|
12
|
+
const TEXT_CONTAINERS = /* @__PURE__ */ new Set([
|
|
13
|
+
PDF_PRIMITIVES.Text,
|
|
14
|
+
PDF_PRIMITIVES.Link,
|
|
15
|
+
PDF_PRIMITIVES.Tspan,
|
|
16
|
+
PDF_PRIMITIVES.Note
|
|
17
|
+
]);
|
|
18
|
+
const PAGE_CHILDREN = /* @__PURE__ */ new Set([
|
|
19
|
+
PDF_PRIMITIVES.View,
|
|
20
|
+
PDF_PRIMITIVES.Text,
|
|
21
|
+
PDF_PRIMITIVES.Image,
|
|
22
|
+
PDF_PRIMITIVES.Link,
|
|
23
|
+
PDF_PRIMITIVES.Note,
|
|
24
|
+
PDF_PRIMITIVES.Svg
|
|
25
|
+
]);
|
|
26
|
+
const SVG_SHAPES = [
|
|
27
|
+
PDF_PRIMITIVES.Path,
|
|
28
|
+
PDF_PRIMITIVES.Rect,
|
|
29
|
+
PDF_PRIMITIVES.Circle,
|
|
30
|
+
PDF_PRIMITIVES.Ellipse,
|
|
31
|
+
PDF_PRIMITIVES.Line,
|
|
32
|
+
PDF_PRIMITIVES.Polyline,
|
|
33
|
+
PDF_PRIMITIVES.Polygon
|
|
34
|
+
];
|
|
35
|
+
const G_CHILDREN = /* @__PURE__ */ new Set([
|
|
36
|
+
...SVG_SHAPES,
|
|
37
|
+
PDF_PRIMITIVES.G,
|
|
38
|
+
PDF_PRIMITIVES.Image,
|
|
39
|
+
PDF_PRIMITIVES.Text
|
|
40
|
+
]);
|
|
41
|
+
const NO_CHILDREN = /* @__PURE__ */ new Set();
|
|
42
|
+
const ELEMENT_CHILDREN = {
|
|
43
|
+
[PDF_PRIMITIVES.Document]: /* @__PURE__ */ new Set([PDF_PRIMITIVES.Page]),
|
|
44
|
+
[PDF_PRIMITIVES.Page]: PAGE_CHILDREN,
|
|
45
|
+
[PDF_PRIMITIVES.View]: PAGE_CHILDREN,
|
|
46
|
+
[PDF_PRIMITIVES.Text]: /* @__PURE__ */ new Set([
|
|
47
|
+
PDF_PRIMITIVES.Text,
|
|
48
|
+
PDF_PRIMITIVES.Image,
|
|
49
|
+
PDF_PRIMITIVES.Link,
|
|
50
|
+
PDF_PRIMITIVES.Tspan
|
|
51
|
+
]),
|
|
52
|
+
[PDF_PRIMITIVES.Image]: NO_CHILDREN,
|
|
53
|
+
[PDF_PRIMITIVES.Link]: /* @__PURE__ */ new Set([
|
|
54
|
+
PDF_PRIMITIVES.View,
|
|
55
|
+
PDF_PRIMITIVES.Image,
|
|
56
|
+
PDF_PRIMITIVES.Text
|
|
57
|
+
]),
|
|
58
|
+
[PDF_PRIMITIVES.Note]: NO_CHILDREN,
|
|
59
|
+
[PDF_PRIMITIVES.Tspan]: NO_CHILDREN,
|
|
60
|
+
[PDF_PRIMITIVES.Svg]: /* @__PURE__ */ new Set([...G_CHILDREN, PDF_PRIMITIVES.Defs]),
|
|
61
|
+
[PDF_PRIMITIVES.G]: G_CHILDREN,
|
|
62
|
+
[PDF_PRIMITIVES.Defs]: /* @__PURE__ */ new Set([
|
|
63
|
+
PDF_PRIMITIVES.ClipPath,
|
|
64
|
+
PDF_PRIMITIVES.LinearGradient,
|
|
65
|
+
PDF_PRIMITIVES.RadialGradient
|
|
66
|
+
]),
|
|
67
|
+
[PDF_PRIMITIVES.ClipPath]: new Set(SVG_SHAPES),
|
|
68
|
+
[PDF_PRIMITIVES.LinearGradient]: /* @__PURE__ */ new Set([PDF_PRIMITIVES.Stop]),
|
|
69
|
+
[PDF_PRIMITIVES.RadialGradient]: /* @__PURE__ */ new Set([PDF_PRIMITIVES.Stop]),
|
|
70
|
+
[PDF_PRIMITIVES.Path]: NO_CHILDREN,
|
|
71
|
+
[PDF_PRIMITIVES.Rect]: NO_CHILDREN,
|
|
72
|
+
[PDF_PRIMITIVES.Circle]: NO_CHILDREN,
|
|
73
|
+
[PDF_PRIMITIVES.Ellipse]: NO_CHILDREN,
|
|
74
|
+
[PDF_PRIMITIVES.Line]: NO_CHILDREN,
|
|
75
|
+
[PDF_PRIMITIVES.Polyline]: NO_CHILDREN,
|
|
76
|
+
[PDF_PRIMITIVES.Polygon]: NO_CHILDREN,
|
|
77
|
+
[PDF_PRIMITIVES.Stop]: NO_CHILDREN
|
|
78
|
+
};
|
|
79
|
+
export const createPdfRoot = () => ({
|
|
80
|
+
type: "ROOT",
|
|
81
|
+
document: null
|
|
82
|
+
});
|
|
83
|
+
const throwHostError = (error) => {
|
|
84
|
+
throw error;
|
|
85
|
+
};
|
|
86
|
+
export const createPdfNodeOps = (onError = throwHostError) => {
|
|
87
|
+
const childOrder = /* @__PURE__ */ new WeakMap();
|
|
88
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
const childrenOf = (parent) => {
|
|
90
|
+
let children = childOrder.get(parent);
|
|
91
|
+
if (!children) {
|
|
92
|
+
children = [];
|
|
93
|
+
childOrder.set(parent, children);
|
|
94
|
+
}
|
|
95
|
+
return children;
|
|
96
|
+
};
|
|
97
|
+
const rejectOrphanText = (parent) => {
|
|
98
|
+
const message = parent ? `<${PDF_PRIMITIVE_NAMES[parent.type]}> cannot contain text. Wrap it in <PdfText>.` : "A PDF component root cannot contain text outside <PdfDocument>.";
|
|
99
|
+
throw new NuxtPdfError(PDF_ERROR_CODES.TreeInvalid, message);
|
|
100
|
+
};
|
|
101
|
+
const rejectInvalidChild = (parent, child) => {
|
|
102
|
+
throw new NuxtPdfError(
|
|
103
|
+
PDF_ERROR_CODES.TreeInvalid,
|
|
104
|
+
`Invalid PDF nesting: <${PDF_PRIMITIVE_NAMES[parent.type]}> cannot contain <${PDF_PRIMITIVE_NAMES[child.type]}>.`
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
const syncRoot = (root, children) => {
|
|
108
|
+
const elements = children.filter(isPdfElementNode);
|
|
109
|
+
for (const child of children) {
|
|
110
|
+
if (isPdfTextInstance(child) && child.value.trim() !== "") {
|
|
111
|
+
rejectOrphanText();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (elements.length === 0) {
|
|
115
|
+
root.document = null;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (elements.length !== 1 || elements[0]?.type !== PDF_PRIMITIVES.Document) {
|
|
119
|
+
throw new NuxtPdfError(
|
|
120
|
+
PDF_ERROR_CODES.TreeInvalid,
|
|
121
|
+
"A PDF component must render exactly one PdfDocument at its root."
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
root.document = elements[0];
|
|
125
|
+
};
|
|
126
|
+
const syncElement = (element, children) => {
|
|
127
|
+
const acceptsText = TEXT_CONTAINERS.has(element.type);
|
|
128
|
+
const pdfChildren = [];
|
|
129
|
+
for (const child of children) {
|
|
130
|
+
if (isPdfCommentNode(child)) continue;
|
|
131
|
+
if (isPdfElementNode(child) && !ELEMENT_CHILDREN[element.type].has(child.type)) {
|
|
132
|
+
rejectInvalidChild(element, child);
|
|
133
|
+
}
|
|
134
|
+
if (isPdfTextInstance(child)) {
|
|
135
|
+
if (!acceptsText) {
|
|
136
|
+
if (child.value.trim() !== "") rejectOrphanText(element);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
pdfChildren.push(child);
|
|
141
|
+
}
|
|
142
|
+
element.children.splice(0, element.children.length, ...pdfChildren);
|
|
143
|
+
};
|
|
144
|
+
const sync = (parent) => {
|
|
145
|
+
const children = childrenOf(parent);
|
|
146
|
+
if (parent.type === "ROOT") syncRoot(parent, children);
|
|
147
|
+
else syncElement(parent, children);
|
|
148
|
+
};
|
|
149
|
+
const detach = (child) => {
|
|
150
|
+
const parent = parents.get(child);
|
|
151
|
+
if (!parent) return;
|
|
152
|
+
const siblings = childrenOf(parent);
|
|
153
|
+
const index = siblings.indexOf(child);
|
|
154
|
+
if (index !== -1) siblings.splice(index, 1);
|
|
155
|
+
parents.delete(child);
|
|
156
|
+
sync(parent);
|
|
157
|
+
};
|
|
158
|
+
const insert = (child, parent, anchor = null) => {
|
|
159
|
+
if (child === anchor) return;
|
|
160
|
+
detach(child);
|
|
161
|
+
const siblings = childrenOf(parent);
|
|
162
|
+
const index = anchor == null ? siblings.length : siblings.indexOf(anchor);
|
|
163
|
+
if (index === -1) {
|
|
164
|
+
onError(new TypeError("Cannot insert a PDF node before an unknown anchor."));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
siblings.splice(index, 0, child);
|
|
168
|
+
parents.set(child, parent);
|
|
169
|
+
try {
|
|
170
|
+
sync(parent);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
siblings.splice(index, 1);
|
|
173
|
+
parents.delete(child);
|
|
174
|
+
sync(parent);
|
|
175
|
+
onError(error);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const remove = (child) => {
|
|
179
|
+
detach(child);
|
|
180
|
+
};
|
|
181
|
+
const createElement = (type) => {
|
|
182
|
+
let elementType;
|
|
183
|
+
if (!isPdfElementType(type)) {
|
|
184
|
+
onError(new TypeError(`Unknown PDF primitive "${type}".`));
|
|
185
|
+
elementType = PDF_PRIMITIVES.View;
|
|
186
|
+
} else elementType = type;
|
|
187
|
+
const element = {
|
|
188
|
+
type: elementType,
|
|
189
|
+
box: {},
|
|
190
|
+
style: {},
|
|
191
|
+
props: {},
|
|
192
|
+
children: []
|
|
193
|
+
};
|
|
194
|
+
childOrder.set(element, []);
|
|
195
|
+
return element;
|
|
196
|
+
};
|
|
197
|
+
const createText = (text) => ({
|
|
198
|
+
type: PDF_PRIMITIVES.TextInstance,
|
|
199
|
+
value: text
|
|
200
|
+
});
|
|
201
|
+
const createComment = (text) => ({
|
|
202
|
+
[PDF_COMMENT]: true,
|
|
203
|
+
value: text
|
|
204
|
+
});
|
|
205
|
+
const setText = (node, text) => {
|
|
206
|
+
if (isPdfElementNode(node)) {
|
|
207
|
+
onError(new TypeError("Cannot set text directly on a PDF element node."));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const previousText = node.value;
|
|
211
|
+
node.value = text;
|
|
212
|
+
const parent = parents.get(node);
|
|
213
|
+
if (!parent) return;
|
|
214
|
+
try {
|
|
215
|
+
sync(parent);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
node.value = previousText;
|
|
218
|
+
sync(parent);
|
|
219
|
+
onError(error);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const setElementText = (element, text) => {
|
|
223
|
+
const children = childrenOf(element);
|
|
224
|
+
const previousChildren = [...children];
|
|
225
|
+
if (children.length === 1 && isPdfTextInstance(children[0]) && text !== "") {
|
|
226
|
+
const textNode = children[0];
|
|
227
|
+
const previousText = textNode.value;
|
|
228
|
+
textNode.value = text;
|
|
229
|
+
try {
|
|
230
|
+
sync(element);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
textNode.value = previousText;
|
|
233
|
+
sync(element);
|
|
234
|
+
onError(error);
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
for (const child of children) parents.delete(child);
|
|
239
|
+
children.length = 0;
|
|
240
|
+
if (text !== "") {
|
|
241
|
+
const textNode = createText(text);
|
|
242
|
+
children.push(textNode);
|
|
243
|
+
parents.set(textNode, element);
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
sync(element);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
for (const child of children) parents.delete(child);
|
|
249
|
+
children.splice(0, children.length, ...previousChildren);
|
|
250
|
+
for (const child of previousChildren) parents.set(child, element);
|
|
251
|
+
sync(element);
|
|
252
|
+
onError(error);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
const parentNode = (node) => parents.get(node) ?? null;
|
|
256
|
+
const nextSibling = (node) => {
|
|
257
|
+
const parent = parents.get(node);
|
|
258
|
+
if (!parent) return null;
|
|
259
|
+
const siblings = childrenOf(parent);
|
|
260
|
+
const index = siblings.indexOf(node);
|
|
261
|
+
return index === -1 ? null : siblings[index + 1] ?? null;
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
patchProp: (...args) => {
|
|
265
|
+
try {
|
|
266
|
+
patchPdfProp(...args);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
onError(error);
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
insert,
|
|
272
|
+
remove,
|
|
273
|
+
createElement,
|
|
274
|
+
createText,
|
|
275
|
+
createComment,
|
|
276
|
+
setText,
|
|
277
|
+
setElementText,
|
|
278
|
+
parentNode,
|
|
279
|
+
nextSibling
|
|
280
|
+
};
|
|
281
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PDF_PRIMITIVES
|
|
3
|
+
} from "../authoring.js";
|
|
4
|
+
import { NuxtPdfError, PDF_ERROR_CODES } from "../shared/errors.js";
|
|
5
|
+
import {
|
|
6
|
+
PDF_PRIMITIVE_NAMES
|
|
7
|
+
} from "./types.js";
|
|
8
|
+
const exactPropNames = () => (names) => new Set(names);
|
|
9
|
+
const BASE_PROP_NAMES = [
|
|
10
|
+
"break",
|
|
11
|
+
"debug",
|
|
12
|
+
"fixed",
|
|
13
|
+
"id",
|
|
14
|
+
"minPresenceAhead",
|
|
15
|
+
"style"
|
|
16
|
+
];
|
|
17
|
+
const BOOKMARK_PROP_NAMES = ["bookmark"];
|
|
18
|
+
const SVG_PRESENTATION_PROP_NAMES = [
|
|
19
|
+
"clipPath",
|
|
20
|
+
"fill",
|
|
21
|
+
"fillOpacity",
|
|
22
|
+
"stroke",
|
|
23
|
+
"strokeLinecap",
|
|
24
|
+
"strokeLinejoin",
|
|
25
|
+
"strokeOpacity",
|
|
26
|
+
"strokeWidth",
|
|
27
|
+
"transform"
|
|
28
|
+
];
|
|
29
|
+
const PDF_PROP_KEYS = {
|
|
30
|
+
[PDF_PRIMITIVES.Document]: exactPropNames()([
|
|
31
|
+
"author",
|
|
32
|
+
"creationDate",
|
|
33
|
+
"creator",
|
|
34
|
+
"keywords",
|
|
35
|
+
"language",
|
|
36
|
+
"pageLayout",
|
|
37
|
+
"pdfVersion",
|
|
38
|
+
"producer",
|
|
39
|
+
"subject",
|
|
40
|
+
"title"
|
|
41
|
+
]),
|
|
42
|
+
[PDF_PRIMITIVES.Page]: exactPropNames()([
|
|
43
|
+
...BASE_PROP_NAMES,
|
|
44
|
+
...BOOKMARK_PROP_NAMES,
|
|
45
|
+
"dpi",
|
|
46
|
+
"orientation",
|
|
47
|
+
"size",
|
|
48
|
+
"wrap"
|
|
49
|
+
]),
|
|
50
|
+
[PDF_PRIMITIVES.View]: exactPropNames()([
|
|
51
|
+
...BASE_PROP_NAMES,
|
|
52
|
+
...BOOKMARK_PROP_NAMES,
|
|
53
|
+
"wrap"
|
|
54
|
+
]),
|
|
55
|
+
[PDF_PRIMITIVES.Text]: exactPropNames()([
|
|
56
|
+
...BASE_PROP_NAMES,
|
|
57
|
+
...BOOKMARK_PROP_NAMES,
|
|
58
|
+
"fill",
|
|
59
|
+
"hyphenationCallback",
|
|
60
|
+
"orphans",
|
|
61
|
+
"render",
|
|
62
|
+
"widows",
|
|
63
|
+
"wrap",
|
|
64
|
+
"x",
|
|
65
|
+
"y"
|
|
66
|
+
]),
|
|
67
|
+
[PDF_PRIMITIVES.Image]: exactPropNames()([
|
|
68
|
+
...BASE_PROP_NAMES,
|
|
69
|
+
...BOOKMARK_PROP_NAMES,
|
|
70
|
+
"source",
|
|
71
|
+
"src"
|
|
72
|
+
]),
|
|
73
|
+
[PDF_PRIMITIVES.Link]: exactPropNames()([
|
|
74
|
+
...BASE_PROP_NAMES,
|
|
75
|
+
"hitSlop",
|
|
76
|
+
"href",
|
|
77
|
+
"src",
|
|
78
|
+
"wrap"
|
|
79
|
+
]),
|
|
80
|
+
[PDF_PRIMITIVES.Note]: exactPropNames()(BASE_PROP_NAMES),
|
|
81
|
+
[PDF_PRIMITIVES.Tspan]: exactPropNames()(["fill", "x", "y"]),
|
|
82
|
+
[PDF_PRIMITIVES.Svg]: exactPropNames()([
|
|
83
|
+
"height",
|
|
84
|
+
"style",
|
|
85
|
+
"viewBox",
|
|
86
|
+
"width"
|
|
87
|
+
]),
|
|
88
|
+
[PDF_PRIMITIVES.G]: exactPropNames()(SVG_PRESENTATION_PROP_NAMES),
|
|
89
|
+
[PDF_PRIMITIVES.Path]: exactPropNames()([
|
|
90
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
91
|
+
"d"
|
|
92
|
+
]),
|
|
93
|
+
[PDF_PRIMITIVES.Rect]: exactPropNames()([
|
|
94
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
95
|
+
"height",
|
|
96
|
+
"rx",
|
|
97
|
+
"ry",
|
|
98
|
+
"width",
|
|
99
|
+
"x",
|
|
100
|
+
"y"
|
|
101
|
+
]),
|
|
102
|
+
[PDF_PRIMITIVES.Circle]: exactPropNames()([
|
|
103
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
104
|
+
"cx",
|
|
105
|
+
"cy",
|
|
106
|
+
"r"
|
|
107
|
+
]),
|
|
108
|
+
[PDF_PRIMITIVES.Ellipse]: exactPropNames()([
|
|
109
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
110
|
+
"cx",
|
|
111
|
+
"cy",
|
|
112
|
+
"rx",
|
|
113
|
+
"ry"
|
|
114
|
+
]),
|
|
115
|
+
[PDF_PRIMITIVES.Line]: exactPropNames()([
|
|
116
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
117
|
+
"x1",
|
|
118
|
+
"x2",
|
|
119
|
+
"y1",
|
|
120
|
+
"y2"
|
|
121
|
+
]),
|
|
122
|
+
[PDF_PRIMITIVES.Polyline]: exactPropNames()([
|
|
123
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
124
|
+
"points"
|
|
125
|
+
]),
|
|
126
|
+
[PDF_PRIMITIVES.Polygon]: exactPropNames()([
|
|
127
|
+
...SVG_PRESENTATION_PROP_NAMES,
|
|
128
|
+
"points"
|
|
129
|
+
]),
|
|
130
|
+
[PDF_PRIMITIVES.Defs]: exactPropNames()([]),
|
|
131
|
+
[PDF_PRIMITIVES.ClipPath]: exactPropNames()(["id"]),
|
|
132
|
+
[PDF_PRIMITIVES.LinearGradient]: exactPropNames()([
|
|
133
|
+
"id",
|
|
134
|
+
"x1",
|
|
135
|
+
"x2",
|
|
136
|
+
"y1",
|
|
137
|
+
"y2"
|
|
138
|
+
]),
|
|
139
|
+
[PDF_PRIMITIVES.RadialGradient]: exactPropNames()([
|
|
140
|
+
"cx",
|
|
141
|
+
"cy",
|
|
142
|
+
"fx",
|
|
143
|
+
"fy",
|
|
144
|
+
"id",
|
|
145
|
+
"r"
|
|
146
|
+
]),
|
|
147
|
+
[PDF_PRIMITIVES.Stop]: exactPropNames()([
|
|
148
|
+
"offset",
|
|
149
|
+
"stopColor",
|
|
150
|
+
"stopOpacity"
|
|
151
|
+
])
|
|
152
|
+
};
|
|
153
|
+
const BOOLEAN_PROPS = /* @__PURE__ */ new Set(["break", "debug", "fixed", "wrap"]);
|
|
154
|
+
const EVENT_PROP = /^on[A-Z]/;
|
|
155
|
+
const DOM_ONLY_PROP = /^(?:aria-|data-)/;
|
|
156
|
+
const DOM_ONLY_PROPS = /* @__PURE__ */ new Set([
|
|
157
|
+
"class",
|
|
158
|
+
"className",
|
|
159
|
+
"contenteditable",
|
|
160
|
+
"contentEditable",
|
|
161
|
+
"draggable",
|
|
162
|
+
"hidden",
|
|
163
|
+
"innerHTML",
|
|
164
|
+
"role",
|
|
165
|
+
"slot",
|
|
166
|
+
"spellcheck",
|
|
167
|
+
"tabindex",
|
|
168
|
+
"tabIndex",
|
|
169
|
+
"textContent",
|
|
170
|
+
"translate"
|
|
171
|
+
]);
|
|
172
|
+
const treeInvalid = (message) => {
|
|
173
|
+
throw new NuxtPdfError(PDF_ERROR_CODES.TreeInvalid, message);
|
|
174
|
+
};
|
|
175
|
+
const wrapDynamicText = (render) => (props) => {
|
|
176
|
+
const result = render(props);
|
|
177
|
+
if (result == null) return null;
|
|
178
|
+
if (typeof result !== "string" && typeof result !== "number") {
|
|
179
|
+
throw new TypeError(
|
|
180
|
+
"PdfText render callbacks must return a string, number, null, or undefined. Vue VNodes are not supported."
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return String(result);
|
|
184
|
+
};
|
|
185
|
+
export const patchPdfProp = (element, key, _previousValue, nextValue) => {
|
|
186
|
+
if (element.type === "ROOT") {
|
|
187
|
+
return treeInvalid(`Cannot set the "${key}" prop on the PDF root.`);
|
|
188
|
+
}
|
|
189
|
+
if (EVENT_PROP.test(key)) {
|
|
190
|
+
treeInvalid(
|
|
191
|
+
`Vue event prop "${key}" is not supported on PDF primitives.`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (DOM_ONLY_PROP.test(key) || DOM_ONLY_PROPS.has(key)) {
|
|
195
|
+
treeInvalid(
|
|
196
|
+
`DOM-only attribute "${key}" is not supported on <${PDF_PRIMITIVE_NAMES[element.type]}>. Use PDF props and styles instead.`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
if (!PDF_PROP_KEYS[element.type].has(key)) {
|
|
200
|
+
treeInvalid(
|
|
201
|
+
`Unsupported prop "${key}" on <${PDF_PRIMITIVE_NAMES[element.type]}>.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (key === "style") {
|
|
205
|
+
element.style = nextValue || {};
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (nextValue == null) {
|
|
209
|
+
Reflect.deleteProperty(element.props, key);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (key === "render") {
|
|
213
|
+
if (element.type !== PDF_PRIMITIVES.Text) {
|
|
214
|
+
treeInvalid("Dynamic render callbacks are only supported by PdfText.");
|
|
215
|
+
}
|
|
216
|
+
if (typeof nextValue !== "function") {
|
|
217
|
+
treeInvalid("The PdfText render prop must be a function.");
|
|
218
|
+
}
|
|
219
|
+
element.props.render = wrapDynamicText(nextValue);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
element.props[key] = BOOLEAN_PROPS.has(key) && nextValue === "" ? true : nextValue;
|
|
223
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Component } from 'vue';
|
|
2
|
+
import type { PdfDocumentNode, PdfRoot } from './types.js';
|
|
3
|
+
export type PdfComponentProps = Record<string, unknown>;
|
|
4
|
+
export type MountedPdfComponent = {
|
|
5
|
+
readonly document: PdfDocumentNode;
|
|
6
|
+
readonly root: PdfRoot;
|
|
7
|
+
/** Whether `usePdfPageNumbers()` was called during mount (flags multi-pass). */
|
|
8
|
+
readonly usesPageNumbers: boolean;
|
|
9
|
+
update(props: PdfComponentProps): Promise<PdfDocumentNode>;
|
|
10
|
+
/** Push a destination `id → page` map into the live tree for the next layout. */
|
|
11
|
+
feedPageNumbers(pages: Record<string, number>): Promise<PdfDocumentNode>;
|
|
12
|
+
unmount(): void;
|
|
13
|
+
};
|
|
14
|
+
export declare const mountPdfComponent: (component: Component, initialProps?: PdfComponentProps) => Promise<MountedPdfComponent>;
|