@jackgreen2018/pdf-engine 1.0.91 → 1.0.93

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/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // Root entry point for @jackgreen2018/pdf-engine
2
2
  // WASM layer for compress/decompress, pdf-lib for merge/split/optimize
3
3
 
4
+ import { createRequire } from 'module';
5
+ import { fileURLToPath } from 'url';
4
6
  import { PDFDocument } from 'pdf-lib';
5
7
 
6
- // Load WASM module
7
- const wasmPath = new URL('./pkg/pdf_tool.js', import.meta.url).pathname;
8
- const wasmModule = await import(wasmPath);
9
- const wasm = wasmModule.default || wasmModule;
8
+ // Load WASM module (ESM output from wasm-pack --target bundler)
9
+ import * as wasm from './pkg/pdf_tool.js';
10
10
 
11
11
  // Compress/decompress - pure WASM
12
12
  export function compress_pdf(input) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jackgreen2018/pdf-engine",
3
- "version": "1.0.91",
3
+ "version": "1.0.93",
4
4
  "type": "module",
5
5
  "description": "Rust/WASM PDF library for merge, split, optimize, and info operations",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "optimize"
30
30
  ],
31
31
  "scripts": {
32
- "build": "wasm-pack build --target nodejs",
32
+ "build": "wasm-pack build --target bundler",
33
33
  "test": "cargo test",
34
34
  "prepack": "npm run build && rm -f pkg/package.json"
35
35
  },
package/pkg/pdf_tool.js CHANGED
@@ -1,193 +1,9 @@
1
1
  /* @ts-self-types="./pdf_tool.d.ts" */
2
+ import * as wasm from "./pdf_tool_bg.wasm";
3
+ import { __wbg_set_wasm } from "./pdf_tool_bg.js";
2
4
 
3
- /**
4
- * Compress data using deflate (PDF content stream compression).
5
- * @param {Uint8Array} input
6
- * @returns {Uint8Array}
7
- */
8
- function compress_pdf(input) {
9
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
10
- const len0 = WASM_VECTOR_LEN;
11
- const ret = wasm.compress_pdf(ptr0, len0);
12
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
13
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
14
- return v2;
15
- }
16
- exports.compress_pdf = compress_pdf;
17
-
18
- /**
19
- * Decompress data that was compressed with deflate (raw).
20
- * @param {Uint8Array} input
21
- * @returns {Uint8Array}
22
- */
23
- function decompress_pdf(input) {
24
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
25
- const len0 = WASM_VECTOR_LEN;
26
- const ret = wasm.decompress_pdf(ptr0, len0);
27
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
28
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
29
- return v2;
30
- }
31
- exports.decompress_pdf = decompress_pdf;
32
-
33
- /**
34
- * Get PDF information including page count.
35
- * @param {Uint8Array} input
36
- * @returns {string}
37
- */
38
- function get_info(input) {
39
- let deferred2_0;
40
- let deferred2_1;
41
- try {
42
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
43
- const len0 = WASM_VECTOR_LEN;
44
- const ret = wasm.get_info(ptr0, len0);
45
- deferred2_0 = ret[0];
46
- deferred2_1 = ret[1];
47
- return getStringFromWasm0(ret[0], ret[1]);
48
- } finally {
49
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
50
- }
51
- }
52
- exports.get_info = get_info;
53
-
54
- /**
55
- * Merge two PDF documents by combining their pages into a single valid PDF.
56
- * @param {Uint8Array} input1
57
- * @param {Uint8Array} input2
58
- * @returns {Uint8Array}
59
- */
60
- function merge_pdfs(input1, input2) {
61
- const ptr0 = passArray8ToWasm0(input1, wasm.__wbindgen_malloc);
62
- const len0 = WASM_VECTOR_LEN;
63
- const ptr1 = passArray8ToWasm0(input2, wasm.__wbindgen_malloc);
64
- const len1 = WASM_VECTOR_LEN;
65
- const ret = wasm.merge_pdfs(ptr0, len0, ptr1, len1);
66
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
67
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
68
- return v3;
69
- }
70
- exports.merge_pdfs = merge_pdfs;
71
-
72
- /**
73
- * Optimize PDF by re-serializing (normalizes structure and recompresses streams).
74
- * @param {Uint8Array} input
75
- * @returns {Uint8Array}
76
- */
77
- function optimize_pdf(input) {
78
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
79
- const len0 = WASM_VECTOR_LEN;
80
- const ret = wasm.optimize_pdf(ptr0, len0);
81
- var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
82
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
83
- return v2;
84
- }
85
- exports.optimize_pdf = optimize_pdf;
86
-
87
- /**
88
- * Split a PDF document into requested pages and return a new PDF.
89
- * @param {Uint8Array} input
90
- * @param {Uint32Array} pages
91
- * @returns {Uint8Array}
92
- */
93
- function split_pdf(input, pages) {
94
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
95
- const len0 = WASM_VECTOR_LEN;
96
- const ptr1 = passArray32ToWasm0(pages, wasm.__wbindgen_malloc);
97
- const len1 = WASM_VECTOR_LEN;
98
- const ret = wasm.split_pdf(ptr0, len0, ptr1, len1);
99
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
100
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
101
- return v3;
102
- }
103
- exports.split_pdf = split_pdf;
104
- function __wbg_get_imports() {
105
- const import0 = {
106
- __proto__: null,
107
- __wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
108
- globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
109
- }, arguments); },
110
- __wbindgen_init_externref_table: function() {
111
- const table = wasm.__wbindgen_externrefs;
112
- const offset = table.grow(4);
113
- table.set(0, undefined);
114
- table.set(offset + 0, undefined);
115
- table.set(offset + 1, null);
116
- table.set(offset + 2, true);
117
- table.set(offset + 3, false);
118
- },
119
- };
120
- return {
121
- __proto__: null,
122
- "./pdf_tool_bg.js": import0,
123
- };
124
- }
125
-
126
- function addToExternrefTable0(obj) {
127
- const idx = wasm.__externref_table_alloc();
128
- wasm.__wbindgen_externrefs.set(idx, obj);
129
- return idx;
130
- }
131
-
132
- function getArrayU8FromWasm0(ptr, len) {
133
- ptr = ptr >>> 0;
134
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
135
- }
136
-
137
- function getStringFromWasm0(ptr, len) {
138
- return decodeText(ptr >>> 0, len);
139
- }
140
-
141
- let cachedUint32ArrayMemory0 = null;
142
- function getUint32ArrayMemory0() {
143
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
144
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
145
- }
146
- return cachedUint32ArrayMemory0;
147
- }
148
-
149
- let cachedUint8ArrayMemory0 = null;
150
- function getUint8ArrayMemory0() {
151
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
152
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
153
- }
154
- return cachedUint8ArrayMemory0;
155
- }
156
-
157
- function handleError(f, args) {
158
- try {
159
- return f.apply(this, args);
160
- } catch (e) {
161
- const idx = addToExternrefTable0(e);
162
- wasm.__wbindgen_exn_store(idx);
163
- }
164
- }
165
-
166
- function passArray32ToWasm0(arg, malloc) {
167
- const ptr = malloc(arg.length * 4, 4) >>> 0;
168
- getUint32ArrayMemory0().set(arg, ptr / 4);
169
- WASM_VECTOR_LEN = arg.length;
170
- return ptr;
171
- }
172
-
173
- function passArray8ToWasm0(arg, malloc) {
174
- const ptr = malloc(arg.length * 1, 1) >>> 0;
175
- getUint8ArrayMemory0().set(arg, ptr / 1);
176
- WASM_VECTOR_LEN = arg.length;
177
- return ptr;
178
- }
179
-
180
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
181
- cachedTextDecoder.decode();
182
- function decodeText(ptr, len) {
183
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
184
- }
185
-
186
- let WASM_VECTOR_LEN = 0;
187
-
188
- const wasmPath = `${__dirname}/pdf_tool_bg.wasm`;
189
- const wasmBytes = require('fs').readFileSync(wasmPath);
190
- const wasmModule = new WebAssembly.Module(wasmBytes);
191
- let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
192
- let wasm = wasmInstance.exports;
5
+ __wbg_set_wasm(wasm);
193
6
  wasm.__wbindgen_start();
7
+ export {
8
+ compress_pdf, decompress_pdf, get_info, merge_pdfs, optimize_pdf, split_pdf
9
+ } from "./pdf_tool_bg.js";