@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,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createRenderer,
|
|
3
|
+
createVNode,
|
|
4
|
+
defineComponent,
|
|
5
|
+
getCurrentInstance,
|
|
6
|
+
nextTick,
|
|
7
|
+
reactive,
|
|
8
|
+
shallowRef
|
|
9
|
+
} from "vue";
|
|
10
|
+
import { PDF_PAGE_NUMBERS_KEY } from "../composables/use-pdf-page-numbers.js";
|
|
11
|
+
import { PDF_PRIMITIVES } from "../authoring.js";
|
|
12
|
+
import {
|
|
13
|
+
PdfCircle,
|
|
14
|
+
PdfClipPath,
|
|
15
|
+
PdfDefs,
|
|
16
|
+
PdfDocument,
|
|
17
|
+
PdfEllipse,
|
|
18
|
+
PdfG,
|
|
19
|
+
PdfImage,
|
|
20
|
+
PdfLine,
|
|
21
|
+
PdfLinearGradient,
|
|
22
|
+
PdfLink,
|
|
23
|
+
PdfNote,
|
|
24
|
+
PdfPage,
|
|
25
|
+
PdfPath,
|
|
26
|
+
PdfPolygon,
|
|
27
|
+
PdfPolyline,
|
|
28
|
+
PdfRadialGradient,
|
|
29
|
+
PdfRect,
|
|
30
|
+
PdfStop,
|
|
31
|
+
PdfSvg,
|
|
32
|
+
PdfText,
|
|
33
|
+
PdfTspan,
|
|
34
|
+
PdfView
|
|
35
|
+
} from "../components/index.js";
|
|
36
|
+
import {
|
|
37
|
+
createPdfNodeOps,
|
|
38
|
+
createPdfRoot
|
|
39
|
+
} from "./node-ops.js";
|
|
40
|
+
import { NuxtPdfError, PDF_ERROR_CODES } from "../shared/errors.js";
|
|
41
|
+
import { validatePdfDocumentTree } from "./validate-tree.js";
|
|
42
|
+
const PDF_COMPONENTS = {
|
|
43
|
+
PdfCircle,
|
|
44
|
+
PdfClipPath,
|
|
45
|
+
PdfDefs,
|
|
46
|
+
PdfDocument,
|
|
47
|
+
PdfEllipse,
|
|
48
|
+
PdfG,
|
|
49
|
+
PdfImage,
|
|
50
|
+
PdfLine,
|
|
51
|
+
PdfLinearGradient,
|
|
52
|
+
PdfLink,
|
|
53
|
+
PdfNote,
|
|
54
|
+
PdfPage,
|
|
55
|
+
PdfPath,
|
|
56
|
+
PdfPolygon,
|
|
57
|
+
PdfPolyline,
|
|
58
|
+
PdfRadialGradient,
|
|
59
|
+
PdfRect,
|
|
60
|
+
PdfStop,
|
|
61
|
+
PdfSvg,
|
|
62
|
+
PdfText,
|
|
63
|
+
PdfTspan,
|
|
64
|
+
PdfView
|
|
65
|
+
};
|
|
66
|
+
const ASYNC_AUTHORING_ERROR = "Async setup and async components are not supported in PDF templates. Load request data before render(props) and pass it through typed props.";
|
|
67
|
+
const requireDocument = (root) => {
|
|
68
|
+
if (root.document?.type !== PDF_PRIMITIVES.Document) {
|
|
69
|
+
throw new NuxtPdfError(
|
|
70
|
+
PDF_ERROR_CODES.TreeInvalid,
|
|
71
|
+
"A PDF component must render exactly one PdfDocument at its root."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
validatePdfDocumentTree(root.document);
|
|
75
|
+
return root.document;
|
|
76
|
+
};
|
|
77
|
+
export const mountPdfComponent = async (component, initialProps = {}) => {
|
|
78
|
+
let hasRenderError = false;
|
|
79
|
+
let renderError;
|
|
80
|
+
const recordRenderError = (error) => {
|
|
81
|
+
if (hasRenderError) return;
|
|
82
|
+
hasRenderError = true;
|
|
83
|
+
renderError = error;
|
|
84
|
+
};
|
|
85
|
+
const resetRenderError = () => {
|
|
86
|
+
hasRenderError = false;
|
|
87
|
+
renderError = void 0;
|
|
88
|
+
};
|
|
89
|
+
const throwRenderError = () => {
|
|
90
|
+
if (!hasRenderError) return;
|
|
91
|
+
const error = renderError;
|
|
92
|
+
resetRenderError();
|
|
93
|
+
throw error;
|
|
94
|
+
};
|
|
95
|
+
const renderer = createRenderer(
|
|
96
|
+
createPdfNodeOps(recordRenderError)
|
|
97
|
+
);
|
|
98
|
+
const root = createPdfRoot();
|
|
99
|
+
const currentProps = shallowRef(initialProps);
|
|
100
|
+
const RootComponent = defineComponent({
|
|
101
|
+
name: "NuxtPdfRenderRoot",
|
|
102
|
+
setup: () => () => createVNode(component, currentProps.value)
|
|
103
|
+
});
|
|
104
|
+
const app = renderer.createApp(RootComponent);
|
|
105
|
+
app.mixin({
|
|
106
|
+
beforeCreate() {
|
|
107
|
+
const type = getCurrentInstance()?.type;
|
|
108
|
+
if (typeof type !== "object" || type === null) return;
|
|
109
|
+
const candidate = type;
|
|
110
|
+
const setup = candidate.setup;
|
|
111
|
+
if ("__asyncLoader" in candidate || typeof setup === "function" && setup.constructor.name === "AsyncFunction") {
|
|
112
|
+
recordRenderError(new NuxtPdfError(
|
|
113
|
+
PDF_ERROR_CODES.TemplateInvalid,
|
|
114
|
+
ASYNC_AUTHORING_ERROR
|
|
115
|
+
));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
app.config.errorHandler = recordRenderError;
|
|
120
|
+
app.config.throwUnhandledErrorInProduction = true;
|
|
121
|
+
app.config.warnHandler = (message) => recordRenderError(new NuxtPdfError(
|
|
122
|
+
PDF_ERROR_CODES.TemplateInvalid,
|
|
123
|
+
message.includes("async setup()") ? ASYNC_AUTHORING_ERROR : `Vue reported an invalid PDF authoring pattern: ${message}`
|
|
124
|
+
));
|
|
125
|
+
for (const [name, primitive] of Object.entries(PDF_COMPONENTS)) {
|
|
126
|
+
app.component(name, primitive);
|
|
127
|
+
}
|
|
128
|
+
const pageNumbers = reactive({});
|
|
129
|
+
let pageNumbersUsed = false;
|
|
130
|
+
app.provide(PDF_PAGE_NUMBERS_KEY, {
|
|
131
|
+
pages: pageNumbers,
|
|
132
|
+
markUsed: () => {
|
|
133
|
+
pageNumbersUsed = true;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
let mounted = false;
|
|
137
|
+
const dispose = (surfaceCleanupError) => {
|
|
138
|
+
if (!mounted) return;
|
|
139
|
+
resetRenderError();
|
|
140
|
+
try {
|
|
141
|
+
app.unmount();
|
|
142
|
+
if (surfaceCleanupError) throwRenderError();
|
|
143
|
+
} finally {
|
|
144
|
+
mounted = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const fail = (error) => {
|
|
148
|
+
try {
|
|
149
|
+
dispose(false);
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
throw error;
|
|
153
|
+
};
|
|
154
|
+
const requireSuccessfulDocument = () => {
|
|
155
|
+
throwRenderError();
|
|
156
|
+
return requireDocument(root);
|
|
157
|
+
};
|
|
158
|
+
const updateDocument = async (mutate) => {
|
|
159
|
+
resetRenderError();
|
|
160
|
+
try {
|
|
161
|
+
mutate();
|
|
162
|
+
await nextTick();
|
|
163
|
+
return requireSuccessfulDocument();
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return fail(error);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
try {
|
|
169
|
+
app.mount(root);
|
|
170
|
+
mounted = true;
|
|
171
|
+
await nextTick();
|
|
172
|
+
requireSuccessfulDocument();
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return fail(error);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
get document() {
|
|
178
|
+
return requireDocument(root);
|
|
179
|
+
},
|
|
180
|
+
root,
|
|
181
|
+
get usesPageNumbers() {
|
|
182
|
+
return pageNumbersUsed;
|
|
183
|
+
},
|
|
184
|
+
async update(props) {
|
|
185
|
+
return updateDocument(() => {
|
|
186
|
+
currentProps.value = props;
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
async feedPageNumbers(pages) {
|
|
190
|
+
return updateDocument(() => {
|
|
191
|
+
for (const key of Object.keys(pageNumbers)) {
|
|
192
|
+
if (!(key in pages)) Reflect.deleteProperty(pageNumbers, key);
|
|
193
|
+
}
|
|
194
|
+
Object.assign(pageNumbers, pages);
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
unmount() {
|
|
198
|
+
dispose(true);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PDF_PRIMITIVES, type PdfStyleValue } from '../authoring.js';
|
|
2
|
+
export type PdfElementType = Exclude<(typeof PDF_PRIMITIVES)[keyof typeof PDF_PRIMITIVES], typeof PDF_PRIMITIVES.TextInstance>;
|
|
3
|
+
export declare const PDF_PRIMITIVE_NAMES: Record<PdfElementType, string>;
|
|
4
|
+
export type PdfTextInstance = {
|
|
5
|
+
type: typeof PDF_PRIMITIVES.TextInstance;
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
export type PdfElementNode = {
|
|
9
|
+
type: PdfElementType;
|
|
10
|
+
box: Record<string, unknown>;
|
|
11
|
+
style: PdfStyleValue;
|
|
12
|
+
props: Record<string, unknown>;
|
|
13
|
+
children: PdfNode[];
|
|
14
|
+
};
|
|
15
|
+
export type PdfDocumentNode = PdfElementNode & {
|
|
16
|
+
type: typeof PDF_PRIMITIVES.Document;
|
|
17
|
+
};
|
|
18
|
+
export type PdfNode = PdfElementNode | PdfTextInstance;
|
|
19
|
+
export type PdfRoot = {
|
|
20
|
+
type: 'ROOT';
|
|
21
|
+
document: PdfDocumentNode | null;
|
|
22
|
+
};
|
|
23
|
+
export declare const PDF_COMMENT: unique symbol;
|
|
24
|
+
export type PdfCommentNode = {
|
|
25
|
+
readonly [PDF_COMMENT]: true;
|
|
26
|
+
value: string;
|
|
27
|
+
};
|
|
28
|
+
export type PdfHostNode = PdfNode | PdfCommentNode;
|
|
29
|
+
export type PdfHostElement = PdfRoot | PdfElementNode;
|
|
30
|
+
export declare const isPdfElementType: (value: string) => value is PdfElementType;
|
|
31
|
+
export declare const isPdfElementNode: (node: PdfHostNode) => node is PdfElementNode;
|
|
32
|
+
export declare const isPdfTextInstance: (node: PdfHostNode) => node is PdfTextInstance;
|
|
33
|
+
export declare const isPdfCommentNode: (node: PdfHostNode) => node is PdfCommentNode;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PDF_PRIMITIVES
|
|
3
|
+
} from "../authoring.js";
|
|
4
|
+
export const PDF_PRIMITIVE_NAMES = {
|
|
5
|
+
[PDF_PRIMITIVES.Document]: "PdfDocument",
|
|
6
|
+
[PDF_PRIMITIVES.Page]: "PdfPage",
|
|
7
|
+
[PDF_PRIMITIVES.View]: "PdfView",
|
|
8
|
+
[PDF_PRIMITIVES.Text]: "PdfText",
|
|
9
|
+
[PDF_PRIMITIVES.Image]: "PdfImage",
|
|
10
|
+
[PDF_PRIMITIVES.Link]: "PdfLink",
|
|
11
|
+
[PDF_PRIMITIVES.Note]: "PdfNote",
|
|
12
|
+
[PDF_PRIMITIVES.Tspan]: "PdfTspan",
|
|
13
|
+
[PDF_PRIMITIVES.Svg]: "PdfSvg",
|
|
14
|
+
[PDF_PRIMITIVES.G]: "PdfG",
|
|
15
|
+
[PDF_PRIMITIVES.Path]: "PdfPath",
|
|
16
|
+
[PDF_PRIMITIVES.Rect]: "PdfRect",
|
|
17
|
+
[PDF_PRIMITIVES.Circle]: "PdfCircle",
|
|
18
|
+
[PDF_PRIMITIVES.Ellipse]: "PdfEllipse",
|
|
19
|
+
[PDF_PRIMITIVES.Line]: "PdfLine",
|
|
20
|
+
[PDF_PRIMITIVES.Polyline]: "PdfPolyline",
|
|
21
|
+
[PDF_PRIMITIVES.Polygon]: "PdfPolygon",
|
|
22
|
+
[PDF_PRIMITIVES.Defs]: "PdfDefs",
|
|
23
|
+
[PDF_PRIMITIVES.ClipPath]: "PdfClipPath",
|
|
24
|
+
[PDF_PRIMITIVES.LinearGradient]: "PdfLinearGradient",
|
|
25
|
+
[PDF_PRIMITIVES.RadialGradient]: "PdfRadialGradient",
|
|
26
|
+
[PDF_PRIMITIVES.Stop]: "PdfStop"
|
|
27
|
+
};
|
|
28
|
+
export const PDF_COMMENT = Symbol("nuxt-pdf-comment");
|
|
29
|
+
const ELEMENT_TYPES = /* @__PURE__ */ new Set([
|
|
30
|
+
PDF_PRIMITIVES.Document,
|
|
31
|
+
PDF_PRIMITIVES.Page,
|
|
32
|
+
PDF_PRIMITIVES.View,
|
|
33
|
+
PDF_PRIMITIVES.Text,
|
|
34
|
+
PDF_PRIMITIVES.Image,
|
|
35
|
+
PDF_PRIMITIVES.Link,
|
|
36
|
+
PDF_PRIMITIVES.Note,
|
|
37
|
+
PDF_PRIMITIVES.Tspan,
|
|
38
|
+
PDF_PRIMITIVES.Svg,
|
|
39
|
+
PDF_PRIMITIVES.G,
|
|
40
|
+
PDF_PRIMITIVES.Path,
|
|
41
|
+
PDF_PRIMITIVES.Rect,
|
|
42
|
+
PDF_PRIMITIVES.Circle,
|
|
43
|
+
PDF_PRIMITIVES.Ellipse,
|
|
44
|
+
PDF_PRIMITIVES.Line,
|
|
45
|
+
PDF_PRIMITIVES.Polyline,
|
|
46
|
+
PDF_PRIMITIVES.Polygon,
|
|
47
|
+
PDF_PRIMITIVES.Defs,
|
|
48
|
+
PDF_PRIMITIVES.ClipPath,
|
|
49
|
+
PDF_PRIMITIVES.LinearGradient,
|
|
50
|
+
PDF_PRIMITIVES.RadialGradient,
|
|
51
|
+
PDF_PRIMITIVES.Stop
|
|
52
|
+
]);
|
|
53
|
+
export const isPdfElementType = (value) => ELEMENT_TYPES.has(value);
|
|
54
|
+
export const isPdfElementNode = (node) => "type" in node && node.type !== PDF_PRIMITIVES.TextInstance;
|
|
55
|
+
export const isPdfTextInstance = (node) => "type" in node && node.type === PDF_PRIMITIVES.TextInstance;
|
|
56
|
+
export const isPdfCommentNode = (node) => PDF_COMMENT in node;
|