takumi-pdf 0.11.2 → 0.12.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/dist/export.cjs +34 -14
- package/dist/export.d.cts +15 -4
- package/dist/export.d.mts +15 -4
- package/dist/export.mjs +34 -14
- package/package.json +4 -4
- package/pkg/takumi_pdf_wasm_bg.wasm +0 -0
package/dist/export.cjs
CHANGED
|
@@ -522,16 +522,20 @@ async function __wbg_load(module, imports) {
|
|
|
522
522
|
}
|
|
523
523
|
function initSync(module) {
|
|
524
524
|
if (wasm !== void 0) return wasm;
|
|
525
|
-
if (module !== void 0)
|
|
526
|
-
|
|
525
|
+
if (module !== void 0) {
|
|
526
|
+
if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
|
|
527
|
+
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
528
|
+
}
|
|
527
529
|
const imports = __wbg_get_imports();
|
|
528
530
|
if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
|
|
529
531
|
return __wbg_finalize_init(new WebAssembly.Instance(module, imports), module);
|
|
530
532
|
}
|
|
531
533
|
async function __wbg_init(module_or_path) {
|
|
532
534
|
if (wasm !== void 0) return wasm;
|
|
533
|
-
if (module_or_path !== void 0)
|
|
534
|
-
|
|
535
|
+
if (module_or_path !== void 0) {
|
|
536
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
537
|
+
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
538
|
+
}
|
|
535
539
|
const imports = __wbg_get_imports();
|
|
536
540
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
537
541
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
@@ -554,10 +558,26 @@ function collectClassNames(node, into) {
|
|
|
554
558
|
function isNode(value) {
|
|
555
559
|
return typeof value === "object" && value !== null && "type" in value && !("$$typeof" in value);
|
|
556
560
|
}
|
|
561
|
+
let warnedStylesheets = false;
|
|
562
|
+
function warnStylesheetsDeprecated() {
|
|
563
|
+
if (warnedStylesheets) return;
|
|
564
|
+
warnedStylesheets = true;
|
|
565
|
+
console.warn("takumi: the `stylesheets` option is deprecated, use `css` instead.");
|
|
566
|
+
}
|
|
567
|
+
/** Narrows the `css` option, which takes one entry or a list of them. */
|
|
568
|
+
function isCssList(css) {
|
|
569
|
+
return Array.isArray(css);
|
|
570
|
+
}
|
|
571
|
+
function ownCss(css, stylesheets) {
|
|
572
|
+
if (css !== void 0 && stylesheets !== void 0) throw new Error("pass either `css` or `stylesheets`, not both");
|
|
573
|
+
if (css !== void 0) return isCssList(css) ? [...css] : [css];
|
|
574
|
+
if (stylesheets !== void 0) warnStylesheetsDeprecated();
|
|
575
|
+
return stylesheets ?? [];
|
|
576
|
+
}
|
|
557
577
|
async function resolveNode(input) {
|
|
558
578
|
if (isNode(input)) return {
|
|
559
579
|
node: input,
|
|
560
|
-
|
|
580
|
+
css: []
|
|
561
581
|
};
|
|
562
582
|
if (typeof input === "string") return (0, _takumi_rs_helpers_html.fromHtml)(input);
|
|
563
583
|
return (0, _takumi_rs_helpers_jsx.fromJsx)(input);
|
|
@@ -568,7 +588,7 @@ var PdfRenderer = class {
|
|
|
568
588
|
fonts = new _takumi_rs_helpers_renderer.FontRegistry((font) => this.inner.registerFont(font));
|
|
569
589
|
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
570
590
|
async render(node, options = {}) {
|
|
571
|
-
const { fonts, images, header, footer, stylesheets, fontFamilies, ...rest } = options;
|
|
591
|
+
const { fonts, images, header, footer, css, stylesheets, fontFamilies, ...rest } = options;
|
|
572
592
|
const [main, headerResult, footerResult] = await Promise.all([
|
|
573
593
|
resolveNode(node),
|
|
574
594
|
header === void 0 ? void 0 : resolveNode(header),
|
|
@@ -585,16 +605,16 @@ var PdfRenderer = class {
|
|
|
585
605
|
]
|
|
586
606
|
}), images, fontFamilies);
|
|
587
607
|
const sheets = [
|
|
588
|
-
...stylesheets
|
|
589
|
-
...main.
|
|
590
|
-
...headerResult?.
|
|
591
|
-
...footerResult?.
|
|
608
|
+
...ownCss(css, stylesheets),
|
|
609
|
+
...main.css,
|
|
610
|
+
...headerResult?.css ?? [],
|
|
611
|
+
...footerResult?.css ?? []
|
|
592
612
|
];
|
|
593
613
|
return this.inner.render(main.node, {
|
|
594
614
|
...rest,
|
|
595
615
|
header: headerResult?.node,
|
|
596
616
|
footer: footerResult?.node,
|
|
597
|
-
|
|
617
|
+
css: sheets.length > 0 ? sheets : void 0,
|
|
598
618
|
images: resources.images,
|
|
599
619
|
fontFamilies: resources.fontFamilies
|
|
600
620
|
});
|
|
@@ -611,7 +631,7 @@ var PdfRenderer = class {
|
|
|
611
631
|
* against: a box with `width: 100px` measures 100 wide on any page.
|
|
612
632
|
*/
|
|
613
633
|
async measure(node, options = {}) {
|
|
614
|
-
const { fonts, images, stylesheets, fontFamilies, ...rest } = options;
|
|
634
|
+
const { fonts, images, css, stylesheets, fontFamilies, ...rest } = options;
|
|
615
635
|
const main = await resolveNode(node);
|
|
616
636
|
const resources = await this.fonts.resolveResources(fonts && (0, _takumi_rs_helpers.subsetFonts)({
|
|
617
637
|
fonts,
|
|
@@ -621,10 +641,10 @@ var PdfRenderer = class {
|
|
|
621
641
|
counterCharacters(classNames(main.node))
|
|
622
642
|
]
|
|
623
643
|
}), images, fontFamilies);
|
|
624
|
-
const sheets = [...stylesheets
|
|
644
|
+
const sheets = [...ownCss(css, stylesheets), ...main.css];
|
|
625
645
|
return this.inner.measure(main.node, {
|
|
626
646
|
...rest,
|
|
627
|
-
|
|
647
|
+
css: sheets.length > 0 ? sheets : void 0,
|
|
628
648
|
images: resources.images,
|
|
629
649
|
fontFamilies: resources.fontFamilies
|
|
630
650
|
});
|
package/dist/export.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages } from "./primitives.cjs";
|
|
2
|
+
import { CssInput, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
2
3
|
import { FontLoader, FontLoader as FontLoader$1, ImagesInput, ImagesInput as ImagesInput$1, RegisteredFamilyLike } from "@takumi-rs/helpers/renderer";
|
|
3
|
-
import { Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
4
4
|
import { ReactNode } from "react";
|
|
5
5
|
//#region pkg/takumi_pdf_wasm.d.ts
|
|
6
6
|
type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
@@ -75,7 +75,7 @@ type PageMargin = PageMarginSide | {
|
|
|
75
75
|
/**
|
|
76
76
|
* Paged output (the default): content flows across pages of `size`, like
|
|
77
77
|
* Puppeteer's `page.pdf()`. The layout canvas has unbounded height, so
|
|
78
|
-
* percentage heights do not resolve. CSS `@page` rules in `
|
|
78
|
+
* percentage heights do not resolve. CSS `@page` rules in `css` are
|
|
79
79
|
* not supported — page geometry comes from these options.
|
|
80
80
|
*/
|
|
81
81
|
type PagedOptions = {
|
|
@@ -127,7 +127,12 @@ type MeasureOptions = ({
|
|
|
127
127
|
fonts?: FontLoader$1[];
|
|
128
128
|
/** Pre-fetched images for `src` URLs in the tree. */
|
|
129
129
|
images?: ImagesInput$1;
|
|
130
|
-
/** CSS
|
|
130
|
+
/** CSS to apply before layout, one string or a list cascading in order. */
|
|
131
|
+
css?: CssInput | readonly CssInput[];
|
|
132
|
+
/**
|
|
133
|
+
* CSS stylesheets to apply before layout.
|
|
134
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
135
|
+
*/
|
|
131
136
|
stylesheets?: string[];
|
|
132
137
|
/** Per-render font stack: ordered family names used as the fallback chain. */
|
|
133
138
|
fontFamilies?: string[];
|
|
@@ -261,8 +266,14 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
|
261
266
|
* `[{ src: "https://…/logo.png", data: bytes }]`.
|
|
262
267
|
*/
|
|
263
268
|
images?: ImagesInput$1;
|
|
264
|
-
/** CSS
|
|
269
|
+
/** CSS to apply before layout, one string or a list cascading in order. */
|
|
270
|
+
css?: CssInput | readonly CssInput[];
|
|
271
|
+
/**
|
|
272
|
+
* CSS stylesheets to apply before layout.
|
|
273
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
274
|
+
*/
|
|
265
275
|
stylesheets?: string[];
|
|
276
|
+
/** CSS custom properties for `:root`; the `--` prefix is optional. */
|
|
266
277
|
/** Per-render font stack: ordered family names used as the fallback chain. */
|
|
267
278
|
fontFamilies?: string[];
|
|
268
279
|
/** Default BCP-47 language tag applied to the root. */
|
package/dist/export.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CounterProps, CounterStyle, PageNumber, TargetPageNumber, TotalPages } from "./primitives.mjs";
|
|
2
2
|
import { FontLoader, FontLoader as FontLoader$1, ImagesInput, ImagesInput as ImagesInput$1, RegisteredFamilyLike } from "@takumi-rs/helpers/renderer";
|
|
3
|
-
import { Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
3
|
+
import { CssInput, Node, ReactElementLike } from "@takumi-rs/helpers";
|
|
4
4
|
import { ReactNode } from "react";
|
|
5
5
|
//#region pkg/takumi_pdf_wasm.d.ts
|
|
6
6
|
type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
@@ -75,7 +75,7 @@ type PageMargin = PageMarginSide | {
|
|
|
75
75
|
/**
|
|
76
76
|
* Paged output (the default): content flows across pages of `size`, like
|
|
77
77
|
* Puppeteer's `page.pdf()`. The layout canvas has unbounded height, so
|
|
78
|
-
* percentage heights do not resolve. CSS `@page` rules in `
|
|
78
|
+
* percentage heights do not resolve. CSS `@page` rules in `css` are
|
|
79
79
|
* not supported — page geometry comes from these options.
|
|
80
80
|
*/
|
|
81
81
|
type PagedOptions = {
|
|
@@ -127,7 +127,12 @@ type MeasureOptions = ({
|
|
|
127
127
|
fonts?: FontLoader$1[];
|
|
128
128
|
/** Pre-fetched images for `src` URLs in the tree. */
|
|
129
129
|
images?: ImagesInput$1;
|
|
130
|
-
/** CSS
|
|
130
|
+
/** CSS to apply before layout, one string or a list cascading in order. */
|
|
131
|
+
css?: CssInput | readonly CssInput[];
|
|
132
|
+
/**
|
|
133
|
+
* CSS stylesheets to apply before layout.
|
|
134
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
135
|
+
*/
|
|
131
136
|
stylesheets?: string[];
|
|
132
137
|
/** Per-render font stack: ordered family names used as the fallback chain. */
|
|
133
138
|
fontFamilies?: string[];
|
|
@@ -261,8 +266,14 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
|
|
|
261
266
|
* `[{ src: "https://…/logo.png", data: bytes }]`.
|
|
262
267
|
*/
|
|
263
268
|
images?: ImagesInput$1;
|
|
264
|
-
/** CSS
|
|
269
|
+
/** CSS to apply before layout, one string or a list cascading in order. */
|
|
270
|
+
css?: CssInput | readonly CssInput[];
|
|
271
|
+
/**
|
|
272
|
+
* CSS stylesheets to apply before layout.
|
|
273
|
+
* @deprecated Use `css` instead. Will be removed in v3.
|
|
274
|
+
*/
|
|
265
275
|
stylesheets?: string[];
|
|
276
|
+
/** CSS custom properties for `:root`; the `--` prefix is optional. */
|
|
266
277
|
/** Per-render font stack: ordered family names used as the fallback chain. */
|
|
267
278
|
fontFamilies?: string[];
|
|
268
279
|
/** Default BCP-47 language tag applied to the root. */
|
package/dist/export.mjs
CHANGED
|
@@ -518,16 +518,20 @@ async function __wbg_load(module, imports) {
|
|
|
518
518
|
}
|
|
519
519
|
function initSync(module) {
|
|
520
520
|
if (wasm !== void 0) return wasm;
|
|
521
|
-
if (module !== void 0)
|
|
522
|
-
|
|
521
|
+
if (module !== void 0) {
|
|
522
|
+
if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
|
|
523
|
+
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
524
|
+
}
|
|
523
525
|
const imports = __wbg_get_imports();
|
|
524
526
|
if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
|
|
525
527
|
return __wbg_finalize_init(new WebAssembly.Instance(module, imports), module);
|
|
526
528
|
}
|
|
527
529
|
async function __wbg_init(module_or_path) {
|
|
528
530
|
if (wasm !== void 0) return wasm;
|
|
529
|
-
if (module_or_path !== void 0)
|
|
530
|
-
|
|
531
|
+
if (module_or_path !== void 0) {
|
|
532
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
533
|
+
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
534
|
+
}
|
|
531
535
|
const imports = __wbg_get_imports();
|
|
532
536
|
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
533
537
|
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
@@ -550,10 +554,26 @@ function collectClassNames(node, into) {
|
|
|
550
554
|
function isNode(value) {
|
|
551
555
|
return typeof value === "object" && value !== null && "type" in value && !("$$typeof" in value);
|
|
552
556
|
}
|
|
557
|
+
let warnedStylesheets = false;
|
|
558
|
+
function warnStylesheetsDeprecated() {
|
|
559
|
+
if (warnedStylesheets) return;
|
|
560
|
+
warnedStylesheets = true;
|
|
561
|
+
console.warn("takumi: the `stylesheets` option is deprecated, use `css` instead.");
|
|
562
|
+
}
|
|
563
|
+
/** Narrows the `css` option, which takes one entry or a list of them. */
|
|
564
|
+
function isCssList(css) {
|
|
565
|
+
return Array.isArray(css);
|
|
566
|
+
}
|
|
567
|
+
function ownCss(css, stylesheets) {
|
|
568
|
+
if (css !== void 0 && stylesheets !== void 0) throw new Error("pass either `css` or `stylesheets`, not both");
|
|
569
|
+
if (css !== void 0) return isCssList(css) ? [...css] : [css];
|
|
570
|
+
if (stylesheets !== void 0) warnStylesheetsDeprecated();
|
|
571
|
+
return stylesheets ?? [];
|
|
572
|
+
}
|
|
553
573
|
async function resolveNode(input) {
|
|
554
574
|
if (isNode(input)) return {
|
|
555
575
|
node: input,
|
|
556
|
-
|
|
576
|
+
css: []
|
|
557
577
|
};
|
|
558
578
|
if (typeof input === "string") return fromHtml(input);
|
|
559
579
|
return fromJsx(input);
|
|
@@ -564,7 +584,7 @@ var PdfRenderer = class {
|
|
|
564
584
|
fonts = new FontRegistry((font) => this.inner.registerFont(font));
|
|
565
585
|
/** Renders a node tree, JSX, or an HTML string to PDF bytes. See {@link RenderOptions}. */
|
|
566
586
|
async render(node, options = {}) {
|
|
567
|
-
const { fonts, images, header, footer, stylesheets, fontFamilies, ...rest } = options;
|
|
587
|
+
const { fonts, images, header, footer, css, stylesheets, fontFamilies, ...rest } = options;
|
|
568
588
|
const [main, headerResult, footerResult] = await Promise.all([
|
|
569
589
|
resolveNode(node),
|
|
570
590
|
header === void 0 ? void 0 : resolveNode(header),
|
|
@@ -581,16 +601,16 @@ var PdfRenderer = class {
|
|
|
581
601
|
]
|
|
582
602
|
}), images, fontFamilies);
|
|
583
603
|
const sheets = [
|
|
584
|
-
...stylesheets
|
|
585
|
-
...main.
|
|
586
|
-
...headerResult?.
|
|
587
|
-
...footerResult?.
|
|
604
|
+
...ownCss(css, stylesheets),
|
|
605
|
+
...main.css,
|
|
606
|
+
...headerResult?.css ?? [],
|
|
607
|
+
...footerResult?.css ?? []
|
|
588
608
|
];
|
|
589
609
|
return this.inner.render(main.node, {
|
|
590
610
|
...rest,
|
|
591
611
|
header: headerResult?.node,
|
|
592
612
|
footer: footerResult?.node,
|
|
593
|
-
|
|
613
|
+
css: sheets.length > 0 ? sheets : void 0,
|
|
594
614
|
images: resources.images,
|
|
595
615
|
fontFamilies: resources.fontFamilies
|
|
596
616
|
});
|
|
@@ -607,7 +627,7 @@ var PdfRenderer = class {
|
|
|
607
627
|
* against: a box with `width: 100px` measures 100 wide on any page.
|
|
608
628
|
*/
|
|
609
629
|
async measure(node, options = {}) {
|
|
610
|
-
const { fonts, images, stylesheets, fontFamilies, ...rest } = options;
|
|
630
|
+
const { fonts, images, css, stylesheets, fontFamilies, ...rest } = options;
|
|
611
631
|
const main = await resolveNode(node);
|
|
612
632
|
const resources = await this.fonts.resolveResources(fonts && subsetFonts({
|
|
613
633
|
fonts,
|
|
@@ -617,10 +637,10 @@ var PdfRenderer = class {
|
|
|
617
637
|
counterCharacters(classNames(main.node))
|
|
618
638
|
]
|
|
619
639
|
}), images, fontFamilies);
|
|
620
|
-
const sheets = [...stylesheets
|
|
640
|
+
const sheets = [...ownCss(css, stylesheets), ...main.css];
|
|
621
641
|
return this.inner.measure(main.node, {
|
|
622
642
|
...rest,
|
|
623
|
-
|
|
643
|
+
css: sheets.length > 0 ? sheets : void 0,
|
|
624
644
|
images: resources.images,
|
|
625
645
|
fontFamilies: resources.fontFamilies
|
|
626
646
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "takumi-pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Render paged PDFs from JSX, HTML, and CSS. No headless browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chromium-free",
|
|
@@ -134,15 +134,15 @@
|
|
|
134
134
|
}
|
|
135
135
|
},
|
|
136
136
|
"scripts": {
|
|
137
|
-
"build": "wasm-pack build ../takumi-pdf-wasm --no-pack --release --out-dir ../takumi-pdf-js/pkg --target web && bun build:js",
|
|
137
|
+
"build": "wasm-pack build ../takumi-pdf-wasm --no-pack --release --out-dir ../takumi-pdf-js/pkg --target web -- --locked && bun build:js",
|
|
138
138
|
"build:js": "tsdown",
|
|
139
139
|
"publish-lint": "attw --pack . && publint --strict ."
|
|
140
140
|
},
|
|
141
141
|
"dependencies": {
|
|
142
|
-
"@takumi-rs/helpers": "2.
|
|
142
|
+
"@takumi-rs/helpers": "2.13.0"
|
|
143
143
|
},
|
|
144
144
|
"devDependencies": {
|
|
145
|
-
"@types/bun": "^1.
|
|
145
|
+
"@types/bun": "^1.4.0",
|
|
146
146
|
"@types/react": "19.2.18",
|
|
147
147
|
"tsdown": "0.22.14"
|
|
148
148
|
},
|
|
Binary file
|