takumi-pdf 0.4.0 → 0.4.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/README.md +3 -0
- package/dist/export.cjs +6 -3
- package/dist/export.d.cts +8 -4
- package/dist/export.d.mts +8 -4
- package/dist/export.mjs +6 -3
- package/package.json +1 -1
- package/pkg/takumi_pdf_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -188,6 +188,8 @@ Omit `metadata` to keep output byte-identical across runs.
|
|
|
188
188
|
|
|
189
189
|
Output is **tagged by default**: HTML semantics (`h1`–`h6`, `p`, `img` with `alt`, `a`, lists) become a PDF structure tree, like Chromium's print-to-PDF. Set `tagged: "ua1"` to validate against PDF/UA-1, or `tagged: false` to drop the tree when file size matters more than accessibility.
|
|
190
190
|
|
|
191
|
+
`<table>` markup is not supported, and a table built out of flex rows carries no `Table` structure elements.
|
|
192
|
+
|
|
191
193
|
`pdfa` renders archival output. Validation runs during rendering. A document that cannot conform fails with the violated rule instead of writing a broken file. Every level, and PDF/UA-1, passes [veraPDF](https://verapdf.org).
|
|
192
194
|
|
|
193
195
|
```tsx
|
|
@@ -205,6 +207,7 @@ const pdf = await render(report, {
|
|
|
205
207
|
| `"2a"` / `"3a"` | A tagged structure tree. |
|
|
206
208
|
| `"3b"` / `"3u"` / `"3a"` | Arbitrary file attachments. |
|
|
207
209
|
| `"4"` | The PDF 2.0 revision of the standard. |
|
|
210
|
+
| `"4f"` | PDF 2.0 with file attachments. |
|
|
208
211
|
|
|
209
212
|
Invalid combinations are **TypeScript type errors**. See the [PDF/A docs](https://takumi.kane.tw/docs/pdf/pdf-a) for the structure-tree mapping and required metadata.
|
|
210
213
|
|
package/dist/export.cjs
CHANGED
|
@@ -2,6 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
+
let _takumi_rs_helpers_html = require("@takumi-rs/helpers/html");
|
|
5
6
|
let _takumi_rs_helpers_jsx = require("@takumi-rs/helpers/jsx");
|
|
6
7
|
let _takumi_rs_helpers_renderer = require("@takumi-rs/helpers/renderer");
|
|
7
8
|
//#region pkg/takumi_pdf_wasm.js
|
|
@@ -500,16 +501,18 @@ function isNode(value) {
|
|
|
500
501
|
return typeof value === "object" && value !== null && "type" in value && !("$$typeof" in value);
|
|
501
502
|
}
|
|
502
503
|
async function resolveNode(input) {
|
|
503
|
-
|
|
504
|
+
if (isNode(input)) return {
|
|
504
505
|
node: input,
|
|
505
506
|
stylesheets: []
|
|
506
|
-
}
|
|
507
|
+
};
|
|
508
|
+
if (typeof input === "string") return (0, _takumi_rs_helpers_html.fromHtml)(input);
|
|
509
|
+
return (0, _takumi_rs_helpers_jsx.fromJsx)(input);
|
|
507
510
|
}
|
|
508
511
|
/** A PDF renderer holding registered fonts. Reuse one instance across renders. */
|
|
509
512
|
var PdfRenderer = class {
|
|
510
513
|
inner = new PdfRenderer$1();
|
|
511
514
|
fonts = new _takumi_rs_helpers_renderer.FontRegistry((font) => this.inner.registerFont(font));
|
|
512
|
-
/** Renders a node tree or
|
|
515
|
+
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
513
516
|
async render(node, options = {}) {
|
|
514
517
|
const { fonts, images, header, footer, stylesheets, fontFamilies, ...rest } = options;
|
|
515
518
|
const [main, headerResult, footerResult, resources] = await Promise.all([
|
package/dist/export.d.cts
CHANGED
|
@@ -46,8 +46,8 @@ declare module "react" {
|
|
|
46
46
|
tw?: string;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
/** A document input: a takumi node tree or
|
|
50
|
-
type NodeInput = Node | ReactNode | ReactElementLike;
|
|
49
|
+
/** A document input: a takumi node tree, JSX, or an HTML string. */
|
|
50
|
+
type NodeInput = Node | ReactNode | ReactElementLike | string;
|
|
51
51
|
/** Explicit dimensions in CSS px (96 dpi). */
|
|
52
52
|
type Dimensions = {
|
|
53
53
|
width: number;
|
|
@@ -213,7 +213,7 @@ type ArchivalAttachment = Attachment & {
|
|
|
213
213
|
* Standards conformance. Invalid combinations are type errors: the `a` levels
|
|
214
214
|
* imply a structure tree so `tagged: false` is rejected, PDF/A-4 is PDF 2.0
|
|
215
215
|
* while PDF/UA-1 is PDF 1.7-only so they cannot combine, and only the
|
|
216
|
-
* PDF/A-3 levels (or plain PDF) accept attachments.
|
|
216
|
+
* PDF/A-3 levels, PDF/A-4f (or plain PDF) accept attachments.
|
|
217
217
|
*/
|
|
218
218
|
type ConformanceOptions = {
|
|
219
219
|
pdfa?: never;
|
|
@@ -242,6 +242,10 @@ type ConformanceOptions = {
|
|
|
242
242
|
pdfa: "4";
|
|
243
243
|
tagged?: boolean;
|
|
244
244
|
attachments?: never;
|
|
245
|
+
} | {
|
|
246
|
+
pdfa: "4f";
|
|
247
|
+
tagged?: boolean;
|
|
248
|
+
attachments?: ArchivalAttachment[];
|
|
245
249
|
};
|
|
246
250
|
type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
247
251
|
/** Fonts to register before rendering, deduped across calls. */
|
|
@@ -266,7 +270,7 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
|
266
270
|
declare class PdfRenderer {
|
|
267
271
|
private inner;
|
|
268
272
|
private fonts;
|
|
269
|
-
/** Renders a node tree or
|
|
273
|
+
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
270
274
|
render(node: NodeInput, options?: RenderOptions): Promise<Uint8Array>;
|
|
271
275
|
/**
|
|
272
276
|
* Lays out a node tree without rendering and returns its size in CSS px.
|
package/dist/export.d.mts
CHANGED
|
@@ -46,8 +46,8 @@ declare module "react" {
|
|
|
46
46
|
tw?: string;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
/** A document input: a takumi node tree or
|
|
50
|
-
type NodeInput = Node | ReactNode | ReactElementLike;
|
|
49
|
+
/** A document input: a takumi node tree, JSX, or an HTML string. */
|
|
50
|
+
type NodeInput = Node | ReactNode | ReactElementLike | string;
|
|
51
51
|
/** Explicit dimensions in CSS px (96 dpi). */
|
|
52
52
|
type Dimensions = {
|
|
53
53
|
width: number;
|
|
@@ -213,7 +213,7 @@ type ArchivalAttachment = Attachment & {
|
|
|
213
213
|
* Standards conformance. Invalid combinations are type errors: the `a` levels
|
|
214
214
|
* imply a structure tree so `tagged: false` is rejected, PDF/A-4 is PDF 2.0
|
|
215
215
|
* while PDF/UA-1 is PDF 1.7-only so they cannot combine, and only the
|
|
216
|
-
* PDF/A-3 levels (or plain PDF) accept attachments.
|
|
216
|
+
* PDF/A-3 levels, PDF/A-4f (or plain PDF) accept attachments.
|
|
217
217
|
*/
|
|
218
218
|
type ConformanceOptions = {
|
|
219
219
|
pdfa?: never;
|
|
@@ -242,6 +242,10 @@ type ConformanceOptions = {
|
|
|
242
242
|
pdfa: "4";
|
|
243
243
|
tagged?: boolean;
|
|
244
244
|
attachments?: never;
|
|
245
|
+
} | {
|
|
246
|
+
pdfa: "4f";
|
|
247
|
+
tagged?: boolean;
|
|
248
|
+
attachments?: ArchivalAttachment[];
|
|
245
249
|
};
|
|
246
250
|
type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
247
251
|
/** Fonts to register before rendering, deduped across calls. */
|
|
@@ -266,7 +270,7 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
|
266
270
|
declare class PdfRenderer {
|
|
267
271
|
private inner;
|
|
268
272
|
private fonts;
|
|
269
|
-
/** Renders a node tree or
|
|
273
|
+
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
270
274
|
render(node: NodeInput, options?: RenderOptions): Promise<Uint8Array>;
|
|
271
275
|
/**
|
|
272
276
|
* Lays out a node tree without rendering and returns its size in CSS px.
|
package/dist/export.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fromHtml } from "@takumi-rs/helpers/html";
|
|
1
2
|
import { fromJsx } from "@takumi-rs/helpers/jsx";
|
|
2
3
|
import { FontRegistry } from "@takumi-rs/helpers/renderer";
|
|
3
4
|
//#region pkg/takumi_pdf_wasm.js
|
|
@@ -496,16 +497,18 @@ function isNode(value) {
|
|
|
496
497
|
return typeof value === "object" && value !== null && "type" in value && !("$$typeof" in value);
|
|
497
498
|
}
|
|
498
499
|
async function resolveNode(input) {
|
|
499
|
-
|
|
500
|
+
if (isNode(input)) return {
|
|
500
501
|
node: input,
|
|
501
502
|
stylesheets: []
|
|
502
|
-
}
|
|
503
|
+
};
|
|
504
|
+
if (typeof input === "string") return fromHtml(input);
|
|
505
|
+
return fromJsx(input);
|
|
503
506
|
}
|
|
504
507
|
/** A PDF renderer holding registered fonts. Reuse one instance across renders. */
|
|
505
508
|
var PdfRenderer = class {
|
|
506
509
|
inner = new PdfRenderer$1();
|
|
507
510
|
fonts = new FontRegistry((font) => this.inner.registerFont(font));
|
|
508
|
-
/** Renders a node tree or
|
|
511
|
+
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
509
512
|
async render(node, options = {}) {
|
|
510
513
|
const { fonts, images, header, footer, stylesheets, fontFamilies, ...rest } = options;
|
|
511
514
|
const [main, headerResult, footerResult, resources] = await Promise.all([
|
package/package.json
CHANGED
|
Binary file
|