@lupinum/nuxt-pdf 0.4.0-beta.1 → 0.4.0-beta.2
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/CHANGELOG.md +20 -0
- package/CONFORMANCE.md +5 -5
- package/dist/module.json +1 -1
- package/dist/module.mjs +11 -4
- package/dist/runtime/fonts.d.ts +1 -1
- package/dist/runtime/renderer/index.d.ts +1 -0
- package/dist/runtime/renderer/index.js +1 -0
- package/dist/runtime/server/engine/fonts.js +1 -1
- package/dist/runtime/server/engine/render-document.d.ts +7 -0
- package/dist/runtime/server/engine/render-document.js +47 -0
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/preview.js +9 -1
- package/dist/runtime/server/registry.d.ts +1 -1
- package/dist/runtime/server/registry.js +9 -1
- package/dist/runtime/server/result.js +1 -0
- package/dist/runtime/shared/index.d.ts +1 -1
- package/dist/runtime/shared/template.d.ts +8 -0
- package/dist/shared/{nuxt-pdf._V584vX4.mjs → nuxt-pdf.D0zmsct0.mjs} +50 -8
- package/dist/test.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@ All notable changes to `@lupinum/nuxt-pdf` are recorded here. The format follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project adheres
|
|
5
5
|
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.4.0-beta.2 - 2026-08-27
|
|
8
|
+
|
|
9
|
+
[compare changes](https://github.com/lupinum-dev/nuxt-pdf/compare/v0.4.0-beta.1...v0.4.0-beta.2)
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **fonts:** Support WOFF2 assets ([ad50390](https://github.com/lupinum-dev/nuxt-pdf/commit/ad50390))
|
|
14
|
+
- **diagnostics:** Explain unbreakable layout overflow ([a5ff0b7](https://github.com/lupinum-dev/nuxt-pdf/commit/a5ff0b7))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **ci:** Harden on-demand Vercel reporting ([#35](https://github.com/lupinum-dev/nuxt-pdf/pull/35))
|
|
19
|
+
- **release:** Repair from certified source evidence ([#36](https://github.com/lupinum-dev/nuxt-pdf/pull/36))
|
|
20
|
+
- **release:** Separate publication from repair ([#37](https://github.com/lupinum-dev/nuxt-pdf/pull/37))
|
|
21
|
+
- **types:** Expose PDF authoring globals ([c427310](https://github.com/lupinum-dev/nuxt-pdf/commit/c427310))
|
|
22
|
+
|
|
23
|
+
### CI
|
|
24
|
+
|
|
25
|
+
- **vercel:** Cut library preview build usage ([#34](https://github.com/lupinum-dev/nuxt-pdf/pull/34))
|
|
26
|
+
|
|
7
27
|
## 0.4.0-beta.1 - 2026-08-22
|
|
8
28
|
|
|
9
29
|
### Added
|
package/CONFORMANCE.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Nuxt PDF 0.4.0-beta.
|
|
1
|
+
# Nuxt PDF 0.4.0-beta.2 conformance
|
|
2
2
|
|
|
3
3
|
Nuxt PDF claims behavioral compatibility for a deliberately small, tested
|
|
4
4
|
corpus. It does not claim full React PDF API or test-suite compatibility.
|
|
5
5
|
|
|
6
6
|
## Version boundary
|
|
7
7
|
|
|
8
|
-
| Layer | 0.4.0-beta.
|
|
8
|
+
| Layer | 0.4.0-beta.2 boundary |
|
|
9
9
|
|---|---|
|
|
10
10
|
| Node.js | `^22.14.0`, `^24.0.0`, or `^26.0.0` |
|
|
11
11
|
| Nuxt | `^4.4.8` |
|
|
@@ -204,7 +204,7 @@ checking.
|
|
|
204
204
|
|
|
205
205
|
### Vue and Nuxt authoring
|
|
206
206
|
|
|
207
|
-
The 0.4.0-beta.
|
|
207
|
+
The 0.4.0-beta.2 tests verify:
|
|
208
208
|
|
|
209
209
|
- `PdfDocument`, `PdfPage`, `PdfView`, `PdfText`, `PdfImage`, `PdfLink`, and
|
|
210
210
|
`PdfNote`;
|
|
@@ -326,7 +326,7 @@ point at the source files and re-read them per render, so an edited image
|
|
|
326
326
|
shows up without a restart. The tested boundary includes:
|
|
327
327
|
|
|
328
328
|
- PNG and JPEG extension/signature validation and source byte limits;
|
|
329
|
-
- TTF and
|
|
329
|
+
- TTF, OTF, and WOFF2 signature/extension/structure validation,
|
|
330
330
|
registration validation, source byte limits, and source-removal rendering;
|
|
331
331
|
- explicit local `pdfs/assets` and `pdfs/fonts` roots;
|
|
332
332
|
- rejection of absolute paths, traversal, missing assets, ambiguous sources,
|
|
@@ -437,7 +437,7 @@ parser, not two. Claimed:
|
|
|
437
437
|
Verified end-to-end against a real rendered template, including assertion
|
|
438
438
|
failure messages, in `test/test-utils-public.test.ts`.
|
|
439
439
|
|
|
440
|
-
## Explicitly not claimed in 0.4.0-beta.
|
|
440
|
+
## Explicitly not claimed in 0.4.0-beta.2
|
|
441
441
|
|
|
442
442
|
- Full React PDF component, hook, browser-helper, or test-suite parity.
|
|
443
443
|
- React runtime compatibility or React-shaped dynamic callback results.
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { Buffer } from 'node:buffer';
|
|
|
3
3
|
import { join, isAbsolute, resolve, relative } from 'node:path';
|
|
4
4
|
import { defineNuxtModule, createResolver, getLayerDirectories, createIsIgnored, addServerTemplate, addTemplate, addImports, addTypeTemplate, logger, addServerHandler, addComponent } from '@nuxt/kit';
|
|
5
5
|
import { joinURL } from 'ufo';
|
|
6
|
-
import { d as discoverPdfTemplates, a as discoverPdfComponentFiles, b as discoverPdfImageFiles, c as bundlePdfFonts, e as createPdfSfcPlugin, f as classifyPdfWatchEvent } from './shared/nuxt-pdf.
|
|
6
|
+
import { d as discoverPdfTemplates, a as discoverPdfComponentFiles, b as discoverPdfImageFiles, c as bundlePdfFonts, e as createPdfSfcPlugin, f as classifyPdfWatchEvent } from './shared/nuxt-pdf.D0zmsct0.mjs';
|
|
7
7
|
import { pdfImageFormatFromKey, loadPdfImageAsset } from '../dist/runtime/server/assets/resolve-asset.js';
|
|
8
8
|
import { PDF_STUB_NAMES } from '../dist/runtime/components/stubs.js';
|
|
9
9
|
import { normalizeRemoteAssetPolicy } from '../dist/runtime/server/assets/remote.js';
|
|
@@ -15,7 +15,7 @@ import 'esbuild';
|
|
|
15
15
|
import 'unimport';
|
|
16
16
|
import '../dist/runtime/shared/template.js';
|
|
17
17
|
|
|
18
|
-
const version = "0.4.0-beta.
|
|
18
|
+
const version = "0.4.0-beta.2";
|
|
19
19
|
|
|
20
20
|
const compareText = (left, right) => {
|
|
21
21
|
if (left < right) return -1;
|
|
@@ -194,7 +194,12 @@ const existingDirectories = async (directories) => {
|
|
|
194
194
|
}
|
|
195
195
|
return result;
|
|
196
196
|
};
|
|
197
|
-
const generateAuthoringTypes = (componentsImport) => `declare
|
|
197
|
+
const generateAuthoringTypes = (componentsImport, composablesImport, definePdfImport) => `declare global {
|
|
198
|
+
const definePdf: typeof import(${quote(definePdfImport)})['definePdf']
|
|
199
|
+
const usePdfPageNumbers: typeof import(${quote(composablesImport)})['usePdfPageNumbers']
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
declare module 'vue' {
|
|
198
203
|
interface GlobalComponents {
|
|
199
204
|
PdfDocument: typeof import(${quote(componentsImport)})['PdfDocument']
|
|
200
205
|
PdfImage: typeof import(${quote(componentsImport)})['PdfImage']
|
|
@@ -331,7 +336,9 @@ const module$1 = defineNuxtModule({
|
|
|
331
336
|
addTypeTemplate({
|
|
332
337
|
filename: "types/nuxt-pdf-authoring.d.ts",
|
|
333
338
|
getContents: () => generateAuthoringTypes(
|
|
334
|
-
componentsImport
|
|
339
|
+
componentsImport,
|
|
340
|
+
composablesImport,
|
|
341
|
+
definePdfImport
|
|
335
342
|
),
|
|
336
343
|
write: true
|
|
337
344
|
}, { nitro: true, node: true, nuxt: true });
|
package/dist/runtime/fonts.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface PdfFontDeclaration {
|
|
|
7
7
|
fontStyle?: PdfFontStyle;
|
|
8
8
|
fontWeight?: PdfFontWeight;
|
|
9
9
|
}
|
|
10
|
-
export type PdfFontDataUrl = `data:font/${'otf' | 'ttf'};base64,${string}`;
|
|
10
|
+
export type PdfFontDataUrl = `data:font/${'otf' | 'ttf' | 'woff2'};base64,${string}`;
|
|
11
11
|
export interface BundledPdfFontDescriptor {
|
|
12
12
|
family: string;
|
|
13
13
|
src: PdfFontDataUrl;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { mountPdfComponent } from './render-component.js';
|
|
2
|
+
export { PDF_PRIMITIVE_NAMES } from './types.js';
|
|
2
3
|
export type { MountedPdfComponent, PdfComponentProps, } from './render-component.js';
|
|
3
4
|
export type { PdfDocumentNode, PdfElementNode, PdfNode, PdfRoot, PdfTextInstance, } from './types.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import FontStore from "@react-pdf/font";
|
|
2
|
-
const isBundledFontSource = (src) => /^data:font\/(?:otf|ttf);base64,[A-Za-z0-9+/]+={0,2}$/.test(src);
|
|
2
|
+
const isBundledFontSource = (src) => /^data:font\/(?:otf|ttf|woff2);base64,[A-Za-z0-9+/]+={0,2}$/.test(src);
|
|
3
3
|
export const createPdfFontStore = (fonts = []) => {
|
|
4
4
|
const fontStore = new FontStore();
|
|
5
5
|
for (const font of fonts) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type DocumentNode, type SafeDocumentNode } from '@react-pdf/layout';
|
|
2
2
|
import { type PdfFontStore } from './fonts.js';
|
|
3
|
+
import type { PdfLayoutWarning } from '../../shared/template.js';
|
|
3
4
|
import { type RenderLimits } from '../render-limits.js';
|
|
4
5
|
export interface PdfEngineOptions {
|
|
5
6
|
compress?: boolean;
|
|
@@ -16,6 +17,12 @@ type DocumentMetadata = DocumentNode['props'];
|
|
|
16
17
|
export declare const layoutPdfTree: (document: DocumentNode, fontStore: PdfFontStore, limits?: RenderLimits) => Promise<SafeDocumentNode>;
|
|
17
18
|
/** The number of laid-out pages in a serialized document. */
|
|
18
19
|
export declare const countPages: (layout: SafeDocumentNode) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Find blocks that cannot fit on any ordinary page because pagination is not
|
|
22
|
+
* allowed to split them. No text, ids, or other authored content enters the
|
|
23
|
+
* public diagnostics object.
|
|
24
|
+
*/
|
|
25
|
+
export declare const collectLayoutWarnings: (layout: SafeDocumentNode) => PdfLayoutWarning[];
|
|
19
26
|
/**
|
|
20
27
|
* Map every `id` (named destination) to the **first** 1-based page it appears
|
|
21
28
|
* on. `id` is the key `render/src/operations/setDestination.ts` emits and that a
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
PDF_PRIMITIVES
|
|
14
14
|
} from "../../authoring.js";
|
|
15
|
+
import { PDF_PRIMITIVE_NAMES } from "../../renderer/index.js";
|
|
15
16
|
import {
|
|
16
17
|
enforceMaxPages
|
|
17
18
|
} from "../render-limits.js";
|
|
@@ -117,6 +118,52 @@ const visitPageNodes = (page, visit) => {
|
|
|
117
118
|
};
|
|
118
119
|
const documentPages = (layout) => layout.children ?? [];
|
|
119
120
|
export const countPages = (layout) => documentPages(layout).length;
|
|
121
|
+
const NON_WRAPPING_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
122
|
+
PDF_PRIMITIVES.Image,
|
|
123
|
+
PDF_PRIMITIVES.Note,
|
|
124
|
+
PDF_PRIMITIVES.Svg
|
|
125
|
+
]);
|
|
126
|
+
const WARNING_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
127
|
+
PDF_PRIMITIVES.Image,
|
|
128
|
+
PDF_PRIMITIVES.Link,
|
|
129
|
+
PDF_PRIMITIVES.Note,
|
|
130
|
+
PDF_PRIMITIVES.Svg,
|
|
131
|
+
PDF_PRIMITIVES.Text,
|
|
132
|
+
PDF_PRIMITIVES.View
|
|
133
|
+
]);
|
|
134
|
+
const finiteNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
135
|
+
const roundedPoints = (value) => Math.round(value * 100) / 100;
|
|
136
|
+
const pageContentHeight = (page) => {
|
|
137
|
+
const style = page.style;
|
|
138
|
+
const pageHeight = finiteNumber(style?.height) ?? finiteNumber(page.box.height);
|
|
139
|
+
if (pageHeight === void 0) return void 0;
|
|
140
|
+
const paddingTop = finiteNumber(page.box.paddingTop) ?? finiteNumber(style?.paddingTop) ?? 0;
|
|
141
|
+
const paddingBottom = finiteNumber(page.box.paddingBottom) ?? finiteNumber(style?.paddingBottom) ?? 0;
|
|
142
|
+
return pageHeight - paddingTop - paddingBottom;
|
|
143
|
+
};
|
|
144
|
+
const cannotWrap = (node) => NON_WRAPPING_NODE_TYPES.has(node.type) || node.props.wrap === false;
|
|
145
|
+
export const collectLayoutWarnings = (layout) => {
|
|
146
|
+
const warnings = [];
|
|
147
|
+
documentPages(layout).forEach((pageNode, pageIndex) => {
|
|
148
|
+
if (!("props" in pageNode)) return;
|
|
149
|
+
const page = pageNode;
|
|
150
|
+
const availableHeight = pageContentHeight(page);
|
|
151
|
+
if (availableHeight === void 0 || availableHeight <= 0) return;
|
|
152
|
+
visitPageNodes(page, (node) => {
|
|
153
|
+
if (node === page || node.props.fixed === true || !WARNING_NODE_TYPES.has(node.type) || !cannotWrap(node)) return;
|
|
154
|
+
const nodeHeight = finiteNumber(node.box.height);
|
|
155
|
+
if (nodeHeight === void 0 || nodeHeight <= availableHeight + 1e-3) return;
|
|
156
|
+
warnings.push({
|
|
157
|
+
code: "PDF_UNBREAKABLE_NODE_OVERFLOW",
|
|
158
|
+
pageNumber: pageIndex + 1,
|
|
159
|
+
nodeType: PDF_PRIMITIVE_NAMES[node.type],
|
|
160
|
+
nodeHeight: roundedPoints(nodeHeight),
|
|
161
|
+
availableHeight: roundedPoints(availableHeight)
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
return warnings;
|
|
166
|
+
};
|
|
120
167
|
const nodeId = (node) => {
|
|
121
168
|
const id = node.props?.id;
|
|
122
169
|
return typeof id === "string" && id.length > 0 ? id : void 0;
|
|
@@ -2,4 +2,4 @@ export { createPdfPreviewEntry, createPdfRegistry, createPdfTemplate, } from './
|
|
|
2
2
|
export { NuxtPdfError, PDF_ERROR_CODES, } from '../shared/errors.js';
|
|
3
3
|
export type { PdfErrorCode } from '../shared/errors.js';
|
|
4
4
|
export type { PdfPreviewEntry, PdfPreviewEntryOptions, PdfRegistry, PdfRegistryEntries, } from './registry.js';
|
|
5
|
-
export type { PdfRenderDiagnostics, PdfRenderResult, PdfComponentProps, PdfTemplate, } from '../shared/template.js';
|
|
5
|
+
export type { PdfLayoutWarning, PdfRenderDiagnostics, PdfRenderResult, PdfComponentProps, PdfTemplate, } from '../shared/template.js';
|
|
@@ -99,6 +99,10 @@ const htmlResponse = (title, content, status = 200) => new Response(`<!doctype h
|
|
|
99
99
|
.font-faces .label { color: #8b948b; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 8px; }
|
|
100
100
|
.font-faces ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
|
|
101
101
|
.font-faces li { color: #d7ddd7; font-size: 0.85rem; line-height: 1.5; }
|
|
102
|
+
.layout-warnings { border: 1px solid #765b23; background: #211b0f; border-left: 3px solid #e2b653; border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
|
|
103
|
+
.layout-warnings .label { color: #e8c977; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 8px; }
|
|
104
|
+
.layout-warnings ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
|
|
105
|
+
.layout-warnings li { color: #f0dfb2; font-size: 0.85rem; line-height: 1.5; }
|
|
102
106
|
.error { border: 1px solid #6b2f2b; background: #1d1210; border-left: 3px solid #ef786f; border-radius: 10px; padding: 18px 20px; }
|
|
103
107
|
.error h2 { margin: 0 0 12px; font-size: 1.1rem; color: #f3d7d3; }
|
|
104
108
|
.error dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
|
|
@@ -173,13 +177,17 @@ const diagnosticsPanel = (diagnostics) => {
|
|
|
173
177
|
stat("Size", formatBytes(diagnostics.byteLength)),
|
|
174
178
|
stat("Pages", String(diagnostics.pageCount)),
|
|
175
179
|
stat("Layout passes", String(diagnostics.passes)),
|
|
180
|
+
stat("Layout warnings", String(diagnostics.layoutWarnings.length)),
|
|
176
181
|
stat("Font faces", String(diagnostics.registeredFontFaces.length))
|
|
177
182
|
].join("");
|
|
183
|
+
const warnings = diagnostics.layoutWarnings.length > 0 ? `<div class="layout-warnings"><div class="label">Layout warnings</div><ul>${diagnostics.layoutWarnings.map(
|
|
184
|
+
(warning) => `<li><strong>${escapeHtml(warning.nodeType)}</strong> on page ${warning.pageNumber} is ${warning.nodeHeight} pt tall, but only ${warning.availableHeight} pt is available. Allow it to wrap or make it smaller.</li>`
|
|
185
|
+
).join("")}</ul></div>` : "";
|
|
178
186
|
const fonts = diagnostics.registeredFontFaces.length > 0 ? `<div class="font-faces"><div class="label">Registered font faces</div><ul>${diagnostics.registeredFontFaces.map((face) => {
|
|
179
187
|
const attributes = [face.fontWeight, face.fontStyle].filter((value) => value !== void 0);
|
|
180
188
|
return `<li>${escapeHtml(face.family)}${attributes.length > 0 ? ` \u2014 ${escapeHtml(attributes.join(" "))}` : ""}</li>`;
|
|
181
189
|
}).join("")}</ul></div>` : "";
|
|
182
|
-
return `<div class="diagnostics">${stats}</div>${fonts}`;
|
|
190
|
+
return `<div class="diagnostics">${stats}</div>${warnings}${fonts}`;
|
|
183
191
|
};
|
|
184
192
|
const errorDetails = (error, fallbackKey, fallbackFile) => {
|
|
185
193
|
const code = error instanceof NuxtPdfError ? error.code : "PDF_RENDER_ERROR";
|
|
@@ -4,7 +4,7 @@ import { type PdfImageAssetMap } from './assets/resolve-asset.js';
|
|
|
4
4
|
import type { RemoteAssetPolicy } from './assets/remote.js';
|
|
5
5
|
import { type PdfRenderLimits } from './render-limits.js';
|
|
6
6
|
import type { BundledPdfFontDescriptor } from '../fonts.js';
|
|
7
|
-
export type { PdfRenderDiagnostics } from '../shared/template.js';
|
|
7
|
+
export type { PdfLayoutWarning, PdfRenderDiagnostics, } from '../shared/template.js';
|
|
8
8
|
export interface PdfTemplateRuntimeOptions {
|
|
9
9
|
assets?: PdfImageAssetMap;
|
|
10
10
|
file?: string;
|
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
createPdfImageResolutionState,
|
|
11
11
|
resolvePdfImageAssets
|
|
12
12
|
} from "./assets/resolve-asset.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
collectLayoutWarnings,
|
|
15
|
+
countPages,
|
|
16
|
+
renderDocument
|
|
17
|
+
} from "./engine/render-document.js";
|
|
14
18
|
import { renderDocumentMultiPass } from "./engine/layout-passes.js";
|
|
15
19
|
import {
|
|
16
20
|
createRenderLimits,
|
|
@@ -140,6 +144,7 @@ const renderTemplate = async (component, props, metadata, options, maxPasses, li
|
|
|
140
144
|
);
|
|
141
145
|
return {
|
|
142
146
|
bytes: result2.bytes,
|
|
147
|
+
layoutWarnings: collectLayoutWarnings(result2.layout),
|
|
143
148
|
metadata: completedMetadata(live.document, metadata),
|
|
144
149
|
passes: result2.passes,
|
|
145
150
|
pageCount: countPages(result2.layout)
|
|
@@ -150,6 +155,7 @@ const renderTemplate = async (component, props, metadata, options, maxPasses, li
|
|
|
150
155
|
const result = await renderDocument(document, { fontStore, limits });
|
|
151
156
|
return {
|
|
152
157
|
bytes: result.bytes,
|
|
158
|
+
layoutWarnings: collectLayoutWarnings(result.layout),
|
|
153
159
|
metadata: completedMetadata(mounted.document, metadata),
|
|
154
160
|
passes: 1,
|
|
155
161
|
pageCount: countPages(result.layout)
|
|
@@ -176,6 +182,7 @@ export const createPdfTemplate = (key, component, options = {}) => {
|
|
|
176
182
|
const definitionMetadata = resolveMetadata(ref, definition, props);
|
|
177
183
|
const {
|
|
178
184
|
bytes,
|
|
185
|
+
layoutWarnings,
|
|
179
186
|
metadata,
|
|
180
187
|
passes,
|
|
181
188
|
pageCount
|
|
@@ -189,6 +196,7 @@ export const createPdfTemplate = (key, component, options = {}) => {
|
|
|
189
196
|
);
|
|
190
197
|
const result = createPdfRenderResult(bytes, metadata, {
|
|
191
198
|
durationMs: performance.now() - start,
|
|
199
|
+
layoutWarnings,
|
|
192
200
|
pageCount,
|
|
193
201
|
passes,
|
|
194
202
|
registeredFontFaces: (options.fonts ?? []).map((font) => ({
|
|
@@ -43,6 +43,7 @@ export const createPdfRenderResult = (source, metadata, diagnostics) => {
|
|
|
43
43
|
const completedDiagnostics = Object.freeze({
|
|
44
44
|
byteLength: bytes.byteLength,
|
|
45
45
|
durationMs: diagnostics.durationMs,
|
|
46
|
+
layoutWarnings: Object.freeze(diagnostics.layoutWarnings.map((warning) => Object.freeze({ ...warning }))),
|
|
46
47
|
pageCount: diagnostics.pageCount,
|
|
47
48
|
passes: diagnostics.passes,
|
|
48
49
|
registeredFontFaces: Object.freeze(diagnostics.registeredFontFaces.map((face) => Object.freeze({ ...face })))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { NuxtPdfError, PDF_ERROR_CODES, } from './errors.js';
|
|
2
2
|
export type { NuxtPdfErrorOptions, PdfErrorCode, } from './errors.js';
|
|
3
3
|
export { PDF_DEFINITION_PROPERTY, } from './template.js';
|
|
4
|
-
export type { PdfComponent, PdfComponentProps, PdfDefinition, PdfDisposition, PdfMetadataValue, PdfRenderDiagnostics, PdfRenderResult, PdfResponseInit, PdfTemplate, ResolvedPdfMetadata, } from './template.js';
|
|
4
|
+
export type { PdfComponent, PdfComponentProps, PdfDefinition, PdfDisposition, PdfLayoutWarning, PdfMetadataValue, PdfRenderDiagnostics, PdfRenderResult, PdfResponseInit, PdfTemplate, ResolvedPdfMetadata, } from './template.js';
|
|
@@ -41,8 +41,16 @@ export interface PdfRenderDiagnostics {
|
|
|
41
41
|
readonly byteLength: number;
|
|
42
42
|
readonly pageCount: number;
|
|
43
43
|
readonly passes: number;
|
|
44
|
+
readonly layoutWarnings: readonly PdfLayoutWarning[];
|
|
44
45
|
readonly registeredFontFaces: readonly PdfRegisteredFontFace[];
|
|
45
46
|
}
|
|
47
|
+
export interface PdfLayoutWarning {
|
|
48
|
+
readonly code: 'PDF_UNBREAKABLE_NODE_OVERFLOW';
|
|
49
|
+
readonly pageNumber: number;
|
|
50
|
+
readonly nodeType: 'PdfImage' | 'PdfLink' | 'PdfNote' | 'PdfSvg' | 'PdfText' | 'PdfView';
|
|
51
|
+
readonly nodeHeight: number;
|
|
52
|
+
readonly availableHeight: number;
|
|
53
|
+
}
|
|
46
54
|
export interface PdfRegisteredFontFace {
|
|
47
55
|
readonly family: string;
|
|
48
56
|
readonly fontStyle?: string;
|
|
@@ -185,6 +185,7 @@ const discoverPdfImageFiles = async (layers, isIgnored) => {
|
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
const DEFAULT_MAX_PDF_FONT_BYTES = 5 * 1024 * 1024;
|
|
188
|
+
const DEFAULT_MAX_PDF_DECOMPRESSED_FONT_BYTES = 20 * 1024 * 1024;
|
|
188
189
|
const FONT_WEIGHT_VALUES = {
|
|
189
190
|
black: 900,
|
|
190
191
|
bold: 700,
|
|
@@ -347,13 +348,53 @@ const validateDeclaration = (declaration) => {
|
|
|
347
348
|
};
|
|
348
349
|
};
|
|
349
350
|
const detectFontFormat = (bytes) => {
|
|
350
|
-
if (bytes.byteLength <
|
|
351
|
+
if (bytes.byteLength < 4) return void 0;
|
|
351
352
|
const isTrueType = bytes[0] === 0 && bytes[1] === 1 && bytes[2] === 0 && bytes[3] === 0;
|
|
352
353
|
const isOpenType = bytes[0] === 79 && bytes[1] === 84 && bytes[2] === 84 && bytes[3] === 79;
|
|
354
|
+
const isWoff2 = bytes[0] === 119 && bytes[1] === 79 && bytes[2] === 70 && bytes[3] === 50;
|
|
353
355
|
if (isTrueType) return "ttf";
|
|
354
356
|
if (isOpenType) return "otf";
|
|
357
|
+
if (isWoff2) return "woff2";
|
|
355
358
|
return void 0;
|
|
356
359
|
};
|
|
360
|
+
const validateWoff2Structure = (source, bytes) => {
|
|
361
|
+
if (bytes.byteLength < 48) {
|
|
362
|
+
throw fontError(source, "the WOFF2 header is corrupt or truncated.");
|
|
363
|
+
}
|
|
364
|
+
const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
365
|
+
const flavor = data.readUInt32BE(4);
|
|
366
|
+
const declaredLength = data.readUInt32BE(8);
|
|
367
|
+
const tableCount = data.readUInt16BE(12);
|
|
368
|
+
const reserved = data.readUInt16BE(14);
|
|
369
|
+
const decompressedSize = data.readUInt32BE(16);
|
|
370
|
+
const compressedSize = data.readUInt32BE(20);
|
|
371
|
+
const isTrueType = flavor === 65536;
|
|
372
|
+
const isOpenType = flavor === 1330926671;
|
|
373
|
+
if (!isTrueType && !isOpenType) {
|
|
374
|
+
throw fontError(source, "the WOFF2 font must wrap a TTF or OTF font.");
|
|
375
|
+
}
|
|
376
|
+
if (declaredLength !== bytes.byteLength || tableCount < 1 || tableCount > 4096 || reserved !== 0 || compressedSize < 1 || compressedSize > bytes.byteLength - 48) {
|
|
377
|
+
throw fontError(source, "the WOFF2 header is corrupt or truncated.");
|
|
378
|
+
}
|
|
379
|
+
if (decompressedSize < 12 || decompressedSize > DEFAULT_MAX_PDF_DECOMPRESSED_FONT_BYTES) {
|
|
380
|
+
throw fontError(
|
|
381
|
+
source,
|
|
382
|
+
`the decompressed WOFF2 font exceeds the ${DEFAULT_MAX_PDF_DECOMPRESSED_FONT_BYTES}-byte limit.`
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
const metadataOffset = data.readUInt32BE(28);
|
|
386
|
+
const metadataLength = data.readUInt32BE(32);
|
|
387
|
+
const metadataOriginalLength = data.readUInt32BE(36);
|
|
388
|
+
const privateOffset = data.readUInt32BE(40);
|
|
389
|
+
const privateLength = data.readUInt32BE(44);
|
|
390
|
+
const metadataAbsent = metadataOffset === 0 && metadataLength === 0 && metadataOriginalLength === 0;
|
|
391
|
+
const metadataPresent = metadataOffset >= 48 && metadataLength > 0 && metadataOriginalLength > 0 && metadataOffset + metadataLength <= bytes.byteLength;
|
|
392
|
+
const privateAbsent = privateOffset === 0 && privateLength === 0;
|
|
393
|
+
const privatePresent = privateOffset >= 48 && privateLength > 0 && privateOffset + privateLength <= bytes.byteLength;
|
|
394
|
+
if (!metadataAbsent && !metadataPresent || !privateAbsent && !privatePresent) {
|
|
395
|
+
throw fontError(source, "the WOFF2 optional data blocks are corrupt.");
|
|
396
|
+
}
|
|
397
|
+
};
|
|
357
398
|
const validateSfntStructure = (source, bytes, format) => {
|
|
358
399
|
const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
359
400
|
const tableCount = data.readUInt16BE(4);
|
|
@@ -380,20 +421,21 @@ const validateSfntStructure = (source, bytes, format) => {
|
|
|
380
421
|
};
|
|
381
422
|
const fontFormat = (source, bytes) => {
|
|
382
423
|
const extension = extname(source).toLowerCase();
|
|
383
|
-
if (extension !== ".otf" && extension !== ".ttf") {
|
|
384
|
-
throw fontError(source, "only .ttf and .
|
|
424
|
+
if (extension !== ".otf" && extension !== ".ttf" && extension !== ".woff2") {
|
|
425
|
+
throw fontError(source, "only .ttf, .otf, and .woff2 files are supported.");
|
|
385
426
|
}
|
|
386
|
-
if (bytes.byteLength <
|
|
387
|
-
throw fontError(source, "the file is too small to be a
|
|
427
|
+
if (bytes.byteLength < 4) {
|
|
428
|
+
throw fontError(source, "the file is too small to be a supported font.");
|
|
388
429
|
}
|
|
389
430
|
const format = detectFontFormat(bytes);
|
|
390
431
|
if (!format) {
|
|
391
|
-
throw fontError(source, "the file has an unsupported
|
|
432
|
+
throw fontError(source, "the file has an unsupported font signature.");
|
|
392
433
|
}
|
|
393
434
|
if (`.${format}` !== extension) {
|
|
394
|
-
throw fontError(source, "the file extension does not match its
|
|
435
|
+
throw fontError(source, "the file extension does not match its font signature.");
|
|
395
436
|
}
|
|
396
|
-
|
|
437
|
+
if (format === "woff2") validateWoff2Structure(source, bytes);
|
|
438
|
+
else validateSfntStructure(source, bytes, format);
|
|
397
439
|
return format;
|
|
398
440
|
};
|
|
399
441
|
const readFont = async (source, filePath, maxBytes) => {
|
package/dist/test.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { mkdir, writeFile, rm, readFile, readdir } from 'node:fs/promises';
|
|
|
10
10
|
import { resolve, dirname, join, relative, basename } from 'node:path';
|
|
11
11
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
12
12
|
import { build } from 'esbuild';
|
|
13
|
-
import { t as templateKeyFromRelativePath, b as discoverPdfImageFiles, c as bundlePdfFonts, g as compilePdfSfc } from './shared/nuxt-pdf.
|
|
13
|
+
import { t as templateKeyFromRelativePath, b as discoverPdfImageFiles, c as bundlePdfFonts, g as compilePdfSfc } from './shared/nuxt-pdf.D0zmsct0.mjs';
|
|
14
14
|
import { pdfImageFormatFromKey } from '../dist/runtime/server/assets/resolve-asset.js';
|
|
15
15
|
import '@vue/compiler-sfc';
|
|
16
16
|
import '@jridgewell/remapping';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lupinum/nuxt-pdf",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.2",
|
|
4
4
|
"description": "Author and render PDFs with Vue components in Nuxt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"test:quickstart": "node scripts/test-package-quickstart.mjs",
|
|
81
81
|
"test:raster": "vitest run --config vitest.raster.config.ts",
|
|
82
82
|
"test:version-headings": "node scripts/check-version-headings.mjs",
|
|
83
|
-
"test:workflows": "node scripts/check-workflow-policy.mjs",
|
|
83
|
+
"test:workflows": "node scripts/check-workflow-policy.mjs && node scripts/test-npm-recovery.mjs && node scripts/test-release-recovery.mjs",
|
|
84
84
|
"check:vercel": "node scripts/check-vercel-config.mjs",
|
|
85
85
|
"test:serverless": "vitest run --config vitest.serverless.config.ts",
|
|
86
86
|
"test:watch": "vitest watch",
|