@laminapdf/render-pdfium 0.0.0-stage → 0.2.0-alpha.3

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/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @laminapdf/render-pdfium
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lamina PDF's default web renderer: PDFium as WebAssembly behind [`@laminapdf/render`](../render/README.md)'s `RenderBackend`. It runs only inside the viewer's document Web Worker. It is private, and `@laminapdf/sdk` never depends on it.
4
+
5
+ ```ts
6
+ import wasmUrl from "@embedpdf/pdfium/pdfium.wasm?url";
7
+ import { initPdfium } from "@laminapdf/render-pdfium";
8
+
9
+ const pdfium = await initPdfium(wasmUrl); // a URL, Response, bytes or compiled WebAssembly.Module
10
+ ```
11
+
12
+ - **The build:** [`@embedpdf/pdfium`](https://www.npmjs.com/package/@embedpdf/pdfium) **2.15.1**, an npm dependency pinned exactly. Its `pdfium.wasm` must have SHA-256 `5e4cd023…4eaa`.
13
+ - **Checking:** the hash is checked before every build and test, so any other file fails them.
14
+ - **Fetched, not vendored:** pnpm's lockfile pins the tarball's integrity, and the 4.6 MB binary stays out of git.
15
+ - **Revision:** the package doesn't record its PDFium revision. It is built from EmbedPDF's fork, [`embedpdf/runtime`](https://github.com/embedpdf/runtime), without XFA, V8 or Skia.
16
+ - **Loading:** `initPdfium(wasm)` takes any `WasmSource`. Bytes (an `ArrayBuffer` or any view of one) go to Emscripten's `wasmBinary`. A module, a URL, or a `Response` or a promise of one goes through Emscripten's `instantiateWasm` hook. A URL served as `application/wasm` compiles while it downloads. The caller decides where the `.wasm` comes from, which controls caching and lazy loading. There are no top-level side effects.
17
+ - **Input:** PDFium's custom file access (`FPDF_LoadCustomDocument`) reads the `RenderSource` block by block, with no whole copy. A block the source can't give yet makes the call throw `data-pending` with its ranges, even if PDFium carried on with defaults. Input is limited to 4 GiB (a wasm32 `unsigned long`).
18
+ - **Rendering:** each document has a form-fill environment (`PDFiumExt_InitFormFillEnvironment`), as the native adapter does.
19
+ - **With widgets** (`FPDF_RenderPageBitmap`, then `FPDF_FFLDraw`), the page is laid out at its whole pixel size and shifted, so only the tile lands in a tile-sized bitmap.
20
+ - **Without widgets,** `FPDF_RenderPageBitmapWithMatrix` gets `pageToTile`'s matrix.
21
+ - **Output:** `FPDF_REVERSE_BYTE_ORDER` gives RGBA, which is copied out of the heap once. Bitmap and buffer are freed on every path.
22
+ - **Cancellation:** the `AbortSignal` is checked before and after the synchronous engine call. Progressive rendering is exported by the build, but not used yet; that's a follow-up if long single tiles need it.
23
+ - **Notices:** `@embedpdf/pdfium` ships none for PDFium's bundled libraries. [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) lists them, and apps ship it.
24
+ - **Size:** `pdfium.wasm` is 2,136,390 B gzip.
25
+
26
+ ## For contributors
27
+
28
+ It is the default renderer of [ADR 0004](../../docs/decisions/0004-render-backend.md), pinned per [§3](../../docs/decisions/0004-render-backend.md#3-the-pinned-pdfium-builds), in the document worker of [ADR 0009](../../docs/decisions/0009-web-client-architecture.md) §2; its size was measured by [C1b](../../docs/todos/done/C1b-pdfium-wasm-spike.md). A re-pin changes `package.json`, the hash in the script, ADR 0004 and `THIRD_PARTY_NOTICES.md` together.
29
+
30
+ - **Hash check:** `scripts/verify-pdfium.mjs` checks the hash before every `build`, `typecheck` and `test`; `test/verify.test.ts` tests the verifier.
31
+ - **Size budget:** `thirdParty.pdfium` in `packages/wasm/size-budgets.json` is the measured size plus 5 %, checked by `cargo xtask size`.
32
+
33
+ ### Tests
34
+
35
+ - **Node:** `pnpm --filter @laminapdf/render-pdfium test` (part of `cargo xtask check ts`) runs the verifier and the RenderBackend contract over the installed `pdfium.wasm`.
36
+ - **Browsers:** `pnpm --filter @laminapdf/render-pdfium exec vitest run -c vitest.browser.config.ts --project chromium` runs the contract in Chromium, and likewise `firefox` and `webkit`. `cargo xtask pdf-runtimes <browser>` runs it too. The browser runs add [C2b](../../docs/todos/done/C2b-lamina-render-crate.md)'s goldens: EmbedPDF's build against native `chromium/7881` goldens, at SSIM ≥ 0.98.
@@ -0,0 +1,30 @@
1
+ # Third-party notices: `@laminapdf/render-pdfium`
2
+
3
+ This package loads `pdfium.wasm` from [`@embedpdf/pdfium`](https://www.npmjs.com/package/@embedpdf/pdfium) 2.15.1 (SHA-256 `5e4cd023c3dad4a895b3571ca573d3fc51bac6de48360d95283134385b954eaa`, checked by `scripts/verify-pdfium.mjs`). The `@embedpdf/pdfium` package ships none of the notices below ([C1b](../../spikes/pdfium-wasm/README.md#licences)); [ADR 0004 §3](../../docs/decisions/0004-render-backend.md#3-the-pinned-pdfium-builds) requires every product that ships PDFium to carry them. An app that bundles this package ships this file, plus the full licence texts it links to, with its other notices.
4
+
5
+ ## Where the list comes from
6
+
7
+ - EmbedPDF builds `pdfium.wasm` from its PDFium fork, [`embedpdf/runtime`](https://github.com/embedpdf/runtime) (`scripts/embedpdf-runtime/build-target.sh`).
8
+ - That build sets `pdf_enable_xfa=false`, `pdf_enable_v8=false` and `pdf_use_skia=false`. So V8, Skia and XFA's own dependencies (libtiff among them) are **not** linked, and the rasteriser is PDFium's copy of AGG.
9
+ - **Confirmed in the binary's strings:** libpng, zlib, OpenJPEG. The symbol names are stripped, so the others below are inferred from PDFium's non-XFA build: FreeType, Little-CMS 2, libjpeg-turbo and AGG are core dependencies of PDFium's codecs and font engine.
10
+ - **Possibly linked, depending on the PDFium revision:** Abseil, fast_float and simdutf. Their notices are listed so a bundle is never short of one.
11
+ - **To do on every re-pin (ADR 0004 §3):** re-check this list against the fork's `DEPS` and `BUILD.gn` at the pinned revision.
12
+
13
+ ## Components
14
+
15
+ | Component | Licence | Required notice or attribution |
16
+ | --- | --- | --- |
17
+ | `@embedpdf/pdfium` (the wrapper and its JS glue) | MIT | © 2024 CloudPDF, Ji Chang. The MIT text ships as the package's `LICENSE`. |
18
+ | PDFium | BSD-3-Clause; parts Apache-2.0 | © 2014 The PDFium Authors. Both texts ship as the package's `LICENSE.pdfium`. |
19
+ | FreeType | FreeType Project License (FTL), chosen over GPLv2 | "Portions of this software are copyright © The FreeType Project (www.freetype.org). All rights reserved." ([FTL](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT)) |
20
+ | Little-CMS 2 | MIT | Copyright © Marti Maria Saguer ([COPYING](https://github.com/mm2/Little-CMS/blob/master/LICENSE)) |
21
+ | libjpeg-turbo | IJG License, BSD-3-Clause, zlib | "This software is based in part on the work of the Independent JPEG Group." ([LICENSE.md](https://github.com/libjpeg-turbo/libjpeg-turbo/blob/main/LICENSE.md)) |
22
+ | libpng | PNG Reference Library License v2 | Copyright © the libpng authors ([LICENSE](https://github.com/pnggroup/libpng/blob/libpng16/LICENSE)) |
23
+ | zlib | zlib | Copyright © Jean-loup Gailly and Mark Adler ([zlib licence](https://zlib.net/zlib_license.html)) |
24
+ | OpenJPEG | BSD-2-Clause | Copyright © Université catholique de Louvain, CNES, and the OpenJPEG contributors ([LICENSE](https://github.com/uclouvain/openjpeg/blob/master/LICENSE)) |
25
+ | Anti-Grain Geometry 2.3 (PDFium's copy) | AGG 2.3 licence (permissive) | Copyright © 2002–2005 Maxim Shemanarev ([PDFium's copy](https://pdfium.googlesource.com/pdfium/+/refs/heads/main/third_party/agg23/)) |
26
+ | Abseil (if linked) | Apache-2.0 | © The Abseil Authors |
27
+ | fast_float (if linked) | MIT OR Apache-2.0 OR BSL-1.0 | © The fast_float authors |
28
+ | simdutf (if linked) | MIT OR Apache-2.0 | © The simdutf authors |
29
+
30
+ **Licences:** all of these are permissive, and none is GPL, LGPL or AGPL ([ADR 0001](../../docs/decisions/0001-core-language-and-licence.md)). FreeType is used under the FTL.
@@ -0,0 +1,24 @@
1
+ import { type WrappedPdfiumModule } from "@embedpdf/pdfium";
2
+ import { type RenderBackend, type RenderDocument, type RenderOpenOptions, type RenderSource, type WasmSource } from "@laminapdf/render";
3
+ /** The pinned package (ADR 0004 §3); its pdfium.wasm's SHA-256 is checked at build time. */
4
+ export declare const PDFIUM_PACKAGE = "@embedpdf/pdfium@2.15.1";
5
+ type Pdfium = WrappedPdfiumModule;
6
+ /**
7
+ * Loads PDFium. Call it inside the document worker (ADR 0009 §2), once per worker.
8
+ *
9
+ * @throws RenderError `render-backend-unavailable` when the module can't be fetched or compiled.
10
+ */
11
+ export declare function initPdfium(wasm: WasmSource): Promise<PdfiumBackend>;
12
+ /** PDFium-WASM as a RenderBackend. */
13
+ export declare class PdfiumBackend implements RenderBackend {
14
+ #private;
15
+ readonly name = "pdfium";
16
+ readonly version = "@embedpdf/pdfium@2.15.1";
17
+ constructor(pdfium: Pdfium);
18
+ /** The size of PDFium's WebAssembly memory, in bytes. */
19
+ memory(): number;
20
+ /** Opens `source` (see {@link RenderBackend.open}). */
21
+ open(source: RenderSource, options?: RenderOpenOptions): RenderDocument;
22
+ }
23
+ export {};
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAQ,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAUL,KAAK,aAAa,EAClB,KAAK,cAAc,EAKnB,KAAK,iBAAiB,EAGtB,KAAK,YAAY,EAMjB,KAAK,UAAU,EAEhB,MAAM,mBAAmB,CAAC;AAE3B,4FAA4F;AAC5F,eAAO,MAAM,cAAc,4BAA4B,CAAC;AAExD,KAAK,MAAM,GAAG,mBAAmB,CAAC;AA2ClC;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAuBzE;AAED,sCAAsC;AACtC,qBAAa,aAAc,YAAW,aAAa;;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,QAAQ,CAAC,OAAO,6BAAkB;IAGlC,YAAY,MAAM,EAAE,MAAM,EAEzB;IAED,yDAAyD;IACzD,MAAM,IAAI,MAAM,CAEf;IAED,uDAAuD;IACvD,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,iBAAsB,GAAG,cAAc,CAE1E;CACF"}
package/dist/index.js ADDED
@@ -0,0 +1,368 @@
1
+ // ADR 0004's default web renderer: the pinned PDFium-WASM build behind
2
+ // @laminapdf/render's RenderBackend. It mirrors the native adapter (laminapdf-render-pdfium):
3
+ // - input through PDFium's custom file access over a RenderSource (no whole copy); a read the
4
+ // source can't answer yet makes the call throw `data-pending` with the ranges;
5
+ // - a form-fill environment per document, so widgets are drawn by FPDF_FFLDraw and can be left
6
+ // out; with widgets the page is laid out at its whole pixel size and shifted so only the tile
7
+ // lands in a tile-sized bitmap, without them FPDF_RenderPageBitmapWithMatrix gets
8
+ // pageToTile's matrix;
9
+ // - straight RGBA through FPDF_REVERSE_BYTE_ORDER, copied out once into the result.
10
+ // PDFium is synchronous: the AbortSignal is checked before and after the engine call.
11
+ import { init } from "@embedpdf/pdfium";
12
+ import { checkInputSize, checkOpen, checkPageIndex, flagsOf, limitsOf, MAX_WASM_INPUT, pageToTile, pendingError, planTile, RenderError, readFailure, readRange, throwIfAborted, WHITE, } from "@laminapdf/render";
13
+ /** The pinned package (ADR 0004 §3); its pdfium.wasm's SHA-256 is checked at build time. */
14
+ export const PDFIUM_PACKAGE = "@embedpdf/pdfium@2.15.1";
15
+ // fpdfview.h
16
+ const FPDF_ANNOT = 0x01;
17
+ const FPDF_GRAYSCALE = 0x08;
18
+ const FPDF_REVERSE_BYTE_ORDER = 0x10;
19
+ const FPDF_PRINTING = 0x800;
20
+ const FPDFBITMAP_BGRA = 4;
21
+ const FPDF_ERR_PASSWORD = 4;
22
+ /** Whether `wasm` is the module's bytes: an ArrayBuffer or any view of one. */
23
+ function isBytes(wasm) {
24
+ return wasm instanceof ArrayBuffer || ArrayBuffer.isView(wasm);
25
+ }
26
+ /** `wasm`'s bytes as a Uint8Array over the same memory. */
27
+ function asUint8Array(wasm) {
28
+ return wasm instanceof ArrayBuffer
29
+ ? new Uint8Array(wasm)
30
+ : new Uint8Array(wasm.buffer, wasm.byteOffset, wasm.byteLength);
31
+ }
32
+ /**
33
+ * A module, or a URL or `Response` to fetch. `isBytes` is the check that keeps bytes out:
34
+ * `WebAssembly.Module` is an empty interface, so this parameter's type alone would accept them.
35
+ */
36
+ async function instantiate(wasm, imports) {
37
+ if (wasm instanceof WebAssembly.Module)
38
+ return WebAssembly.instantiate(wasm, imports);
39
+ const awaited = await wasm;
40
+ const response = awaited instanceof Response ? awaited : await fetch(awaited);
41
+ if (!response.ok)
42
+ throw new RenderError("render-backend-unavailable", `pdfium.wasm: HTTP ${response.status}`);
43
+ // Streaming compile needs `application/wasm`; fall back to the bytes otherwise.
44
+ if (response.headers.get("content-type")?.startsWith("application/wasm")) {
45
+ return (await WebAssembly.instantiateStreaming(response, imports)).instance;
46
+ }
47
+ return (await WebAssembly.instantiate(await response.arrayBuffer(), imports)).instance;
48
+ }
49
+ /**
50
+ * Loads PDFium. Call it inside the document worker (ADR 0009 §2), once per worker.
51
+ *
52
+ * @throws RenderError `render-backend-unavailable` when the module can't be fetched or compiled.
53
+ */
54
+ export async function initPdfium(wasm) {
55
+ let fail = () => { };
56
+ const failed = new Promise((_, reject) => {
57
+ fail = reject;
58
+ });
59
+ // Bytes go to the glue's own `wasmBinary` as a Uint8Array over the same memory (it reads it with
60
+ // `new Uint8Array(…)`, wrong for other views); a module, a URL or a Response through its hook.
61
+ const overrides = isBytes(wasm)
62
+ ? { wasmBinary: asUint8Array(wasm) }
63
+ : {
64
+ instantiateWasm: (imports, done) => {
65
+ instantiate(wasm, imports).then(done, fail);
66
+ return {};
67
+ },
68
+ };
69
+ try {
70
+ const pdfium = await Promise.race([failed, init(overrides)]);
71
+ pdfium.PDFiumExt_Init();
72
+ return new PdfiumBackend(pdfium);
73
+ }
74
+ catch (e) {
75
+ if (e instanceof RenderError)
76
+ throw e;
77
+ throw new RenderError("render-backend-unavailable", "PDFium could not be loaded");
78
+ }
79
+ }
80
+ /** PDFium-WASM as a RenderBackend. */
81
+ export class PdfiumBackend {
82
+ name = "pdfium";
83
+ version = PDFIUM_PACKAGE;
84
+ #pdfium;
85
+ constructor(pdfium) {
86
+ this.#pdfium = pdfium;
87
+ }
88
+ /** The size of PDFium's WebAssembly memory, in bytes. */
89
+ memory() {
90
+ return heap(this.#pdfium).buffer.byteLength;
91
+ }
92
+ /** Opens `source` (see {@link RenderBackend.open}). */
93
+ open(source, options = {}) {
94
+ return PdfiumDocument.open(this.#pdfium, source, options);
95
+ }
96
+ }
97
+ function heap(p) {
98
+ return p.pdfium.wasmExports.memory;
99
+ }
100
+ /** The error the refused reads make, if any: a failed read first, else `data-pending`. */
101
+ function refusal(reads) {
102
+ if (reads.failure !== undefined)
103
+ return reads.failure;
104
+ return reads.pending.length > 0 ? pendingError(reads.pending) : undefined;
105
+ }
106
+ /** PDFium's render flags for the request's flags; every render writes RGBA byte order. */
107
+ function renderFlagsOf(flags) {
108
+ return ((flags.annotations ? FPDF_ANNOT : 0) |
109
+ (flags.print ? FPDF_PRINTING : 0) |
110
+ (flags.grayscale ? FPDF_GRAYSCALE : 0) |
111
+ FPDF_REVERSE_BYTE_ORDER);
112
+ }
113
+ class PdfiumDocument {
114
+ pageCount;
115
+ #p;
116
+ #limits;
117
+ #pages = new Map();
118
+ #reads;
119
+ #doc;
120
+ #form;
121
+ #formInfo;
122
+ #access;
123
+ #getBlock;
124
+ constructor(p, handles, reads, limits) {
125
+ this.#p = p;
126
+ this.#doc = handles.doc;
127
+ this.#form = handles.form;
128
+ this.#formInfo = handles.formInfo;
129
+ this.#access = handles.access;
130
+ this.#getBlock = handles.getBlock;
131
+ this.pageCount = handles.count;
132
+ this.#reads = reads;
133
+ this.#limits = limits;
134
+ }
135
+ static open(p, source, options) {
136
+ // PDFium reads block by block, so only wasm32's custom file access (32-bit sizes) bounds the
137
+ // input; `maxInputBytes` is for engines that read the whole file (ADR 0004).
138
+ checkInputSize(source.size, MAX_WASM_INPUT);
139
+ const reads = { pending: [], failure: undefined };
140
+ const { malloc, free } = p.pdfium.wasmExports;
141
+ // FPDF_FILEACCESS.m_GetBlock(param, position, pBuf, size): 1 on success, 0 on failure. It
142
+ // never throws: an exception would unwind through PDFium's C++ frames. A throwing or short
143
+ // read is recorded and reported after the engine call returns.
144
+ const getBlock = p.pdfium.addFunction((_param, position, buf, size) => {
145
+ const at = position >>> 0;
146
+ const length = size >>> 0;
147
+ try {
148
+ const bytes = readRange(source, at, length);
149
+ if (bytes === undefined) {
150
+ reads.pending.push([at, length]);
151
+ return 0;
152
+ }
153
+ new Uint8Array(heap(p).buffer, buf, length).set(bytes);
154
+ return 1;
155
+ }
156
+ catch (e) {
157
+ reads.failure ??= readFailure(at, length, e);
158
+ return 0;
159
+ }
160
+ }, "iiiii");
161
+ // FPDF_FILEACCESS on wasm32: m_FileLen (unsigned long), m_GetBlock, m_Param: 12 bytes.
162
+ const access = malloc(12);
163
+ if (access === 0) {
164
+ p.pdfium.removeFunction(getBlock);
165
+ throw new RenderError("render-failed", "the pdfium backend could not allocate memory");
166
+ }
167
+ p.pdfium.setValue(access, source.size >>> 0, "i32");
168
+ p.pdfium.setValue(access + 4, getBlock, "i32");
169
+ p.pdfium.setValue(access + 8, 0, "i32");
170
+ const release = () => {
171
+ free(access);
172
+ p.pdfium.removeFunction(getBlock);
173
+ };
174
+ const doc = p.FPDF_LoadCustomDocument(access, options.password ?? "");
175
+ if (doc === 0) {
176
+ const error = p.FPDF_GetLastError();
177
+ release();
178
+ const refused = refusal(reads);
179
+ if (refused !== undefined)
180
+ throw refused;
181
+ if (error === FPDF_ERR_PASSWORD) {
182
+ throw options.password === undefined
183
+ ? new RenderError("password-required", "the document is encrypted and needs a password")
184
+ : new RenderError("wrong-password", "the password does not open the document");
185
+ }
186
+ throw new RenderError("render-failed", "the pdfium backend could not open the document");
187
+ }
188
+ const formInfo = p.PDFiumExt_OpenFormFillInfo();
189
+ const form = p.PDFiumExt_InitFormFillEnvironment(doc, formInfo);
190
+ const count = p.FPDF_GetPageCount(doc);
191
+ // PDFium may open after refused reads by rebuilding the structure, and the form environment
192
+ // and the page count read more: any refusal up to here makes the open fail, so a document
193
+ // never keeps a page count read from a partial file.
194
+ const refused = refusal(reads);
195
+ if (refused !== undefined) {
196
+ if (form !== 0)
197
+ p.PDFiumExt_ExitFormFillEnvironment(form);
198
+ if (formInfo !== 0)
199
+ p.PDFiumExt_CloseFormFillInfo(formInfo);
200
+ p.FPDF_CloseDocument(doc);
201
+ release();
202
+ throw refused;
203
+ }
204
+ return new PdfiumDocument(p, { doc, form, formInfo, access, getBlock, count }, reads, limitsOf(options.limits));
205
+ }
206
+ #live() {
207
+ checkOpen(this.#doc !== 0);
208
+ return this.#doc;
209
+ }
210
+ /**
211
+ * Runs `f` with the refusals cleared; any read the source refused makes the outcome that
212
+ * refusal (`source` or `data-pending`), success or not.
213
+ */
214
+ #reading(f) {
215
+ this.#reads.pending.length = 0;
216
+ this.#reads.failure = undefined;
217
+ let outcome;
218
+ try {
219
+ outcome = f();
220
+ }
221
+ catch (e) {
222
+ throw refusal(this.#reads) ?? e;
223
+ }
224
+ const refused = refusal(this.#reads);
225
+ if (refused !== undefined)
226
+ throw refused;
227
+ return outcome;
228
+ }
229
+ #withPage(index, f) {
230
+ const doc = this.#live();
231
+ checkPageIndex(index, this.pageCount);
232
+ const p = this.#p;
233
+ const page = p.FPDF_LoadPage(doc, index);
234
+ if (page === 0)
235
+ throw new RenderError("render-failed", "the pdfium backend could not load the page");
236
+ if (this.#form !== 0)
237
+ p.FORM_OnAfterLoadPage(page, this.#form);
238
+ try {
239
+ return f(page);
240
+ }
241
+ finally {
242
+ if (this.#form !== 0)
243
+ p.FORM_OnBeforeClosePage(page, this.#form);
244
+ p.FPDF_ClosePage(page);
245
+ }
246
+ }
247
+ #geometry(page) {
248
+ const p = this.#p;
249
+ return {
250
+ width: p.FPDF_GetPageWidthF(page),
251
+ height: p.FPDF_GetPageHeightF(page),
252
+ rotate: (((p.FPDFPage_GetRotation(page) % 4) + 4) % 4) * 90,
253
+ };
254
+ }
255
+ page(index) {
256
+ this.#live();
257
+ const cached = this.#pages.get(index);
258
+ if (cached !== undefined)
259
+ return cached;
260
+ const page = this.#reading(() => this.#withPage(index, (handle) => this.#geometry(handle)));
261
+ this.#pages.set(index, page);
262
+ return page;
263
+ }
264
+ plan(request) {
265
+ return planTile(this.page(request.page), request, this.#limits);
266
+ }
267
+ render(request, options = {}) {
268
+ // As in every adapter: the abort first, then whether the document is open.
269
+ throwIfAborted(options.signal);
270
+ this.#live();
271
+ const result = this.#reading(() => this.#withPage(request.page, (page) => this.#renderPage(page, request)));
272
+ throwIfAborted(options.signal);
273
+ return result;
274
+ }
275
+ /** Renders the request's tile of an open page into a fresh bitmap and copies it out. */
276
+ #renderPage(page, request) {
277
+ const p = this.#p;
278
+ const { malloc, free } = p.pdfium.wasmExports;
279
+ const info = this.#geometry(page);
280
+ const plan = planTile(info, request, this.#limits);
281
+ const { width, height } = plan.tile;
282
+ const buffer = malloc(plan.byteLength);
283
+ if (buffer === 0)
284
+ throw new RenderError("render-failed", "the pdfium backend could not allocate the tile");
285
+ const bitmap = p.FPDFBitmap_CreateEx(width, height, FPDFBITMAP_BGRA, buffer, width * 4);
286
+ try {
287
+ if (bitmap === 0)
288
+ throw new RenderError("render-failed", "the pdfium backend could not allocate the tile");
289
+ this.#fillBackground(bitmap, plan, request.background === undefined ? WHITE : request.background);
290
+ this.#draw(bitmap, page, plan, info, request);
291
+ const pixels = new Uint8ClampedArray(plan.byteLength);
292
+ pixels.set(new Uint8Array(heap(p).buffer, buffer, plan.byteLength));
293
+ return { width, height, pixels };
294
+ }
295
+ finally {
296
+ if (bitmap !== 0)
297
+ p.FPDFBitmap_Destroy(bitmap);
298
+ free(buffer);
299
+ }
300
+ }
301
+ /**
302
+ * Draws the page into the bitmap. Widgets need the whole page laid out and shifted, since
303
+ * FPDF_FFLDraw takes no matrix; without them the matrix call draws only the tile.
304
+ */
305
+ #draw(bitmap, page, plan, info, request) {
306
+ const flags = flagsOf(request.flags);
307
+ const renderFlags = renderFlagsOf(flags);
308
+ const rotation = request.rotation ?? 0;
309
+ if (flags.annotations && flags.formWidgets) {
310
+ this.#drawWithWidgets(bitmap, page, plan, rotation / 90, renderFlags);
311
+ }
312
+ else {
313
+ this.#drawWithMatrix(bitmap, page, pageToTile(plan, info, rotation), plan, renderFlags);
314
+ }
315
+ }
316
+ #drawWithWidgets(bitmap, page, plan, rotate, renderFlags) {
317
+ const p = this.#p;
318
+ const [x, y] = [-plan.tile.x, -plan.tile.y];
319
+ p.FPDF_RenderPageBitmap(bitmap, page, x, y, plan.pageWidth, plan.pageHeight, rotate, renderFlags);
320
+ if (this.#form !== 0) {
321
+ p.FPDF_FFLDraw(this.#form, bitmap, page, x, y, plan.pageWidth, plan.pageHeight, rotate, renderFlags);
322
+ }
323
+ }
324
+ /** Fills the whole bitmap with the background, or with transparent black when it is `null`. */
325
+ #fillBackground(bitmap, plan, background) {
326
+ // FillRect takes 0xAARRGGBB into BGRA memory; with R and B swapped it lands as RGBA, the
327
+ // order the reversed-byte-order render writes.
328
+ const c = background ?? { r: 0, g: 0, b: 0, a: 0 };
329
+ const color = ((c.a << 24) | (c.b << 16) | (c.g << 8) | c.r) >>> 0;
330
+ this.#p.FPDFBitmap_FillRect(bitmap, 0, 0, plan.tile.width, plan.tile.height, color);
331
+ }
332
+ /** Draws only the tile, through `matrix` (pageToTile's) and a clip of the whole bitmap. */
333
+ #drawWithMatrix(bitmap, page, matrix, plan, renderFlags) {
334
+ const p = this.#p;
335
+ const { malloc, free } = p.pdfium.wasmExports;
336
+ // FS_MATRIX (6 floats) then FS_RECTF (left, top, right, bottom).
337
+ const scratch = malloc(40);
338
+ if (scratch === 0)
339
+ throw new RenderError("render-failed", "the pdfium backend could not allocate memory");
340
+ try {
341
+ const floats = new Float32Array(heap(p).buffer, scratch, 10);
342
+ floats.set([...matrix, 0, 0, plan.tile.width, plan.tile.height]);
343
+ p.FPDF_RenderPageBitmapWithMatrix(bitmap, page, scratch, scratch + 24, renderFlags);
344
+ }
345
+ finally {
346
+ free(scratch);
347
+ }
348
+ }
349
+ close() {
350
+ if (this.#doc === 0)
351
+ return;
352
+ const p = this.#p;
353
+ if (this.#form !== 0)
354
+ p.PDFiumExt_ExitFormFillEnvironment(this.#form);
355
+ if (this.#formInfo !== 0)
356
+ p.PDFiumExt_CloseFormFillInfo(this.#formInfo);
357
+ p.FPDF_CloseDocument(this.#doc);
358
+ p.pdfium.wasmExports.free(this.#access);
359
+ p.pdfium.removeFunction(this.#getBlock);
360
+ this.#doc = 0;
361
+ this.#form = 0;
362
+ this.#formInfo = 0;
363
+ }
364
+ [Symbol.dispose]() {
365
+ this.close();
366
+ }
367
+ }
368
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,8FAA8F;AAC9F,8FAA8F;AAC9F,iFAAiF;AACjF,+FAA+F;AAC/F,gGAAgG;AAChG,oFAAoF;AACpF,yBAAyB;AACzB,oFAAoF;AACpF,sFAAsF;AACtF,OAAO,EAAE,IAAI,EAA4B,MAAM,kBAAkB,CAAC;AAClE,OAAO,EACL,cAAc,EACd,SAAS,EACT,cAAc,EACd,OAAO,EACP,QAAQ,EACR,cAAc,EACd,UAAU,EACV,YAAY,EACZ,QAAQ,EAGR,WAAW,EASX,WAAW,EACX,SAAS,EAET,cAAc,EAEd,KAAK,GACN,MAAM,mBAAmB,CAAC;AAE3B,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAIxD,aAAa;AACb,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,aAAa,GAAG,KAAK,CAAC;AAC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I,CAAC,OAAO,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC;YAAE,OAAO;QAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,IAAI,CAAC,KAAK,KAAK,CAAC;YAAE,CAAC,CAAC,iCAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtE,IAAI,IAAI,CAAC,SAAS,KAAK,CAAC;YAAE,CAAC,CAAC,2BAA2B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxE,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACrB,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@laminapdf/render-pdfium",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0-alpha.3",
4
+ "description": "ADR 0004's default web renderer: the pinned PDFium-WASM build (@embedpdf/pdfium 2.15.1, SHA-256 checked) behind @laminapdf/render's RenderBackend interface, for the document worker.",
5
+ "license": "MIT OR Apache-2.0",
6
+ "homepage": "https://laminapdf.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/laudebugs/laminapdf.git",
10
+ "directory": "packages/render-pdfium"
11
+ },
12
+ "keywords": [
13
+ "pdf",
14
+ "render",
15
+ "pdfium",
16
+ "wasm"
17
+ ],
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "THIRD_PARTY_NOTICES.md"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "dependencies": {
35
+ "@embedpdf/pdfium": "2.15.1",
36
+ "@laminapdf/render": "0.2.0-alpha.3"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "26.6.5",
40
+ "@vitest/browser-playwright": "5.0.5",
41
+ "playwright": "1.64.1",
42
+ "typescript": "7.0.2",
43
+ "vite": "8.3.5",
44
+ "vitest": "5.0.5",
45
+ "@laminapdf/test-utils": "0.0.0"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "scripts": {
51
+ "build": "node scripts/verify-pdfium.mjs && tsc -p tsconfig.build.json",
52
+ "typecheck": "node scripts/verify-pdfium.mjs && tsc -p tsconfig.build.json && tsc --noEmit -p tsconfig.json",
53
+ "test": "node scripts/verify-pdfium.mjs && tsc -p tsconfig.build.json && vitest run -c vitest.node.config.ts"
54
+ }
6
55
  }