takumi-pdf 0.7.0 → 0.8.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.
@@ -0,0 +1,9 @@
1
+ import * as wasm from "../dist/export.mjs";
2
+ import wasmPath from "../pkg/takumi_pdf_wasm_bg.wasm";
3
+
4
+ const wasmBytes = await Bun.file(new URL(wasmPath, import.meta.url)).arrayBuffer();
5
+
6
+ wasm.initSync({ module: wasmBytes });
7
+
8
+ export * from "../dist/export.mjs";
9
+ export default wasm.default;
@@ -0,0 +1,11 @@
1
+ import module from "../pkg/takumi_pdf_wasm_bg.wasm?module";
2
+ import * as wasm from "../dist/export.mjs";
3
+
4
+ // typeof module says its Module { } but instanceof WebAssembly.Module is false
5
+ // Have to force override the prototype to be WebAssembly.Module
6
+ Object.setPrototypeOf(module, WebAssembly.Module.prototype);
7
+
8
+ wasm.initSync({ module });
9
+
10
+ export * from "../dist/export.mjs";
11
+ export default wasm.default;
@@ -0,0 +1,46 @@
1
+ import url from "../pkg/takumi_pdf_wasm_bg.wasm?url";
2
+ import * as wasm from "../dist/export.mjs";
3
+
4
+ // `?url` is a browser path; map it to a file for server reads. Vite emits the asset next to the
5
+ // importing server chunk, so resolve relative to import.meta.url, not the framework output dir.
6
+ async function resolveWasm() {
7
+ if (typeof process !== "undefined" && process.versions?.node != null) {
8
+ const { readFile } = await import("node:fs/promises");
9
+ const path = decodeURIComponent(url.replace(/[?#].*$/, ""));
10
+
11
+ // Dev SSR serves an `/@fs/<abs-path>` URL.
12
+ if (path.startsWith("/@fs/")) {
13
+ return readFile(path.slice("/@fs".length));
14
+ }
15
+
16
+ if (!path.startsWith("/")) {
17
+ return readFile(new URL(path, import.meta.url));
18
+ }
19
+
20
+ const basename = path.slice(path.lastIndexOf("/") + 1);
21
+ const candidates = [`./${basename}`, `.${path}`, `../client${path}`, `../../client${path}`];
22
+
23
+ let lastError;
24
+ for (const candidate of candidates) {
25
+ try {
26
+ return await readFile(new URL(candidate, import.meta.url));
27
+ } catch (error) {
28
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
29
+ lastError = error;
30
+ continue;
31
+ }
32
+
33
+ throw error;
34
+ }
35
+ }
36
+
37
+ throw new Error(`Unable to locate Takumi WASM asset for SSR: ${url}`, { cause: lastError });
38
+ }
39
+
40
+ return fetch(new URL(url, import.meta.url)).then((response) => response.arrayBuffer());
41
+ }
42
+
43
+ wasm.initSync({ module: await resolveWasm() });
44
+
45
+ export * from "../dist/export.mjs";
46
+ export default wasm.default;
package/dist/export.d.cts CHANGED
@@ -267,6 +267,11 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
267
267
  metadata?: PdfMetadata;
268
268
  /** Generates a PDF outline (bookmarks) from `h1`–`h6` headings. */
269
269
  outline?: boolean;
270
+ /**
271
+ * The paper color as a CSS color, painted under everything on every page.
272
+ * Unset leaves the page empty, so a viewer shows its own white.
273
+ */
274
+ backgroundColor?: string;
270
275
  };
271
276
  /** A PDF renderer holding registered fonts. Reuse one instance across renders. */
272
277
  declare class PdfRenderer {
package/dist/export.d.mts CHANGED
@@ -267,6 +267,11 @@ type RenderOptions = (PagedOptions | ViewportOptions) & ConformanceOptions & {
267
267
  metadata?: PdfMetadata;
268
268
  /** Generates a PDF outline (bookmarks) from `h1`–`h6` headings. */
269
269
  outline?: boolean;
270
+ /**
271
+ * The paper color as a CSS color, painted under everything on every page.
272
+ * Unset leaves the page empty, so a viewer shows its own white.
273
+ */
274
+ backgroundColor?: string;
270
275
  };
271
276
  /** A PDF renderer holding registered fonts. Reuse one instance across renders. */
272
277
  declare class PdfRenderer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "takumi-pdf",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Render paged PDFs from JSX, HTML, and CSS. No headless browser.",
5
5
  "keywords": [
6
6
  "chromium-free",
@@ -45,12 +45,24 @@
45
45
  ".": {
46
46
  "bun": {
47
47
  "types": "./bundlers/node.d.ts",
48
- "default": "./bundlers/node.mjs"
48
+ "default": "./bundlers/bun.mjs"
49
49
  },
50
50
  "workerd": {
51
51
  "types": "./bundlers/node.d.ts",
52
52
  "default": "./bundlers/workerd.mjs"
53
53
  },
54
+ "edge-light": {
55
+ "types": "./bundlers/node.d.ts",
56
+ "default": "./bundlers/next.mjs"
57
+ },
58
+ "unwasm": {
59
+ "types": "./bundlers/node.d.ts",
60
+ "default": "./bundlers/next.mjs"
61
+ },
62
+ "module": {
63
+ "types": "./bundlers/node.d.ts",
64
+ "default": "./bundlers/vite.mjs"
65
+ },
54
66
  "node": {
55
67
  "require": {
56
68
  "types": "./bundlers/node.d.cts",
@@ -62,8 +74,8 @@
62
74
  }
63
75
  },
64
76
  "default": {
65
- "types": "./dist/export.d.mts",
66
- "default": "./dist/export.mjs"
77
+ "types": "./bundlers/node.d.ts",
78
+ "default": "./bundlers/vite.mjs"
67
79
  }
68
80
  },
69
81
  "./no-init": {
@@ -88,7 +100,7 @@
88
100
  "publish-lint": "attw --pack . && publint --strict ."
89
101
  },
90
102
  "dependencies": {
91
- "@takumi-rs/helpers": "2.7.3"
103
+ "@takumi-rs/helpers": "2.8.0"
92
104
  },
93
105
  "devDependencies": {
94
106
  "@types/bun": "^1.3.14",
Binary file