@formepdf/core 0.2.0 → 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.
- package/dist/index.js +26 -5
- package/package.json +2 -2
- package/pkg/forme_bg.wasm +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import initWasm, { render_pdf as wasmRenderPdf } from '../pkg/forme.js';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
5
|
// ── WASM initialization ────────────────────────────────────────────
|
|
6
6
|
let initialized = false;
|
|
7
7
|
async function ensureInit() {
|
|
@@ -13,6 +13,25 @@ async function ensureInit() {
|
|
|
13
13
|
await initWasm({ module_or_path: wasmBytes });
|
|
14
14
|
initialized = true;
|
|
15
15
|
}
|
|
16
|
+
// ── Font resolution ──────────────────────────────────────────────
|
|
17
|
+
function uint8ArrayToBase64(bytes) {
|
|
18
|
+
return Buffer.from(bytes).toString('base64');
|
|
19
|
+
}
|
|
20
|
+
async function resolveFonts(doc) {
|
|
21
|
+
const fonts = doc.fonts;
|
|
22
|
+
if (!fonts?.length)
|
|
23
|
+
return;
|
|
24
|
+
for (const font of fonts) {
|
|
25
|
+
if (font.src instanceof Uint8Array) {
|
|
26
|
+
font.src = uint8ArrayToBase64(font.src);
|
|
27
|
+
}
|
|
28
|
+
else if (typeof font.src === 'string' && !font.src.startsWith('data:')) {
|
|
29
|
+
const bytes = await readFile(resolve(font.src));
|
|
30
|
+
font.src = uint8ArrayToBase64(new Uint8Array(bytes));
|
|
31
|
+
}
|
|
32
|
+
// data URIs pass through as-is (engine extracts base64 portion)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
16
35
|
// ── Render functions ───────────────────────────────────────────────
|
|
17
36
|
export async function renderPdf(json) {
|
|
18
37
|
await ensureInit();
|
|
@@ -27,11 +46,13 @@ export async function renderPdfWithLayout(json) {
|
|
|
27
46
|
}
|
|
28
47
|
export async function renderDocument(element) {
|
|
29
48
|
const { serialize } = await import('@formepdf/react');
|
|
30
|
-
const
|
|
31
|
-
|
|
49
|
+
const doc = serialize(element);
|
|
50
|
+
await resolveFonts(doc);
|
|
51
|
+
return renderPdf(JSON.stringify(doc));
|
|
32
52
|
}
|
|
33
53
|
export async function renderDocumentWithLayout(element) {
|
|
34
54
|
const { serialize } = await import('@formepdf/react');
|
|
35
|
-
const
|
|
36
|
-
|
|
55
|
+
const doc = serialize(element);
|
|
56
|
+
await resolveFonts(doc);
|
|
57
|
+
return renderPdfWithLayout(JSON.stringify(doc));
|
|
37
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formepdf/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "WASM-powered PDF rendering engine for Forme",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "vitest run"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@formepdf/react": "0.
|
|
21
|
+
"@formepdf/react": "0.3.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^18 || ^19"
|
package/pkg/forme_bg.wasm
CHANGED
|
Binary file
|