@formepdf/core 0.1.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.d.ts +76 -0
- package/dist/index.js +37 -0
- package/package.json +43 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
export interface Color {
|
|
3
|
+
r: number;
|
|
4
|
+
g: number;
|
|
5
|
+
b: number;
|
|
6
|
+
a: number;
|
|
7
|
+
}
|
|
8
|
+
export interface EdgeValues<T> {
|
|
9
|
+
top: T;
|
|
10
|
+
right: T;
|
|
11
|
+
bottom: T;
|
|
12
|
+
left: T;
|
|
13
|
+
}
|
|
14
|
+
export interface CornerValues {
|
|
15
|
+
top_left: number;
|
|
16
|
+
top_right: number;
|
|
17
|
+
bottom_right: number;
|
|
18
|
+
bottom_left: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ElementStyleInfo {
|
|
21
|
+
margin: EdgeValues<number>;
|
|
22
|
+
padding: EdgeValues<number>;
|
|
23
|
+
borderWidth: EdgeValues<number>;
|
|
24
|
+
flexDirection: string;
|
|
25
|
+
justifyContent: string;
|
|
26
|
+
alignItems: string;
|
|
27
|
+
flexWrap: string;
|
|
28
|
+
gap: number;
|
|
29
|
+
fontFamily: string;
|
|
30
|
+
fontSize: number;
|
|
31
|
+
fontWeight: number;
|
|
32
|
+
fontStyle: string;
|
|
33
|
+
lineHeight: number;
|
|
34
|
+
textAlign: string;
|
|
35
|
+
color: Color;
|
|
36
|
+
backgroundColor: Color | null;
|
|
37
|
+
borderColor: EdgeValues<Color>;
|
|
38
|
+
borderRadius: CornerValues;
|
|
39
|
+
opacity: number;
|
|
40
|
+
}
|
|
41
|
+
export interface ElementInfo {
|
|
42
|
+
x: number;
|
|
43
|
+
y: number;
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
kind: string;
|
|
47
|
+
nodeType: string;
|
|
48
|
+
style: ElementStyleInfo;
|
|
49
|
+
children: ElementInfo[];
|
|
50
|
+
sourceLocation?: {
|
|
51
|
+
file: string;
|
|
52
|
+
line: number;
|
|
53
|
+
column: number;
|
|
54
|
+
};
|
|
55
|
+
textContent?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface PageInfo {
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
contentX: number;
|
|
61
|
+
contentY: number;
|
|
62
|
+
contentWidth: number;
|
|
63
|
+
contentHeight: number;
|
|
64
|
+
elements: ElementInfo[];
|
|
65
|
+
}
|
|
66
|
+
export interface LayoutInfo {
|
|
67
|
+
pages: PageInfo[];
|
|
68
|
+
}
|
|
69
|
+
export interface RenderWithLayoutResult {
|
|
70
|
+
pdf: Uint8Array;
|
|
71
|
+
layout: LayoutInfo;
|
|
72
|
+
}
|
|
73
|
+
export declare function renderPdf(json: string): Promise<Uint8Array>;
|
|
74
|
+
export declare function renderPdfWithLayout(json: string): Promise<RenderWithLayoutResult>;
|
|
75
|
+
export declare function renderDocument(element: ReactElement): Promise<Uint8Array>;
|
|
76
|
+
export declare function renderDocumentWithLayout(element: ReactElement): Promise<RenderWithLayoutResult>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import initWasm, { render_pdf as wasmRenderPdf } from '../pkg/forme.js';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
// ── WASM initialization ────────────────────────────────────────────
|
|
6
|
+
let initialized = false;
|
|
7
|
+
async function ensureInit() {
|
|
8
|
+
if (initialized)
|
|
9
|
+
return;
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const wasmPath = join(__dirname, '..', 'pkg', 'forme_bg.wasm');
|
|
12
|
+
const wasmBytes = await readFile(wasmPath);
|
|
13
|
+
await initWasm({ module_or_path: wasmBytes });
|
|
14
|
+
initialized = true;
|
|
15
|
+
}
|
|
16
|
+
// ── Render functions ───────────────────────────────────────────────
|
|
17
|
+
export async function renderPdf(json) {
|
|
18
|
+
await ensureInit();
|
|
19
|
+
return wasmRenderPdf(json);
|
|
20
|
+
}
|
|
21
|
+
export async function renderPdfWithLayout(json) {
|
|
22
|
+
await ensureInit();
|
|
23
|
+
// Dynamic import to access the WASM binding that returns { pdf, layout }
|
|
24
|
+
const { render_pdf_with_layout } = await import('../pkg/forme.js');
|
|
25
|
+
const result = render_pdf_with_layout(json);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export async function renderDocument(element) {
|
|
29
|
+
const { serialize } = await import('@formepdf/react');
|
|
30
|
+
const json = JSON.stringify(serialize(element));
|
|
31
|
+
return renderPdf(json);
|
|
32
|
+
}
|
|
33
|
+
export async function renderDocumentWithLayout(element) {
|
|
34
|
+
const { serialize } = await import('@formepdf/react');
|
|
35
|
+
const json = JSON.stringify(serialize(element));
|
|
36
|
+
return renderPdfWithLayout(json);
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formepdf/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "WASM-powered PDF rendering engine for Forme",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build:wasm": "./build.sh",
|
|
16
|
+
"build:ts": "tsc",
|
|
17
|
+
"build": "npm run build:wasm && npm run build:ts",
|
|
18
|
+
"test": "vitest run"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@formepdf/react": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"react": "^18 || ^19"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^22.0.0",
|
|
28
|
+
"@types/react": "^19.0.0",
|
|
29
|
+
"react": "^19.0.0",
|
|
30
|
+
"typescript": "^5.7.0",
|
|
31
|
+
"vitest": "^3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/",
|
|
35
|
+
"pkg/"
|
|
36
|
+
],
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/formepdf/forme",
|
|
41
|
+
"directory": "packages/core"
|
|
42
|
+
}
|
|
43
|
+
}
|