@embedpdf/engine-runtime 3.0.0-next.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,88 @@
1
+ import type { PdfFunctions } from './pdf-functions.generated';
2
+ export type Ptr = bigint & {
3
+ readonly __brand: 'PdfRuntimePtr';
4
+ };
5
+ export type Callback = bigint & {
6
+ readonly __brand: 'PdfRuntimeCallback';
7
+ };
8
+ /** The null pointer; useful when the underlying API accepts a NULL value. */
9
+ export declare const NULL_PTR: Ptr;
10
+ export type MemoryValueKind = 'i8' | 'i16' | 'i32' | 'i64' | 'f32' | 'f64' | 'ptr';
11
+ export type CallbackKind = string;
12
+ export type CallbackFn<K extends CallbackKind = CallbackKind> = (...args: unknown[]) => unknown;
13
+ export interface PdfRuntimeMemory {
14
+ alloc(bytes: number): Ptr;
15
+ free(ptr: Ptr): void;
16
+ readBytes(ptr: Ptr, len: number): Uint8Array;
17
+ writeBytes(ptr: Ptr, data: Uint8Array): void;
18
+ readU8String(ptr: Ptr): string;
19
+ writeU8String(str: string): Ptr;
20
+ readU16String(ptr: Ptr): string;
21
+ writeU16String(str: string): Ptr;
22
+ peek(ptr: Ptr, kind: MemoryValueKind, byteOffset?: number): number | bigint;
23
+ poke(ptr: Ptr, kind: MemoryValueKind, value: number | bigint, byteOffset?: number): void;
24
+ }
25
+ export interface PdfRuntimeCallbacks {
26
+ register<K extends CallbackKind>(kind: K, fn: CallbackFn<K>): Callback;
27
+ dispose(callback: Callback): void;
28
+ }
29
+ export interface PdfFileAccessHandle {
30
+ /** Pointer to the owned FPDF_FILEACCESS struct. */
31
+ readonly ptr: Ptr;
32
+ /** Releases callbacks, native file handles, and retained byte views. */
33
+ close(): void;
34
+ }
35
+ export interface PdfRuntimeFileAccess {
36
+ /**
37
+ * Small in-memory file access, intended for layer deltas/artifacts.
38
+ * Browser base documents should prefer EPDF_LoadMemBaseDocument64().
39
+ */
40
+ fromMemory(bytes: Uint8Array | ArrayBuffer): PdfFileAccessHandle;
41
+ /** Native/node only: range-reads a local file without loading it into JS. */
42
+ fromNodeFile(path: string): PdfFileAccessHandle;
43
+ }
44
+ export interface PdfFileWriteHandle {
45
+ /** Pointer to the owned FPDF_FILEWRITE struct. */
46
+ readonly ptr: Ptr;
47
+ /** Flushes/closes the underlying writer and releases native resources. */
48
+ close(): void;
49
+ }
50
+ export interface PdfRuntimeFileWrite {
51
+ /** Native/node only: writes PDFium output directly to a local file. */
52
+ toNodeFile(path: string): PdfFileWriteHandle;
53
+ }
54
+ export interface PdfRuntimeModule {
55
+ readonly kind: 'wasm' | 'native';
56
+ readonly platform: string;
57
+ readonly mem: PdfRuntimeMemory;
58
+ readonly cb: PdfRuntimeCallbacks;
59
+ readonly fileAccess: PdfRuntimeFileAccess;
60
+ readonly fileWrite: PdfRuntimeFileWrite;
61
+ readonly fn: PdfFunctions;
62
+ destroy(): Promise<void>;
63
+ }
64
+ export interface CreatePdfRuntimeOptions {
65
+ /**
66
+ * Runtime preference. Native is attempted first in Node by default, with
67
+ * WebAssembly as the fallback.
68
+ */
69
+ prefer?: 'auto' | 'native' | 'wasm';
70
+ /**
71
+ * Exact URL of `embedpdf.wasm`. When set, the wasm runtime fetches the binary
72
+ * from here instead of resolving it relative to the Emscripten glue
73
+ * (`import.meta.url`). Must be an absolute URL when the runtime boots inside
74
+ * a `blob:` worker, where relative resolution is meaningless.
75
+ */
76
+ wasmUrl?: string;
77
+ /**
78
+ * The `embedpdf.wasm` bytes, pre-fetched by the caller. Takes precedence over
79
+ * `wasmUrl`; no network request is made (the air-gapped path).
80
+ */
81
+ wasmBinary?: ArrayBuffer | Uint8Array;
82
+ /**
83
+ * Emscripten module overrides for the wasm runtime (escape hatch). An
84
+ * explicit `locateFile` / `wasmBinary` here wins over the first-class
85
+ * options above.
86
+ */
87
+ wasm?: Record<string, unknown>;
88
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Environment-NEUTRAL platform vocabulary. This module must stay importable
3
+ * from every graph (browser, worker, node) — so it carries no Node imports.
4
+ * The node-only target detection (detect-libc) lives in `platform.node.ts`;
5
+ * the browser graph pins `wasm32` in `index.browser.ts`.
6
+ */
7
+ export type RuntimeTarget = 'wasm32' | 'darwin-arm64' | 'darwin-x64' | 'linux-x64' | 'linux-arm64' | 'linuxmusl-x64' | 'linuxmusl-arm64' | 'win32-x64' | 'win32-arm64';
8
+ export declare function isNodeLike(): boolean;
9
+ export declare function packageNameForTarget(target: RuntimeTarget): string;
@@ -0,0 +1,2 @@
1
+ import { type RuntimeTarget } from './platform';
2
+ export declare function resolveRuntimeTarget(): RuntimeTarget | null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * BROWSER entry (the exports map's `default` condition). WASM only, ZERO Node
3
+ * imports anywhere in its graph — no `detect-libc`, no `native/`, no builtins.
4
+ * Browsers always resolve to `wasm32`; `prefer` is accepted and ignored so the
5
+ * API matches the node entry exactly.
6
+ *
7
+ * Do not rely on dead-code elimination to keep this pure: bundlers must
8
+ * RESOLVE an import before they can prove its branch unreachable, so a Node
9
+ * import anywhere in this graph breaks strict builders (Angular/esbuild) even
10
+ * if it never executes. Purity is enforced by `verify:browser-purity`.
11
+ */
12
+ export * from './shared';
13
+ import type { CreatePdfRuntimeOptions, PdfRuntimeModule } from './core/pdf-runtime-module';
14
+ import type { RuntimeTarget } from './core/platform';
15
+ export declare function resolveRuntimeTarget(): RuntimeTarget | null;
16
+ export declare function createPdfRuntime(opts?: CreatePdfRuntimeOptions): Promise<PdfRuntimeModule>;
17
+ export declare const init: typeof createPdfRuntime;