modern-pdf-lib 0.15.1 → 0.22.9
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 +119 -9
- package/dist/batchOptimize-Ba_pWw71.cjs +427 -0
- package/dist/batchOptimize-CxyY4fZe.mjs +392 -0
- package/dist/{bridge-DpzMOnHd.mjs → bridge-DTH5LMAK.mjs} +3 -3
- package/dist/{bridge-DN7BOHRW.cjs → bridge-DYCQzxF7.cjs} +2 -2
- package/dist/browser.cjs +621 -0
- package/dist/browser.d.cts +190 -0
- package/dist/browser.d.cts.map +1 -0
- package/dist/browser.d.mts +190 -0
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.mjs +212 -0
- package/dist/cli/index.cjs +40 -18
- package/dist/cli/index.mjs +40 -18
- package/dist/compressionAnalysis-B84FPXaQ.cjs +1525 -0
- package/dist/compressionAnalysis-BBv4BkQP.d.mts +261 -0
- package/dist/compressionAnalysis-BBv4BkQP.d.mts.map +1 -0
- package/dist/compressionAnalysis-ChkscEa1.mjs +1490 -0
- package/dist/compressionAnalysis-CtJ2X9l2.d.cts +261 -0
- package/dist/compressionAnalysis-CtJ2X9l2.d.cts.map +1 -0
- package/dist/create.cjs +35 -0
- package/dist/create.d.cts +3 -0
- package/dist/create.d.mts +3 -0
- package/dist/create.mjs +5 -0
- package/dist/{deduplicateImages-BfpjHY9b.mjs → deduplicateImages-CmTeo6Tx.mjs} +3 -3
- package/dist/{deduplicateImages-BtJ5tlrr.cjs → deduplicateImages-cKsnD6Ep.cjs} +2 -2
- package/dist/{fflateAdapter-D2mv_ttM.mjs → fflateAdapter-CBQpGTlx.mjs} +2 -2
- package/dist/{fflateAdapter-cT4YeY_h.cjs → fflateAdapter-LTAeAhaD.cjs} +1 -1
- package/dist/fieldAppearance-C8PoLFSc.d.mts +136 -0
- package/dist/fieldAppearance-C8PoLFSc.d.mts.map +1 -0
- package/dist/fieldAppearance-CdiGFG5e.d.cts +136 -0
- package/dist/fieldAppearance-CdiGFG5e.d.cts.map +1 -0
- package/dist/fontEmbed-Dsu9fo4U.d.mts +636 -0
- package/dist/fontEmbed-Dsu9fo4U.d.mts.map +1 -0
- package/dist/fontEmbed-LID6yG6g.d.cts +636 -0
- package/dist/fontEmbed-LID6yG6g.d.cts.map +1 -0
- package/dist/{fontSubset-BxsF9Tu5.cjs → fontSubset-5SLWMmEw.cjs} +1 -1
- package/dist/{fontSubset-ClyTXlhY.mjs → fontSubset-DWpduoY2.mjs} +2 -2
- package/dist/forms.cjs +13 -0
- package/dist/forms.d.cts +3 -0
- package/dist/forms.d.mts +3 -0
- package/dist/forms.mjs +3 -0
- package/dist/grayscaleDetect-C2m-eEXR.cjs +96 -0
- package/dist/grayscaleDetect-C6kFF3dk.mjs +84 -0
- package/dist/imageExtract-Dnk_Ssv7.mjs +155 -0
- package/dist/imageExtract-zEb1gnkb.cjs +166 -0
- package/dist/index-BtYOx5wh.d.mts +4904 -0
- package/dist/index-BtYOx5wh.d.mts.map +1 -0
- package/dist/index-bpktKzCA.d.cts +4904 -0
- package/dist/index-bpktKzCA.d.cts.map +1 -0
- package/dist/index.cjs +274 -20704
- package/dist/index.d.cts +7 -9151
- package/dist/index.d.mts +7 -9151
- package/dist/index.mjs +17 -20532
- package/dist/layout-CuAVk_Or.cjs +563 -0
- package/dist/layout-DgX_0jfK.mjs +438 -0
- package/dist/{libdeflateWasm-Cg7cWHOq.cjs → libdeflateWasm-BdiDEJOj.cjs} +2 -2
- package/dist/{libdeflateWasm-Cmxa-yiS.mjs → libdeflateWasm-rLppXytE.mjs} +3 -3
- package/dist/loader-3u6Tw5T-.mjs +328 -0
- package/dist/loader-I4zdkoWc.cjs +393 -0
- package/dist/parse.cjs +24 -0
- package/dist/parse.d.cts +4 -0
- package/dist/parse.d.mts +4 -0
- package/dist/parse.mjs +7 -0
- package/dist/{pdfCatalog-BcOL6QF-.cjs → pdfCatalog-CYy4NXEY.cjs} +2 -2
- package/dist/{pdfCatalog-CnJRovvm.mjs → pdfCatalog-IImGcMbR.mjs} +3 -3
- package/dist/pdfDocument-BFxHD_2u.mjs +13755 -0
- package/dist/pdfDocument-BSiQdNZq.d.cts +4640 -0
- package/dist/pdfDocument-BSiQdNZq.d.cts.map +1 -0
- package/dist/pdfDocument-i6U5fQ91.d.mts +4640 -0
- package/dist/pdfDocument-i6U5fQ91.d.mts.map +1 -0
- package/dist/pdfDocument-pmRXryVI.cjs +14180 -0
- package/dist/pdfForm-9gd40uz9.cjs +1796 -0
- package/dist/pdfForm-BiyNtYem.d.mts +905 -0
- package/dist/pdfForm-BiyNtYem.d.mts.map +1 -0
- package/dist/pdfForm-Cn-cVicP.mjs +1695 -0
- package/dist/pdfForm-SOXJ72LW.d.cts +905 -0
- package/dist/pdfForm-SOXJ72LW.d.cts.map +1 -0
- package/dist/{pdfObjects-BrU4Xd0V.cjs → pdfObjects-1veop1_d.cjs} +2 -2
- package/dist/{pdfObjects-DZZ2GPRW.mjs → pdfObjects-uEsWlfzU.mjs} +2 -2
- package/dist/{pdfPage-Dm5XC_g_.mjs → pdfPage-Cd8e7flb.mjs} +3024 -5
- package/dist/{pdfPage-Dz_SVKUS.cjs → pdfPage-Cd8jOJp6.cjs} +3046 -3
- package/dist/{pngEmbed-I1hU3Y6m.mjs → pngEmbed-BLj2zi-5.mjs} +3 -3
- package/dist/{pngEmbed-C6M1eX6b.cjs → pngEmbed-D4X4ZN-3.cjs} +2 -2
- package/dist/src-6L07EQsi.cjs +11852 -0
- package/dist/src-Dm4aaZ8q.mjs +11103 -0
- package/dist/{imageExtract-vjyQyFcT.mjs → streamDecode-Bj568Nc9.mjs} +1646 -188
- package/dist/{imageExtract-BC7TMY98.cjs → streamDecode-CvgErkFu.cjs} +1645 -199
- package/package.json +33 -1
- package/dist/batchOptimize-ClXizv19.mjs +0 -306
- package/dist/batchOptimize-DYQOX1-7.cjs +0 -329
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/loader-B6VIrZOJ.mjs +0 -164
- package/dist/loader-DdB5Xo5D.cjs +0 -166
- package/dist/rolldown-runtime-95iHPtFO.mjs +0 -18
package/dist/loader-DdB5Xo5D.cjs
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/wasm/loader.ts
|
|
3
|
-
/** Map of module names to their default `.wasm` filenames. */
|
|
4
|
-
const DEFAULT_FILENAMES = {
|
|
5
|
-
libdeflate: "modern_pdf_deflate_bg.wasm",
|
|
6
|
-
png: "modern_pdf_png_bg.wasm",
|
|
7
|
-
ttf: "modern_pdf_ttf_bg.wasm",
|
|
8
|
-
shaping: "modern_pdf_shaping_bg.wasm",
|
|
9
|
-
jbig2: "modern_pdf_jbig2_bg.wasm",
|
|
10
|
-
jpeg: "modern_pdf_jpeg_bg.wasm"
|
|
11
|
-
};
|
|
12
|
-
/** Cached loaded WASM modules. */
|
|
13
|
-
const moduleCache = /* @__PURE__ */ new Map();
|
|
14
|
-
/** Global loader configuration. */
|
|
15
|
-
let globalConfig = {};
|
|
16
|
-
/**
|
|
17
|
-
* Detect the current JavaScript runtime environment.
|
|
18
|
-
*
|
|
19
|
-
* @returns The detected runtime kind.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const runtime = detectRuntime();
|
|
24
|
-
* if (runtime === 'node') { ... }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
function detectRuntime() {
|
|
28
|
-
if (typeof globalThis !== "undefined" && "caches" in globalThis && typeof globalThis["HTMLElement"] === "undefined" && typeof globalThis["process"] === "undefined") {
|
|
29
|
-
if (typeof globalThis["navigator"] === "object") {
|
|
30
|
-
if ((globalThis.navigator?.userAgent ?? "").includes("Cloudflare-Workers")) return "workerd";
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (typeof globalThis["Deno"] === "object") return "deno";
|
|
34
|
-
if (typeof globalThis["Bun"] === "object") return "bun";
|
|
35
|
-
if (typeof globalThis["process"] === "object" && typeof globalThis["process"]?.["versions"] === "object" && typeof (globalThis["process"]?.["versions"])?.["node"] === "string") return "node";
|
|
36
|
-
if (typeof globalThis.document === "object" || typeof globalThis.window === "object") return "browser";
|
|
37
|
-
return "unknown";
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get the current WASM loader configuration (for testing/inspection).
|
|
41
|
-
*/
|
|
42
|
-
function getWasmLoaderConfig() {
|
|
43
|
-
return globalConfig;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Load WASM bytes using `fetch()` (works in browsers, Deno, Bun, and
|
|
47
|
-
* Node.js 18+).
|
|
48
|
-
*
|
|
49
|
-
* @param url - URL or path to the `.wasm` file.
|
|
50
|
-
* @returns The raw WASM bytes.
|
|
51
|
-
*/
|
|
52
|
-
async function loadViaFetch(url) {
|
|
53
|
-
const response = await fetch(url);
|
|
54
|
-
if (!response.ok) throw new Error(`Failed to fetch WASM module: ${response.status} ${response.statusText} (${url})`);
|
|
55
|
-
const buffer = await response.arrayBuffer();
|
|
56
|
-
return new Uint8Array(buffer);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Load WASM bytes from the filesystem using Node.js `fs/promises`.
|
|
60
|
-
*
|
|
61
|
-
* Uses dynamic import to avoid top-level CJS dependency.
|
|
62
|
-
*
|
|
63
|
-
* @param filePath - Absolute or relative filesystem path.
|
|
64
|
-
* @returns The raw WASM bytes.
|
|
65
|
-
*/
|
|
66
|
-
async function loadViaNodeFs(filePath) {
|
|
67
|
-
try {
|
|
68
|
-
const { readFile } = await import("node:fs/promises");
|
|
69
|
-
const buffer = await readFile(filePath);
|
|
70
|
-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
71
|
-
} catch (err) {
|
|
72
|
-
throw new Error(`Failed to load WASM module from filesystem: ${filePath} -- ${err instanceof Error ? err.message : String(err)}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Resolve the path/URL for a WASM module given its name.
|
|
77
|
-
*
|
|
78
|
-
* Resolution order:
|
|
79
|
-
* 1. `config.modulePaths[name]` (explicit per-module path)
|
|
80
|
-
* 2. `config.basePath + DEFAULT_FILENAMES[name]` (base path + default name)
|
|
81
|
-
* 3. Relative to the package directory (best-effort)
|
|
82
|
-
*
|
|
83
|
-
* @param name - Module name (e.g. `'libdeflate'`).
|
|
84
|
-
* @param config - Current loader config.
|
|
85
|
-
* @param runtime - Detected runtime.
|
|
86
|
-
* @returns Resolved path or URL string.
|
|
87
|
-
*/
|
|
88
|
-
function resolveModulePath(name, config, runtime) {
|
|
89
|
-
if (config.modulePaths?.[name]) return config.modulePaths[name];
|
|
90
|
-
const filename = DEFAULT_FILENAMES[name];
|
|
91
|
-
if (!filename) throw new Error(`Unknown WASM module: "${name}". Known modules: ${Object.keys(DEFAULT_FILENAMES).join(", ")}`);
|
|
92
|
-
if (config.basePath) return `${config.basePath.endsWith("/") ? config.basePath : `${config.basePath}/`}${filename}`;
|
|
93
|
-
switch (runtime) {
|
|
94
|
-
case "browser": return `/wasm/${filename}`;
|
|
95
|
-
case "node":
|
|
96
|
-
case "bun": try {
|
|
97
|
-
return new URL(`../wasm/${name}/pkg/${filename}`, require("url").pathToFileURL(__filename).href).pathname;
|
|
98
|
-
} catch {
|
|
99
|
-
return `./wasm/${name}/pkg/${filename}`;
|
|
100
|
-
}
|
|
101
|
-
case "deno": try {
|
|
102
|
-
return new URL(`../wasm/${name}/pkg/${filename}`, require("url").pathToFileURL(__filename).href).href;
|
|
103
|
-
} catch {
|
|
104
|
-
return `./wasm/${name}/pkg/${filename}`;
|
|
105
|
-
}
|
|
106
|
-
case "workerd": throw new Error(`Cannot auto-resolve WASM path in Workers/Edge runtime. Provide WASM bytes via configureWasmLoader({ moduleBytes: { ${name}: bytes } }) or use modulePaths configuration.`);
|
|
107
|
-
default: return `./wasm/${name}/pkg/${filename}`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Load a WASM module by name.
|
|
112
|
-
*
|
|
113
|
-
* Returns the raw `.wasm` bytes, suitable for passing to
|
|
114
|
-
* `WebAssembly.compile()` or `WebAssembly.instantiate()`.
|
|
115
|
-
*
|
|
116
|
-
* Results are cached -- subsequent calls for the same module name
|
|
117
|
-
* return the cached bytes without re-fetching.
|
|
118
|
-
*
|
|
119
|
-
* @param name - Module name. One of: `'libdeflate'`, `'png'`, `'ttf'`, `'shaping'`, `'jbig2'`.
|
|
120
|
-
* @returns The raw WASM bytes.
|
|
121
|
-
* @throws If the module cannot be loaded in the current runtime.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* // Auto-detect runtime and load
|
|
126
|
-
* const wasmBytes = await loadWasmModule('libdeflate');
|
|
127
|
-
*
|
|
128
|
-
* // Pre-configure for Workers
|
|
129
|
-
* configureWasmLoader({ moduleBytes: { libdeflate: bundledBytes } });
|
|
130
|
-
* const bytes = await loadWasmModule('libdeflate');
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
async function loadWasmModule(name) {
|
|
134
|
-
const cached = moduleCache.get(name);
|
|
135
|
-
if (cached) return cached;
|
|
136
|
-
if (globalConfig.moduleBytes?.[name]) {
|
|
137
|
-
const bytes = globalConfig.moduleBytes[name];
|
|
138
|
-
moduleCache.set(name, bytes);
|
|
139
|
-
return bytes;
|
|
140
|
-
}
|
|
141
|
-
const runtime = detectRuntime();
|
|
142
|
-
const modulePath = resolveModulePath(name, globalConfig, runtime);
|
|
143
|
-
let bytes;
|
|
144
|
-
switch (runtime) {
|
|
145
|
-
case "node":
|
|
146
|
-
if (modulePath.startsWith("http://") || modulePath.startsWith("https://")) bytes = await loadViaFetch(modulePath);
|
|
147
|
-
else bytes = await loadViaNodeFs(modulePath);
|
|
148
|
-
break;
|
|
149
|
-
case "deno":
|
|
150
|
-
case "bun":
|
|
151
|
-
case "browser":
|
|
152
|
-
bytes = await loadViaFetch(modulePath);
|
|
153
|
-
break;
|
|
154
|
-
case "workerd": throw new Error(`WASM module "${name}" cannot be auto-loaded in Workers/Edge. Provide bytes via configureWasmLoader().`);
|
|
155
|
-
default:
|
|
156
|
-
bytes = await loadViaFetch(modulePath);
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
moduleCache.set(name, bytes);
|
|
160
|
-
return bytes;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
//#endregion
|
|
164
|
-
exports.getWasmLoaderConfig = getWasmLoaderConfig;
|
|
165
|
-
exports.loadWasmModule = loadWasmModule;
|
|
166
|
-
//# sourceMappingURL=loader-DdB5Xo5D.cjs.map
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (!no_symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __exportAll as t };
|