@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.
Files changed (75) hide show
  1. package/API_REPORT.md +262 -0
  2. package/CHANGELOG.md +168 -0
  3. package/CONFORMANCE.md +496 -0
  4. package/LICENSE +21 -0
  5. package/README.md +203 -0
  6. package/THIRD_PARTY_NOTICES.md +75 -0
  7. package/dist/module.d.mts +24 -0
  8. package/dist/module.json +12 -0
  9. package/dist/module.mjs +368 -0
  10. package/dist/runtime/authoring.d.ts +141 -0
  11. package/dist/runtime/authoring.js +25 -0
  12. package/dist/runtime/components/_props.d.ts +196 -0
  13. package/dist/runtime/components/_props.js +63 -0
  14. package/dist/runtime/components/document.d.ts +9 -0
  15. package/dist/runtime/components/document.js +26 -0
  16. package/dist/runtime/components/index.d.ts +4 -0
  17. package/dist/runtime/components/index.js +27 -0
  18. package/dist/runtime/components/svg.d.ts +17 -0
  19. package/dist/runtime/components/svg.js +50 -0
  20. package/dist/runtime/composables/index.d.ts +2 -0
  21. package/dist/runtime/composables/index.js +3 -0
  22. package/dist/runtime/composables/use-pdf-page-numbers.d.ts +39 -0
  23. package/dist/runtime/composables/use-pdf-page-numbers.js +17 -0
  24. package/dist/runtime/define-pdf.d.ts +6 -0
  25. package/dist/runtime/define-pdf.js +5 -0
  26. package/dist/runtime/fonts.d.ts +16 -0
  27. package/dist/runtime/fonts.js +0 -0
  28. package/dist/runtime/renderer/index.d.ts +3 -0
  29. package/dist/runtime/renderer/index.js +1 -0
  30. package/dist/runtime/renderer/node-ops.d.ts +5 -0
  31. package/dist/runtime/renderer/node-ops.js +281 -0
  32. package/dist/runtime/renderer/patch-prop.d.ts +3 -0
  33. package/dist/runtime/renderer/patch-prop.js +223 -0
  34. package/dist/runtime/renderer/render-component.d.ts +14 -0
  35. package/dist/runtime/renderer/render-component.js +201 -0
  36. package/dist/runtime/renderer/types.d.ts +33 -0
  37. package/dist/runtime/renderer/types.js +56 -0
  38. package/dist/runtime/renderer/validate-tree.d.ts +3 -0
  39. package/dist/runtime/renderer/validate-tree.js +428 -0
  40. package/dist/runtime/server/assets/errors.d.ts +12 -0
  41. package/dist/runtime/server/assets/errors.js +15 -0
  42. package/dist/runtime/server/assets/remote.d.ts +48 -0
  43. package/dist/runtime/server/assets/remote.js +234 -0
  44. package/dist/runtime/server/assets/resolve-asset.d.ts +53 -0
  45. package/dist/runtime/server/assets/resolve-asset.js +482 -0
  46. package/dist/runtime/server/engine/CONTRACTS.md +386 -0
  47. package/dist/runtime/server/engine/fonts.d.ts +8 -0
  48. package/dist/runtime/server/engine/fonts.js +19 -0
  49. package/dist/runtime/server/engine/layout-passes.d.ts +42 -0
  50. package/dist/runtime/server/engine/layout-passes.js +58 -0
  51. package/dist/runtime/server/engine/react-pdf-pdfkit.d.ts +7 -0
  52. package/dist/runtime/server/engine/render-document.d.ts +31 -0
  53. package/dist/runtime/server/engine/render-document.js +236 -0
  54. package/dist/runtime/server/index.d.ts +5 -0
  55. package/dist/runtime/server/index.js +9 -0
  56. package/dist/runtime/server/preview.d.ts +17 -0
  57. package/dist/runtime/server/preview.js +332 -0
  58. package/dist/runtime/server/registry.d.ts +41 -0
  59. package/dist/runtime/server/registry.js +270 -0
  60. package/dist/runtime/server/render-limits.d.ts +51 -0
  61. package/dist/runtime/server/render-limits.js +143 -0
  62. package/dist/runtime/server/result.d.ts +6 -0
  63. package/dist/runtime/server/result.js +81 -0
  64. package/dist/runtime/server/tsconfig.json +3 -0
  65. package/dist/runtime/shared/errors.d.ts +22 -0
  66. package/dist/runtime/shared/errors.js +22 -0
  67. package/dist/runtime/shared/index.d.ts +4 -0
  68. package/dist/runtime/shared/index.js +7 -0
  69. package/dist/runtime/shared/template.d.ts +63 -0
  70. package/dist/runtime/shared/template.js +1 -0
  71. package/dist/shared/nuxt-pdf.D2ZziYn4.mjs +1132 -0
  72. package/dist/test.d.mts +198 -0
  73. package/dist/test.mjs +696 -0
  74. package/dist/types.d.mts +13 -0
  75. package/package.json +135 -0
@@ -0,0 +1,198 @@
1
+ import { PdfRenderResult, PdfComponentProps } from '../dist/runtime/shared/template.js';
2
+ export { PdfComponentProps } from '../dist/runtime/shared/template.js';
3
+ import { Component } from 'vue';
4
+ import { ModuleOptions } from './module.mjs';
5
+ import '@nuxt/schema';
6
+ import '../dist/runtime/server/assets/remote.js';
7
+ import '../dist/runtime/server/render-limits.js';
8
+ import '../dist/runtime/fonts.js';
9
+ import '../dist/runtime/authoring.js';
10
+ import '../dist/runtime/components/index.js';
11
+
12
+ /** Raw PDF (or PNG) bytes accepted by the low-level readers. */
13
+ type PdfData = ArrayBuffer | Uint8Array;
14
+ /** Anything the public `parsePdf`/`rasterizePdf` accept: bytes or a render result. */
15
+ type PdfInput = PdfData | PdfRenderResult;
16
+ interface PdfAnnotationReference {
17
+ generation: number;
18
+ number: number;
19
+ }
20
+ type PdfAnnotationDestination = string | Array<string | number | null | PdfAnnotationReference>;
21
+ interface PdfAnnotation {
22
+ annotationType?: number;
23
+ destination?: PdfAnnotationDestination;
24
+ rect?: number[];
25
+ subtype: string;
26
+ unsafeUrl?: string;
27
+ url?: string;
28
+ }
29
+ /** A link annotation flattened to the fields users assert against. */
30
+ interface ParsedPdfLink {
31
+ /** 1-based page the link sits on. */
32
+ page: number;
33
+ /** Named internal destination (e.g. a `#id` target), when the link is internal. */
34
+ destination?: string;
35
+ /** External URL, when the link points outside the document. */
36
+ url?: string;
37
+ }
38
+ /** A normalized PDF.js text run for tolerant layout and typography assertions. */
39
+ interface ParsedPdfTextRun {
40
+ direction: string;
41
+ fontName: string;
42
+ fontSize: number;
43
+ height: number;
44
+ text: string;
45
+ width: number;
46
+ x: number;
47
+ y: number;
48
+ }
49
+ interface ParsedPdfPage {
50
+ annotations: PdfAnnotation[];
51
+ height: number;
52
+ number: number;
53
+ rawText: string;
54
+ text: string;
55
+ textItems: string[];
56
+ textRuns: ParsedPdfTextRun[];
57
+ width: number;
58
+ }
59
+ interface PdfOutlineItem {
60
+ title: string;
61
+ /** Initial viewer state for entries with children. Absent on leaf entries. */
62
+ expanded?: boolean;
63
+ children: PdfOutlineItem[];
64
+ }
65
+ interface ParsedPdf {
66
+ pageCount: number;
67
+ pages: ParsedPdfPage[];
68
+ /** Every link annotation in the document, flattened across pages. */
69
+ links: ParsedPdfLink[];
70
+ /** The bookmark tree (outline), including initial expansion state. */
71
+ outline: PdfOutlineItem[];
72
+ }
73
+ interface RasterizePdfOptions {
74
+ background?: string;
75
+ scale?: number;
76
+ }
77
+ interface PdfPageImage {
78
+ height: number;
79
+ number: number;
80
+ pixels: Uint8ClampedArray;
81
+ png: Uint8Array;
82
+ width: number;
83
+ }
84
+ interface PageImageComparison {
85
+ changedPixelRatio: number;
86
+ changedPixels: number;
87
+ dimensionsMatch: boolean;
88
+ matches: boolean;
89
+ maxChannelDifference: number;
90
+ pageNumbersMatch: boolean;
91
+ totalPixels: number;
92
+ }
93
+ /** Resolve any accepted input (bytes or a `PdfRenderResult`) to raw PDF bytes. */
94
+ declare function toPdfBytes(input: PdfInput): Promise<Uint8Array>;
95
+ /** Parse stable, semantic information from every page of a PDF. */
96
+ declare function parsePdf(input: PdfInput): Promise<ParsedPdf>;
97
+ /** Rasterize every PDF page independently for deterministic page-level diffs. */
98
+ declare function rasterizePdf(input: PdfInput, options?: RasterizePdfOptions): Promise<PdfPageImage[]>;
99
+
100
+ /**
101
+ * Error thrown by the `expectPdf` helpers. Named so test runners surface it like
102
+ * their own assertion errors, without this module depending on any runner.
103
+ */
104
+ declare class PdfAssertionError extends Error {
105
+ constructor(message: string);
106
+ }
107
+ interface ToContainTextOptions {
108
+ /** Restrict the search to a single 1-based page. */
109
+ page?: number;
110
+ }
111
+ type LinkQuery = {
112
+ destination: string;
113
+ page?: number;
114
+ } | {
115
+ url: string;
116
+ page?: number;
117
+ } | {
118
+ destination: string;
119
+ url: string;
120
+ page?: number;
121
+ };
122
+ /** A partial outline shape: title is required; state and children are optional. */
123
+ interface OutlineShape {
124
+ title: string;
125
+ expanded?: boolean;
126
+ children?: OutlineShape[];
127
+ }
128
+ interface PdfExpectation {
129
+ toHavePageCount(count: number): PdfExpectation;
130
+ toContainText(text: string, options?: ToContainTextOptions): PdfExpectation;
131
+ toHaveLink(query: LinkQuery): PdfExpectation;
132
+ toHaveOutline(shape: OutlineShape[]): PdfExpectation;
133
+ }
134
+ /**
135
+ * Fluent, runner-agnostic assertions over a `ParsedPdf`. Every method returns the
136
+ * same expectation so calls chain, and throws a `PdfAssertionError` on failure
137
+ * with a message naming what was expected and what the document actually holds.
138
+ */
139
+ declare function expectPdf(parsed: ParsedPdf): PdfExpectation;
140
+
141
+ /** User-shaped render policy, matching the corresponding Nuxt module options. */
142
+ type RenderPdfTemplateOptions = Pick<ModuleOptions, 'limits' | 'remote'>;
143
+ interface RenderedPdfTemplate {
144
+ /** The rendered PDF bytes. */
145
+ bytes: Uint8Array;
146
+ /** The parsed document, ready for `expectPdf`. */
147
+ parsed: ParsedPdf;
148
+ /** The underlying completed result (diagnostics, bytes, buffer, and response). */
149
+ result: PdfRenderResult;
150
+ }
151
+ /**
152
+ * Render a Vue PDF component through the real Nuxt PDF pipeline — mount, asset
153
+ * resolution, font registration, single- or multi-pass layout — without booting
154
+ * Nuxt, then parse the bytes so a test can assert against them immediately.
155
+ */
156
+ declare function renderPdfTemplate<C extends Component>(component: C, props: PdfComponentProps<C>, options?: RenderPdfTemplateOptions): Promise<RenderedPdfTemplate>;
157
+
158
+ /** User-shaped SFC render configuration, matching the Nuxt module options. */
159
+ type RenderPdfSfcOptions = RenderPdfTemplateOptions & Pick<ModuleOptions, 'fonts'>;
160
+ /** Compile a real PDF SFC graph with the same compiler used by the Nuxt module. */
161
+ declare function loadPdfSfc(filename: string): Promise<Component>;
162
+ /** Compile and render a real `pdfs/*.vue` template with production resource handling. */
163
+ declare function renderPdfSfc<Props extends object>(filename: string, props: Props, options?: RenderPdfSfcOptions): Promise<RenderedPdfTemplate>;
164
+
165
+ interface ComparePdfSnapshotOptions {
166
+ /** Directory for expected, actual, diff, and JSON failure artifacts. */
167
+ artifactDir?: string;
168
+ /** Maximum ratio of changed pixels allowed per page (default 0.005). */
169
+ threshold?: number;
170
+ /** Maximum per-channel RGBA difference for a matching pixel (default 25). */
171
+ channelThreshold?: number;
172
+ /** Raster scale (default 1). */
173
+ scale?: number;
174
+ /**
175
+ * Write the current render as the reviewed baseline instead of comparing.
176
+ * Defaults to `process.env.UPDATE_PDF_BASELINES === '1'`.
177
+ */
178
+ update?: boolean;
179
+ }
180
+ interface PdfSnapshotResult {
181
+ /** Whether the render matched the reviewed baseline. */
182
+ matches: boolean;
183
+ /** Whether the baseline was (re)written this run. */
184
+ updated: boolean;
185
+ /** Per-page comparison detail (empty when the baseline was written). */
186
+ pages: PageImageComparison[];
187
+ }
188
+ /**
189
+ * Compare a rendered PDF against a directory of reviewed per-page PNG baselines,
190
+ * following the `UPDATE_PDF_BASELINES` review policy. With `update` (or the env
191
+ * flag) set, it (re)writes the baselines and returns; otherwise it rasterizes the
192
+ * document, checks every page against `baselineDir/page-N.png`, and throws a
193
+ * `PdfAssertionError` on any mismatch.
194
+ */
195
+ declare function comparePdfSnapshot(input: PdfInput, baselineDir: string, options?: ComparePdfSnapshotOptions): Promise<PdfSnapshotResult>;
196
+
197
+ export { PdfAssertionError, comparePdfSnapshot, expectPdf, loadPdfSfc, parsePdf, rasterizePdf, renderPdfSfc, renderPdfTemplate, toPdfBytes };
198
+ export type { ComparePdfSnapshotOptions, LinkQuery, OutlineShape, ParsedPdf, ParsedPdfLink, ParsedPdfPage, ParsedPdfTextRun, PdfExpectation, PdfInput, PdfOutlineItem, PdfPageImage, PdfSnapshotResult, RasterizePdfOptions, RenderPdfSfcOptions, RenderPdfTemplateOptions, RenderedPdfTemplate, ToContainTextOptions };