@jacktea/pdf-viewer-core 0.1.6 → 0.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacktea/pdf-viewer-core",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "typescript": "^5.5.4"
23
23
  },
24
24
  "scripts": {
25
- "build": "tsup src/index.ts --format esm --dts --minify --clean && mkdir -p dist/pdf-tools && cp -r src/pdf-tools/pkg dist/pdf-tools/pkg",
25
+ "build": "tsup src/index.ts --format esm --dts --minify --clean && cp src/pdf-tools/pkg/pdf_tools_bg.wasm dist/",
26
26
  "typecheck": "tsc -p tsconfig.json --noEmit"
27
27
  }
28
28
  }
@@ -1,17 +0,0 @@
1
- {
2
- "name": "pdf-tools",
3
- "type": "module",
4
- "description": "PDF manipulation tools with WASM support for pdf-viewer",
5
- "version": "0.1.0",
6
- "license": "MIT",
7
- "files": [
8
- "pdf_tools_bg.wasm",
9
- "pdf_tools.js",
10
- "pdf_tools.d.ts"
11
- ],
12
- "main": "pdf_tools.js",
13
- "types": "pdf_tools.d.ts",
14
- "sideEffects": [
15
- "./snippets/*"
16
- ]
17
- }
@@ -1,74 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
-
4
- /**
5
- * Embed watermark (Text or Image) into PDF
6
- *
7
- * config_json examples:
8
- * Text: {"type": "text", "content": "Hello", "opacity": 0.5, ...}
9
- * Image: {"type": "image", "imageDataBase64": "...", ...}
10
- */
11
- export function embed_watermark_wasm(pdf_bytes: Uint8Array, config_json: string): Uint8Array;
12
-
13
- /**
14
- * Extract specific pages from PDF
15
- * page_indices should be a Uint32Array from JS side
16
- */
17
- export function extract_pages_wasm(pdf_bytes: Uint8Array, page_indices: Uint32Array): Uint8Array;
18
-
19
- /**
20
- * Get number of pages in PDF
21
- */
22
- export function get_page_count_wasm(pdf_bytes: Uint8Array): number;
23
-
24
- export function init(): void;
25
-
26
- /**
27
- * Read PdfData JSON from PDF bytes
28
- */
29
- export function read_pdf_data_wasm(pdf_bytes: Uint8Array): any;
30
-
31
- /**
32
- * Write PdfData JSON to PDF bytes
33
- */
34
- export function write_pdf_data_wasm(pdf_bytes: Uint8Array, json_data: string): Uint8Array;
35
-
36
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
37
-
38
- export interface InitOutput {
39
- readonly memory: WebAssembly.Memory;
40
- readonly embed_watermark_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
41
- readonly extract_pages_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
42
- readonly get_page_count_wasm: (a: number, b: number) => [number, number, number];
43
- readonly init: () => void;
44
- readonly read_pdf_data_wasm: (a: number, b: number) => [number, number, number];
45
- readonly write_pdf_data_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
46
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
47
- readonly __wbindgen_malloc: (a: number, b: number) => number;
48
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
49
- readonly __wbindgen_externrefs: WebAssembly.Table;
50
- readonly __externref_table_dealloc: (a: number) => void;
51
- readonly __wbindgen_start: () => void;
52
- }
53
-
54
- export type SyncInitInput = BufferSource | WebAssembly.Module;
55
-
56
- /**
57
- * Instantiates the given `module`, which can either be bytes or
58
- * a precompiled `WebAssembly.Module`.
59
- *
60
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
61
- *
62
- * @returns {InitOutput}
63
- */
64
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
65
-
66
- /**
67
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
68
- * for everything else, calls `WebAssembly.instantiate` directly.
69
- *
70
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
71
- *
72
- * @returns {Promise<InitOutput>}
73
- */
74
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,366 +0,0 @@
1
- /* @ts-self-types="./pdf_tools.d.ts" */
2
-
3
- /**
4
- * Embed watermark (Text or Image) into PDF
5
- *
6
- * config_json examples:
7
- * Text: {"type": "text", "content": "Hello", "opacity": 0.5, ...}
8
- * Image: {"type": "image", "imageDataBase64": "...", ...}
9
- * @param {Uint8Array} pdf_bytes
10
- * @param {string} config_json
11
- * @returns {Uint8Array}
12
- */
13
- export function embed_watermark_wasm(pdf_bytes, config_json) {
14
- const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
15
- const len0 = WASM_VECTOR_LEN;
16
- const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
17
- const len1 = WASM_VECTOR_LEN;
18
- const ret = wasm.embed_watermark_wasm(ptr0, len0, ptr1, len1);
19
- if (ret[3]) {
20
- throw takeFromExternrefTable0(ret[2]);
21
- }
22
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
23
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
24
- return v3;
25
- }
26
-
27
- /**
28
- * Extract specific pages from PDF
29
- * page_indices should be a Uint32Array from JS side
30
- * @param {Uint8Array} pdf_bytes
31
- * @param {Uint32Array} page_indices
32
- * @returns {Uint8Array}
33
- */
34
- export function extract_pages_wasm(pdf_bytes, page_indices) {
35
- const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
36
- const len0 = WASM_VECTOR_LEN;
37
- const ptr1 = passArray32ToWasm0(page_indices, wasm.__wbindgen_malloc);
38
- const len1 = WASM_VECTOR_LEN;
39
- const ret = wasm.extract_pages_wasm(ptr0, len0, ptr1, len1);
40
- if (ret[3]) {
41
- throw takeFromExternrefTable0(ret[2]);
42
- }
43
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
44
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
45
- return v3;
46
- }
47
-
48
- /**
49
- * Get number of pages in PDF
50
- * @param {Uint8Array} pdf_bytes
51
- * @returns {number}
52
- */
53
- export function get_page_count_wasm(pdf_bytes) {
54
- const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
55
- const len0 = WASM_VECTOR_LEN;
56
- const ret = wasm.get_page_count_wasm(ptr0, len0);
57
- if (ret[2]) {
58
- throw takeFromExternrefTable0(ret[1]);
59
- }
60
- return ret[0] >>> 0;
61
- }
62
-
63
- export function init() {
64
- wasm.init();
65
- }
66
-
67
- /**
68
- * Read PdfData JSON from PDF bytes
69
- * @param {Uint8Array} pdf_bytes
70
- * @returns {any}
71
- */
72
- export function read_pdf_data_wasm(pdf_bytes) {
73
- const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
74
- const len0 = WASM_VECTOR_LEN;
75
- const ret = wasm.read_pdf_data_wasm(ptr0, len0);
76
- if (ret[2]) {
77
- throw takeFromExternrefTable0(ret[1]);
78
- }
79
- return takeFromExternrefTable0(ret[0]);
80
- }
81
-
82
- /**
83
- * Write PdfData JSON to PDF bytes
84
- * @param {Uint8Array} pdf_bytes
85
- * @param {string} json_data
86
- * @returns {Uint8Array}
87
- */
88
- export function write_pdf_data_wasm(pdf_bytes, json_data) {
89
- const ptr0 = passArray8ToWasm0(pdf_bytes, wasm.__wbindgen_malloc);
90
- const len0 = WASM_VECTOR_LEN;
91
- const ptr1 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
- const len1 = WASM_VECTOR_LEN;
93
- const ret = wasm.write_pdf_data_wasm(ptr0, len0, ptr1, len1);
94
- if (ret[3]) {
95
- throw takeFromExternrefTable0(ret[2]);
96
- }
97
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
98
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
99
- return v3;
100
- }
101
-
102
- function __wbg_get_imports() {
103
- const import0 = {
104
- __proto__: null,
105
- __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
106
- throw new Error(getStringFromWasm0(arg0, arg1));
107
- },
108
- __wbg_error_7534b8e9a36f1ab4: function(arg0, arg1) {
109
- let deferred0_0;
110
- let deferred0_1;
111
- try {
112
- deferred0_0 = arg0;
113
- deferred0_1 = arg1;
114
- console.error(getStringFromWasm0(arg0, arg1));
115
- } finally {
116
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
117
- }
118
- },
119
- __wbg_log_6b5ca2e6124b2808: function(arg0) {
120
- console.log(arg0);
121
- },
122
- __wbg_new_8a6f238a6ece86ea: function() {
123
- const ret = new Error();
124
- return ret;
125
- },
126
- __wbg_stack_0ed75d68575b0f3c: function(arg0, arg1) {
127
- const ret = arg1.stack;
128
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
129
- const len1 = WASM_VECTOR_LEN;
130
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
131
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
132
- },
133
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
134
- // Cast intrinsic for `Ref(String) -> Externref`.
135
- const ret = getStringFromWasm0(arg0, arg1);
136
- return ret;
137
- },
138
- __wbindgen_init_externref_table: function() {
139
- const table = wasm.__wbindgen_externrefs;
140
- const offset = table.grow(4);
141
- table.set(0, undefined);
142
- table.set(offset + 0, undefined);
143
- table.set(offset + 1, null);
144
- table.set(offset + 2, true);
145
- table.set(offset + 3, false);
146
- },
147
- };
148
- return {
149
- __proto__: null,
150
- "./pdf_tools_bg.js": import0,
151
- };
152
- }
153
-
154
- function getArrayU8FromWasm0(ptr, len) {
155
- ptr = ptr >>> 0;
156
- return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
157
- }
158
-
159
- let cachedDataViewMemory0 = null;
160
- function getDataViewMemory0() {
161
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
162
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
163
- }
164
- return cachedDataViewMemory0;
165
- }
166
-
167
- function getStringFromWasm0(ptr, len) {
168
- ptr = ptr >>> 0;
169
- return decodeText(ptr, len);
170
- }
171
-
172
- let cachedUint32ArrayMemory0 = null;
173
- function getUint32ArrayMemory0() {
174
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
175
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
176
- }
177
- return cachedUint32ArrayMemory0;
178
- }
179
-
180
- let cachedUint8ArrayMemory0 = null;
181
- function getUint8ArrayMemory0() {
182
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
183
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
184
- }
185
- return cachedUint8ArrayMemory0;
186
- }
187
-
188
- function passArray32ToWasm0(arg, malloc) {
189
- const ptr = malloc(arg.length * 4, 4) >>> 0;
190
- getUint32ArrayMemory0().set(arg, ptr / 4);
191
- WASM_VECTOR_LEN = arg.length;
192
- return ptr;
193
- }
194
-
195
- function passArray8ToWasm0(arg, malloc) {
196
- const ptr = malloc(arg.length * 1, 1) >>> 0;
197
- getUint8ArrayMemory0().set(arg, ptr / 1);
198
- WASM_VECTOR_LEN = arg.length;
199
- return ptr;
200
- }
201
-
202
- function passStringToWasm0(arg, malloc, realloc) {
203
- if (realloc === undefined) {
204
- const buf = cachedTextEncoder.encode(arg);
205
- const ptr = malloc(buf.length, 1) >>> 0;
206
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
207
- WASM_VECTOR_LEN = buf.length;
208
- return ptr;
209
- }
210
-
211
- let len = arg.length;
212
- let ptr = malloc(len, 1) >>> 0;
213
-
214
- const mem = getUint8ArrayMemory0();
215
-
216
- let offset = 0;
217
-
218
- for (; offset < len; offset++) {
219
- const code = arg.charCodeAt(offset);
220
- if (code > 0x7F) break;
221
- mem[ptr + offset] = code;
222
- }
223
- if (offset !== len) {
224
- if (offset !== 0) {
225
- arg = arg.slice(offset);
226
- }
227
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
228
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
229
- const ret = cachedTextEncoder.encodeInto(arg, view);
230
-
231
- offset += ret.written;
232
- ptr = realloc(ptr, len, offset, 1) >>> 0;
233
- }
234
-
235
- WASM_VECTOR_LEN = offset;
236
- return ptr;
237
- }
238
-
239
- function takeFromExternrefTable0(idx) {
240
- const value = wasm.__wbindgen_externrefs.get(idx);
241
- wasm.__externref_table_dealloc(idx);
242
- return value;
243
- }
244
-
245
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
246
- cachedTextDecoder.decode();
247
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
248
- let numBytesDecoded = 0;
249
- function decodeText(ptr, len) {
250
- numBytesDecoded += len;
251
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
252
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
253
- cachedTextDecoder.decode();
254
- numBytesDecoded = len;
255
- }
256
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
257
- }
258
-
259
- const cachedTextEncoder = new TextEncoder();
260
-
261
- if (!('encodeInto' in cachedTextEncoder)) {
262
- cachedTextEncoder.encodeInto = function (arg, view) {
263
- const buf = cachedTextEncoder.encode(arg);
264
- view.set(buf);
265
- return {
266
- read: arg.length,
267
- written: buf.length
268
- };
269
- };
270
- }
271
-
272
- let WASM_VECTOR_LEN = 0;
273
-
274
- let wasmModule, wasm;
275
- function __wbg_finalize_init(instance, module) {
276
- wasm = instance.exports;
277
- wasmModule = module;
278
- cachedDataViewMemory0 = null;
279
- cachedUint32ArrayMemory0 = null;
280
- cachedUint8ArrayMemory0 = null;
281
- wasm.__wbindgen_start();
282
- return wasm;
283
- }
284
-
285
- async function __wbg_load(module, imports) {
286
- if (typeof Response === 'function' && module instanceof Response) {
287
- if (typeof WebAssembly.instantiateStreaming === 'function') {
288
- try {
289
- return await WebAssembly.instantiateStreaming(module, imports);
290
- } catch (e) {
291
- const validResponse = module.ok && expectedResponseType(module.type);
292
-
293
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
294
- console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
295
-
296
- } else { throw e; }
297
- }
298
- }
299
-
300
- const bytes = await module.arrayBuffer();
301
- return await WebAssembly.instantiate(bytes, imports);
302
- } else {
303
- const instance = await WebAssembly.instantiate(module, imports);
304
-
305
- if (instance instanceof WebAssembly.Instance) {
306
- return { instance, module };
307
- } else {
308
- return instance;
309
- }
310
- }
311
-
312
- function expectedResponseType(type) {
313
- switch (type) {
314
- case 'basic': case 'cors': case 'default': return true;
315
- }
316
- return false;
317
- }
318
- }
319
-
320
- function initSync(module) {
321
- if (wasm !== undefined) return wasm;
322
-
323
-
324
- if (module !== undefined) {
325
- if (Object.getPrototypeOf(module) === Object.prototype) {
326
- ({module} = module)
327
- } else {
328
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
329
- }
330
- }
331
-
332
- const imports = __wbg_get_imports();
333
- if (!(module instanceof WebAssembly.Module)) {
334
- module = new WebAssembly.Module(module);
335
- }
336
- const instance = new WebAssembly.Instance(module, imports);
337
- return __wbg_finalize_init(instance, module);
338
- }
339
-
340
- async function __wbg_init(module_or_path) {
341
- if (wasm !== undefined) return wasm;
342
-
343
-
344
- if (module_or_path !== undefined) {
345
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
346
- ({module_or_path} = module_or_path)
347
- } else {
348
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
349
- }
350
- }
351
-
352
- if (module_or_path === undefined) {
353
- module_or_path = new URL('pdf_tools_bg.wasm', import.meta.url);
354
- }
355
- const imports = __wbg_get_imports();
356
-
357
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
358
- module_or_path = fetch(module_or_path);
359
- }
360
-
361
- const { instance, module } = await __wbg_load(await module_or_path, imports);
362
-
363
- return __wbg_finalize_init(instance, module);
364
- }
365
-
366
- export { initSync, __wbg_init as default };
@@ -1,15 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- export const memory: WebAssembly.Memory;
4
- export const embed_watermark_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
- export const extract_pages_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
6
- export const get_page_count_wasm: (a: number, b: number) => [number, number, number];
7
- export const init: () => void;
8
- export const read_pdf_data_wasm: (a: number, b: number) => [number, number, number];
9
- export const write_pdf_data_wasm: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
11
- export const __wbindgen_malloc: (a: number, b: number) => number;
12
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
- export const __wbindgen_externrefs: WebAssembly.Table;
14
- export const __externref_table_dealloc: (a: number) => void;
15
- export const __wbindgen_start: () => void;