bm-render 0.0.0-stage → 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/LICENSE +21 -0
- package/NOTICE +38 -0
- package/README.md +51 -3
- package/README.vi.md +51 -0
- package/THIRD-PARTY-NOTICES.md +1228 -0
- package/js/addons.d.mts +13 -0
- package/js/addons.mjs +74 -0
- package/js/bm_render.core.wasm +0 -0
- package/js/bm_render.pdf.wasm +0 -0
- package/js/bm_render.standard.wasm +0 -0
- package/js/bm_render.wasm +0 -0
- package/js/bm_woff.wasm +0 -0
- package/js/build-manifest.json +46 -0
- package/js/core.d.mts +16 -0
- package/js/core.mjs +20 -0
- package/js/engine.mjs +797 -0
- package/js/full.d.mts +16 -0
- package/js/full.mjs +20 -0
- package/js/index.d.mts +381 -0
- package/js/index.mjs +64 -0
- package/js/native.d.mts +4 -0
- package/js/native.mjs +250 -0
- package/js/node-core.mjs +9 -0
- package/js/node-full.mjs +9 -0
- package/js/node-native.mjs +15 -0
- package/js/node-pdf.mjs +34 -0
- package/js/node-standard.mjs +9 -0
- package/js/node.mjs +63 -0
- package/js/pdf-api.mjs +232 -0
- package/js/pdf-resources.mjs +152 -0
- package/js/pdf-types.d.mts +211 -0
- package/js/pdf.d.mts +85 -0
- package/js/pdf.mjs +26 -0
- package/js/standard.d.mts +16 -0
- package/js/standard.mjs +20 -0
- package/js/wasm-file.mjs +93 -0
- package/js/wasm.d.mts +9 -0
- package/package.json +248 -4
package/js/addons.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// bm-render/woff: lazily loaded add-on modules (js/addons.mjs).
|
|
2
|
+
import type { ByteBuf, OutputBytes } from "./index.mjs";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Instantiates the WOFF add-on (bm_woff.wasm, ~85 KiB) and makes `registerFont` accept WOFF / WOFF2 on
|
|
6
|
+
* builds without built-in support (any entry in the process). `input`: wasm bytes, a WebAssembly.Module,
|
|
7
|
+
* a URL / Request / Response, or omitted (Node: the file next to addons.mjs; bundlers / browsers:
|
|
8
|
+
* `new URL("./bm_woff.wasm", import.meta.url)`). Idempotent. `builtIn` reports whether the `bm-render`
|
|
9
|
+
* entry's loaded build decodes WOFF itself.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadWoff(input?: ByteBuf | WebAssembly.Module | URL | string | Request | Response | Promise<unknown>): Promise<{ builtIn: boolean }>;
|
|
12
|
+
/** WOFF / WOFF2 -> sfnt (TTF / OTF) bytes with the loaded add-on. */
|
|
13
|
+
export declare function decodeWoff(bytes: ByteBuf): OutputBytes;
|
package/js/addons.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Lazily loaded add-on wasm modules for the smaller engine builds.
|
|
2
|
+
//
|
|
3
|
+
// import { loadWoff } from "bm-render/woff";
|
|
4
|
+
// await loadWoff(); // Node: reads bm_woff.wasm next to this file; bundlers: emitted asset via new URL(...);
|
|
5
|
+
// // Workers: await loadWoff(woffModule) with import woffModule from "bm-render/woff.wasm"
|
|
6
|
+
// renderer.registerFont(woff2Bytes); // now works on a build without WOFF support
|
|
7
|
+
//
|
|
8
|
+
// bm_woff.wasm (WOFF / WOFF2 -> sfnt, the engine's own decoder incl. brotli) is a separate ~90 KB module
|
|
9
|
+
// with no imports; registerFont uses it automatically when the main binary has no WOFF support. The
|
|
10
|
+
// converted font is byte-identical to what the built-in path registers. The decoder is shared by every
|
|
11
|
+
// entry (bm-render, bm-render/core, ...) in the process.
|
|
12
|
+
import { setWoffDecoder, readFileUrl, builtInWoffDecoder } from "./engine.mjs";
|
|
13
|
+
import { features } from "./index.mjs";
|
|
14
|
+
|
|
15
|
+
let woff = null;
|
|
16
|
+
let loading = null;
|
|
17
|
+
|
|
18
|
+
async function bytesOf(input) {
|
|
19
|
+
input = await input;
|
|
20
|
+
if (input == null) {
|
|
21
|
+
const url = new URL("./bm_woff.wasm", import.meta.url);
|
|
22
|
+
if (url.protocol === "file:") return readFileUrl(url);
|
|
23
|
+
input = url;
|
|
24
|
+
}
|
|
25
|
+
if (typeof input === "string" || input instanceof URL || (typeof Request !== "undefined" && input instanceof Request)) input = await fetch(input);
|
|
26
|
+
if (typeof Response !== "undefined" && input instanceof Response) {
|
|
27
|
+
if (!input.ok) throw new Error(`bm-render: failed to fetch bm_woff.wasm (${input.status}): ${input.url}`);
|
|
28
|
+
return new Uint8Array(await input.arrayBuffer());
|
|
29
|
+
}
|
|
30
|
+
return input;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Converts WOFF / WOFF2 bytes to an sfnt (TTF / OTF) with the loaded add-on. */
|
|
34
|
+
export function decodeWoff(bytes) {
|
|
35
|
+
if (!woff) {
|
|
36
|
+
const builtIn = builtInWoffDecoder(); // the native addon decodes WOFF itself
|
|
37
|
+
if (builtIn) return builtIn(bytes);
|
|
38
|
+
throw new Error("bm-render: call loadWoff() first");
|
|
39
|
+
}
|
|
40
|
+
const W = woff;
|
|
41
|
+
const src = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes.buffer ?? bytes, bytes.byteOffset ?? 0, bytes.byteLength);
|
|
42
|
+
const p = W.bm_alloc(src.length || 1);
|
|
43
|
+
if (!p) throw new Error("bm-render: out of memory (woff add-on)");
|
|
44
|
+
new Uint8Array(W.memory.buffer).set(src, p);
|
|
45
|
+
const st = W.bm_woff_decode(p, src.length);
|
|
46
|
+
W.bm_free(p, src.length || 1);
|
|
47
|
+
if (st !== 0) throw new Error(st === 2 ? "bm-render: out of memory (woff add-on)" : "bm-render: invalid WOFF/WOFF2 font data");
|
|
48
|
+
const rp = W.bm_woff_result_ptr(), rn = W.bm_woff_result_len();
|
|
49
|
+
const out = new Uint8Array(W.memory.buffer).slice(rp, rp + rn);
|
|
50
|
+
W.bm_woff_release();
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Instantiates the WOFF add-on (bm_woff.wasm) and makes `registerFont` accept WOFF / WOFF2 on builds
|
|
56
|
+
* without built-in support. `input`: bytes, a WebAssembly.Module, a URL / Request / Response, or
|
|
57
|
+
* omitted (Node: the file next to this module; browsers: fetched from the same directory).
|
|
58
|
+
*/
|
|
59
|
+
export async function loadWoff(input) {
|
|
60
|
+
// Native backend loaded (Node.js): WOFF / WOFF2 is compiled in and its decoder already serves every entry.
|
|
61
|
+
if (builtInWoffDecoder()) return { builtIn: true };
|
|
62
|
+
if (!woff) {
|
|
63
|
+
if (!loading) {
|
|
64
|
+
loading = (async () => {
|
|
65
|
+
const src = await bytesOf(input);
|
|
66
|
+
const inst = Object.prototype.toString.call(src) === "[object WebAssembly.Module]" ? await WebAssembly.instantiate(src, {}) : (await WebAssembly.instantiate(src, {})).instance;
|
|
67
|
+
woff = inst.exports;
|
|
68
|
+
})().finally(() => { loading = null; });
|
|
69
|
+
}
|
|
70
|
+
await loading;
|
|
71
|
+
}
|
|
72
|
+
setWoffDecoder(decodeWoff);
|
|
73
|
+
return { builtIn: features.woff };
|
|
74
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/js/bm_woff.wasm
ADDED
|
Binary file
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"package": "bm-render",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"date": "2026-11-16T03:11:06.515Z",
|
|
5
|
+
"git": "ac27b4d-dirty",
|
|
6
|
+
"zig": "0.17.0",
|
|
7
|
+
"files": {
|
|
8
|
+
"core": {
|
|
9
|
+
"file": "js/bm_render.core.wasm",
|
|
10
|
+
"bytes": 641236,
|
|
11
|
+
"sha256": "34bf8761a1e405748a1ab26e309012999292296b669e9859c833260eccc9849d",
|
|
12
|
+
"profile": "core",
|
|
13
|
+
"features": "0x0",
|
|
14
|
+
"custom": false
|
|
15
|
+
},
|
|
16
|
+
"standard": {
|
|
17
|
+
"file": "js/bm_render.standard.wasm",
|
|
18
|
+
"bytes": 1101451,
|
|
19
|
+
"sha256": "1fc119ea9061dc68c6a9c334688e781295357a101cac6ce6ee8baa38b62ac92a",
|
|
20
|
+
"profile": "standard",
|
|
21
|
+
"features": "0x1fff",
|
|
22
|
+
"custom": false
|
|
23
|
+
},
|
|
24
|
+
"full": {
|
|
25
|
+
"file": "js/bm_render.wasm",
|
|
26
|
+
"bytes": 1303291,
|
|
27
|
+
"sha256": "23ca1ee3dc8f0665989732c09fe0208ad6395754b1b1550c3d148814b48e6898",
|
|
28
|
+
"profile": "full",
|
|
29
|
+
"features": "0x3ffff",
|
|
30
|
+
"custom": false
|
|
31
|
+
},
|
|
32
|
+
"woff": {
|
|
33
|
+
"file": "js/bm_woff.wasm",
|
|
34
|
+
"bytes": 86399,
|
|
35
|
+
"sha256": "fb7ffb487956283ea749d8201b85149735b15065aaa7371e69fbaa3d9872b2fb"
|
|
36
|
+
},
|
|
37
|
+
"pdf": {
|
|
38
|
+
"file": "js/bm_render.pdf.wasm",
|
|
39
|
+
"bytes": 1952483,
|
|
40
|
+
"sha256": "732022192568246946237440bac877afcf25ceda6b097495b13ee15720393986",
|
|
41
|
+
"profile": "pdf",
|
|
42
|
+
"features": "0x7ffff",
|
|
43
|
+
"custom": false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
package/js/core.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// bm-render/core: the core build profile (bm_render.core.wasm) with its own module instance. Same API as bm-render
|
|
2
|
+
// (./index.d.mts); init() may be called without an argument (and on Node.js it already ran on import).
|
|
3
|
+
import type { InitArgument, WasmExports } from "./index.mjs";
|
|
4
|
+
|
|
5
|
+
export * from "./index.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Instantiates the core wasm. Without an argument it loads bm_render.core.wasm from next to the module
|
|
8
|
+
* (`new URL("./bm_render.core.wasm", import.meta.url)`, which bundlers emit as an asset). On Cloudflare Workers pass
|
|
9
|
+
* the module: `import wasm from "bm-render/core.wasm"; await init(wasm)`. Idempotent.
|
|
10
|
+
*/
|
|
11
|
+
export declare function init(input?: InitArgument): Promise<WasmExports>;
|
|
12
|
+
export default init;
|
|
13
|
+
/** The URL init() loads by default (throws where `import.meta.url` is unusable). */
|
|
14
|
+
export declare function wasmUrl(): URL;
|
|
15
|
+
/** Build profile of this entry. */
|
|
16
|
+
export declare const profile: "core";
|
package/js/core.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// bm-render/core (browsers, bundlers, Deno, edge runtimes): the core build profile (bm_render.core.wasm) with its own
|
|
2
|
+
// module instance. `await init()` without an argument loads bm_render.core.wasm from next to this file through
|
|
3
|
+
// `new URL("./bm_render.core.wasm", import.meta.url)`, a pattern Vite, webpack 5, Rollup and Parcel turn into an emitted
|
|
4
|
+
// asset. Where that cannot work (Cloudflare Workers / workerd), pass the precompiled module instead:
|
|
5
|
+
//
|
|
6
|
+
// import wasm from "bm-render/core.wasm"; // a WebAssembly.Module under wrangler
|
|
7
|
+
// import { init, Renderer } from "bm-render/core";
|
|
8
|
+
// await init(wasm);
|
|
9
|
+
//
|
|
10
|
+
// On Node.js this subpath resolves to ./node-core.mjs, which reads the file and initialises on import.
|
|
11
|
+
// API: see ./index.mjs and ./index.d.mts.
|
|
12
|
+
import { createBinding } from "./engine.mjs";
|
|
13
|
+
|
|
14
|
+
const binding = createBinding(() => new URL("./bm_render.core.wasm", import.meta.url));
|
|
15
|
+
|
|
16
|
+
export const { init, initSync, Renderer, features, setGlyphCacheMaxBytes, wasmUrl, backend } = binding;
|
|
17
|
+
export { Prepared, setWoffDecoder } from "./engine.mjs";
|
|
18
|
+
/** Build profile of this entry. */
|
|
19
|
+
export const profile = "core";
|
|
20
|
+
export default init;
|