@veripublica/epubsana-wasm 0.4.0 → 0.6.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/epubsana_wasm.d.ts +0 -42
- package/epubsana_wasm.js +8 -381
- package/epubsana_wasm_bg.js +282 -0
- package/epubsana_wasm_bg.wasm +0 -0
- package/package.json +4 -3
- package/LICENSE-COMMERCIAL.md +0 -22
package/epubsana_wasm.d.ts
CHANGED
|
@@ -182,45 +182,3 @@ export class Session {
|
|
|
182
182
|
* `tool_version` print, git build metadata included.
|
|
183
183
|
*/
|
|
184
184
|
export function version(): string;
|
|
185
|
-
|
|
186
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
187
|
-
|
|
188
|
-
export interface InitOutput {
|
|
189
|
-
readonly memory: WebAssembly.Memory;
|
|
190
|
-
readonly __wbg_session_free: (a: number, b: number) => void;
|
|
191
|
-
readonly session_apply: (a: number, b: number) => [number, number];
|
|
192
|
-
readonly session_apply_auto_safe: (a: number) => number;
|
|
193
|
-
readonly session_load: (a: number, b: number) => [number, number, number];
|
|
194
|
-
readonly session_plan: (a: number) => any;
|
|
195
|
-
readonly session_report: (a: number, b: number, c: number) => [number, number, number];
|
|
196
|
-
readonly session_result_bytes: (a: number) => [number, number, number, number];
|
|
197
|
-
readonly version: () => [number, number];
|
|
198
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
199
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
200
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
201
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
202
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
203
|
-
readonly __wbindgen_start: () => void;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
210
|
-
* a precompiled `WebAssembly.Module`.
|
|
211
|
-
*
|
|
212
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
213
|
-
*
|
|
214
|
-
* @returns {InitOutput}
|
|
215
|
-
*/
|
|
216
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
220
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
221
|
-
*
|
|
222
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
223
|
-
*
|
|
224
|
-
* @returns {Promise<InitOutput>}
|
|
225
|
-
*/
|
|
226
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/epubsana_wasm.js
CHANGED
|
@@ -1,382 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./epubsana_wasm.d.ts" */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
SessionFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
11
|
-
return obj;
|
|
12
|
-
}
|
|
13
|
-
__destroy_into_raw() {
|
|
14
|
-
const ptr = this.__wbg_ptr;
|
|
15
|
-
this.__wbg_ptr = 0;
|
|
16
|
-
SessionFinalization.unregister(this);
|
|
17
|
-
return ptr;
|
|
18
|
-
}
|
|
19
|
-
free() {
|
|
20
|
-
const ptr = this.__destroy_into_raw();
|
|
21
|
-
wasm.__wbg_session_free(ptr, 0);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Apply the fix at `index` (a user-approved step). A no-op if that fix was
|
|
25
|
-
* already applied; an error only if `index` is out of range.
|
|
26
|
-
* @param {number} index
|
|
27
|
-
*/
|
|
28
|
-
apply(index) {
|
|
29
|
-
const ret = wasm.session_apply(this.__wbg_ptr, index);
|
|
30
|
-
if (ret[1]) {
|
|
31
|
-
throw takeFromExternrefTable0(ret[0]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Apply every provably-safe (`AutoSafe`) fix at once; returns how many were
|
|
36
|
-
* applied. The shortcut for "just fix what's unambiguously safe."
|
|
37
|
-
* @returns {number}
|
|
38
|
-
*/
|
|
39
|
-
apply_auto_safe() {
|
|
40
|
-
const ret = wasm.session_apply_auto_safe(this.__wbg_ptr);
|
|
41
|
-
return ret >>> 0;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
|
|
45
|
-
* @param {Uint8Array} bytes
|
|
46
|
-
* @returns {Session}
|
|
47
|
-
*/
|
|
48
|
-
static load(bytes) {
|
|
49
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
50
|
-
const len0 = WASM_VECTOR_LEN;
|
|
51
|
-
const ret = wasm.session_load(ptr0, len0);
|
|
52
|
-
if (ret[2]) {
|
|
53
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
54
|
-
}
|
|
55
|
-
return Session.__wrap(ret[0]);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The session's plan: the starting counts and every proposed fix (each with
|
|
59
|
-
* its current `outcome`). Cheap — it re-validates nothing.
|
|
60
|
-
* @returns {Plan}
|
|
61
|
-
*/
|
|
62
|
-
plan() {
|
|
63
|
-
const ret = wasm.session_plan(this.__wbg_ptr);
|
|
64
|
-
return ret;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* **Re-validate** the current (possibly repaired) EPUB with epubveri and
|
|
68
|
-
* return the result in the shared envelope shape — the same independent
|
|
69
|
-
* check the CLI reports. `goal` is `"valid"` (the default: no fatals and no
|
|
70
|
-
* errors remain) or `"openable"` (no fatals remain — the book opens).
|
|
71
|
-
* @param {string | null} [goal]
|
|
72
|
-
* @returns {Report}
|
|
73
|
-
*/
|
|
74
|
-
report(goal) {
|
|
75
|
-
var ptr0 = isLikeNone(goal) ? 0 : passStringToWasm0(goal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
76
|
-
var len0 = WASM_VECTOR_LEN;
|
|
77
|
-
const ret = wasm.session_report(this.__wbg_ptr, ptr0, len0);
|
|
78
|
-
if (ret[2]) {
|
|
79
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
80
|
-
}
|
|
81
|
-
return takeFromExternrefTable0(ret[0]);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
|
|
85
|
-
* @returns {Uint8Array}
|
|
86
|
-
*/
|
|
87
|
-
result_bytes() {
|
|
88
|
-
const ret = wasm.session_result_bytes(this.__wbg_ptr);
|
|
89
|
-
if (ret[3]) {
|
|
90
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
91
|
-
}
|
|
92
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
93
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
94
|
-
return v1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (Symbol.dispose) Session.prototype[Symbol.dispose] = Session.prototype.free;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The version string — the same one the CLI's `-V` and the json envelope's
|
|
101
|
-
* `tool_version` print, git build metadata included.
|
|
102
|
-
* @returns {string}
|
|
103
|
-
*/
|
|
104
|
-
export function version() {
|
|
105
|
-
let deferred1_0;
|
|
106
|
-
let deferred1_1;
|
|
107
|
-
try {
|
|
108
|
-
const ret = wasm.version();
|
|
109
|
-
deferred1_0 = ret[0];
|
|
110
|
-
deferred1_1 = ret[1];
|
|
111
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
112
|
-
} finally {
|
|
113
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function __wbg_get_imports() {
|
|
117
|
-
const import0 = {
|
|
118
|
-
__proto__: null,
|
|
119
|
-
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
120
|
-
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
121
|
-
return ret;
|
|
122
|
-
},
|
|
123
|
-
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
124
|
-
const ret = String(arg1);
|
|
125
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
126
|
-
const len1 = WASM_VECTOR_LEN;
|
|
127
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
128
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
129
|
-
},
|
|
130
|
-
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
131
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
132
|
-
},
|
|
133
|
-
__wbg_new_32b398fb48b6d94a: function() {
|
|
134
|
-
const ret = new Array();
|
|
135
|
-
return ret;
|
|
136
|
-
},
|
|
137
|
-
__wbg_new_da52cf8fe3429cb2: function() {
|
|
138
|
-
const ret = new Object();
|
|
139
|
-
return ret;
|
|
140
|
-
},
|
|
141
|
-
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
|
|
142
|
-
arg0[arg1] = arg2;
|
|
143
|
-
},
|
|
144
|
-
__wbg_set_8a16b38e4805b298: function(arg0, arg1, arg2) {
|
|
145
|
-
arg0[arg1 >>> 0] = arg2;
|
|
146
|
-
},
|
|
147
|
-
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
148
|
-
// Cast intrinsic for `F64 -> Externref`.
|
|
149
|
-
const ret = arg0;
|
|
150
|
-
return ret;
|
|
151
|
-
},
|
|
152
|
-
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
153
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
154
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
155
|
-
return ret;
|
|
156
|
-
},
|
|
157
|
-
__wbindgen_cast_0000000000000003: function(arg0) {
|
|
158
|
-
// Cast intrinsic for `U64 -> Externref`.
|
|
159
|
-
const ret = BigInt.asUintN(64, arg0);
|
|
160
|
-
return ret;
|
|
161
|
-
},
|
|
162
|
-
__wbindgen_init_externref_table: function() {
|
|
163
|
-
const table = wasm.__wbindgen_externrefs;
|
|
164
|
-
const offset = table.grow(4);
|
|
165
|
-
table.set(0, undefined);
|
|
166
|
-
table.set(offset + 0, undefined);
|
|
167
|
-
table.set(offset + 1, null);
|
|
168
|
-
table.set(offset + 2, true);
|
|
169
|
-
table.set(offset + 3, false);
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
return {
|
|
173
|
-
__proto__: null,
|
|
174
|
-
"./epubsana_wasm_bg.js": import0,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const SessionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
179
|
-
? { register: () => {}, unregister: () => {} }
|
|
180
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_session_free(ptr, 1));
|
|
181
|
-
|
|
182
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
183
|
-
ptr = ptr >>> 0;
|
|
184
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
let cachedDataViewMemory0 = null;
|
|
188
|
-
function getDataViewMemory0() {
|
|
189
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
190
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
191
|
-
}
|
|
192
|
-
return cachedDataViewMemory0;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function getStringFromWasm0(ptr, len) {
|
|
196
|
-
return decodeText(ptr >>> 0, len);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let cachedUint8ArrayMemory0 = null;
|
|
200
|
-
function getUint8ArrayMemory0() {
|
|
201
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
202
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
203
|
-
}
|
|
204
|
-
return cachedUint8ArrayMemory0;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function isLikeNone(x) {
|
|
208
|
-
return x === undefined || x === null;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
212
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
213
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
214
|
-
WASM_VECTOR_LEN = arg.length;
|
|
215
|
-
return ptr;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
219
|
-
if (realloc === undefined) {
|
|
220
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
221
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
222
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
223
|
-
WASM_VECTOR_LEN = buf.length;
|
|
224
|
-
return ptr;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
let len = arg.length;
|
|
228
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
229
|
-
|
|
230
|
-
const mem = getUint8ArrayMemory0();
|
|
231
|
-
|
|
232
|
-
let offset = 0;
|
|
233
|
-
|
|
234
|
-
for (; offset < len; offset++) {
|
|
235
|
-
const code = arg.charCodeAt(offset);
|
|
236
|
-
if (code > 0x7F) break;
|
|
237
|
-
mem[ptr + offset] = code;
|
|
238
|
-
}
|
|
239
|
-
if (offset !== len) {
|
|
240
|
-
if (offset !== 0) {
|
|
241
|
-
arg = arg.slice(offset);
|
|
242
|
-
}
|
|
243
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
244
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
245
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
246
|
-
|
|
247
|
-
offset += ret.written;
|
|
248
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
WASM_VECTOR_LEN = offset;
|
|
252
|
-
return ptr;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function takeFromExternrefTable0(idx) {
|
|
256
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
257
|
-
wasm.__externref_table_dealloc(idx);
|
|
258
|
-
return value;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
262
|
-
cachedTextDecoder.decode();
|
|
263
|
-
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
264
|
-
let numBytesDecoded = 0;
|
|
265
|
-
function decodeText(ptr, len) {
|
|
266
|
-
numBytesDecoded += len;
|
|
267
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
268
|
-
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
269
|
-
cachedTextDecoder.decode();
|
|
270
|
-
numBytesDecoded = len;
|
|
271
|
-
}
|
|
272
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const cachedTextEncoder = new TextEncoder();
|
|
276
|
-
|
|
277
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
278
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
279
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
280
|
-
view.set(buf);
|
|
281
|
-
return {
|
|
282
|
-
read: arg.length,
|
|
283
|
-
written: buf.length
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
let WASM_VECTOR_LEN = 0;
|
|
289
|
-
|
|
290
|
-
let wasmModule, wasmInstance, wasm;
|
|
291
|
-
function __wbg_finalize_init(instance, module) {
|
|
292
|
-
wasmInstance = instance;
|
|
293
|
-
wasm = instance.exports;
|
|
294
|
-
wasmModule = module;
|
|
295
|
-
cachedDataViewMemory0 = null;
|
|
296
|
-
cachedUint8ArrayMemory0 = null;
|
|
297
|
-
wasm.__wbindgen_start();
|
|
298
|
-
return wasm;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
async function __wbg_load(module, imports) {
|
|
302
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
303
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
304
|
-
try {
|
|
305
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
306
|
-
} catch (e) {
|
|
307
|
-
const validResponse = module.ok && expectedResponseType(module.type);
|
|
308
|
-
|
|
309
|
-
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
310
|
-
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);
|
|
311
|
-
|
|
312
|
-
} else { throw e; }
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const bytes = await module.arrayBuffer();
|
|
317
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
318
|
-
} else {
|
|
319
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
320
|
-
|
|
321
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
322
|
-
return { instance, module };
|
|
323
|
-
} else {
|
|
324
|
-
return instance;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function expectedResponseType(type) {
|
|
329
|
-
switch (type) {
|
|
330
|
-
case 'basic': case 'cors': case 'default': return true;
|
|
331
|
-
}
|
|
332
|
-
return false;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function initSync(module) {
|
|
337
|
-
if (wasm !== undefined) return wasm;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (module !== undefined) {
|
|
341
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
342
|
-
({module} = module)
|
|
343
|
-
} else {
|
|
344
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const imports = __wbg_get_imports();
|
|
349
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
350
|
-
module = new WebAssembly.Module(module);
|
|
351
|
-
}
|
|
352
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
353
|
-
return __wbg_finalize_init(instance, module);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
async function __wbg_init(module_or_path) {
|
|
357
|
-
if (wasm !== undefined) return wasm;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (module_or_path !== undefined) {
|
|
361
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
362
|
-
({module_or_path} = module_or_path)
|
|
363
|
-
} else {
|
|
364
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
if (module_or_path === undefined) {
|
|
369
|
-
module_or_path = new URL('epubsana_wasm_bg.wasm', import.meta.url);
|
|
370
|
-
}
|
|
371
|
-
const imports = __wbg_get_imports();
|
|
372
|
-
|
|
373
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
374
|
-
module_or_path = fetch(module_or_path);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
378
|
-
|
|
379
|
-
return __wbg_finalize_init(instance, module);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export { initSync, __wbg_init as default };
|
|
2
|
+
import * as wasm from "./epubsana_wasm_bg.wasm";
|
|
3
|
+
import { __wbg_set_wasm } from "./epubsana_wasm_bg.js";
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
Session, version
|
|
9
|
+
} from "./epubsana_wasm_bg.js";
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A repair session over one EPUB, held in WASM memory across calls.
|
|
3
|
+
*/
|
|
4
|
+
export class Session {
|
|
5
|
+
static __wrap(ptr) {
|
|
6
|
+
const obj = Object.create(Session.prototype);
|
|
7
|
+
obj.__wbg_ptr = ptr;
|
|
8
|
+
SessionFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
__destroy_into_raw() {
|
|
12
|
+
const ptr = this.__wbg_ptr;
|
|
13
|
+
this.__wbg_ptr = 0;
|
|
14
|
+
SessionFinalization.unregister(this);
|
|
15
|
+
return ptr;
|
|
16
|
+
}
|
|
17
|
+
free() {
|
|
18
|
+
const ptr = this.__destroy_into_raw();
|
|
19
|
+
wasm.__wbg_session_free(ptr, 0);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Apply the fix at `index` (a user-approved step). A no-op if that fix was
|
|
23
|
+
* already applied; an error only if `index` is out of range.
|
|
24
|
+
* @param {number} index
|
|
25
|
+
*/
|
|
26
|
+
apply(index) {
|
|
27
|
+
const ret = wasm.session_apply(this.__wbg_ptr, index);
|
|
28
|
+
if (ret[1]) {
|
|
29
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Apply every provably-safe (`AutoSafe`) fix at once; returns how many were
|
|
34
|
+
* applied. The shortcut for "just fix what's unambiguously safe."
|
|
35
|
+
* @returns {number}
|
|
36
|
+
*/
|
|
37
|
+
apply_auto_safe() {
|
|
38
|
+
const ret = wasm.session_apply_auto_safe(this.__wbg_ptr);
|
|
39
|
+
return ret >>> 0;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Load an EPUB from its raw bytes, detect its defects, and plan the fixes.
|
|
43
|
+
* @param {Uint8Array} bytes
|
|
44
|
+
* @returns {Session}
|
|
45
|
+
*/
|
|
46
|
+
static load(bytes) {
|
|
47
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
48
|
+
const len0 = WASM_VECTOR_LEN;
|
|
49
|
+
const ret = wasm.session_load(ptr0, len0);
|
|
50
|
+
if (ret[2]) {
|
|
51
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
52
|
+
}
|
|
53
|
+
return Session.__wrap(ret[0]);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The session's plan: the starting counts and every proposed fix (each with
|
|
57
|
+
* its current `outcome`). Cheap — it re-validates nothing.
|
|
58
|
+
* @returns {Plan}
|
|
59
|
+
*/
|
|
60
|
+
plan() {
|
|
61
|
+
const ret = wasm.session_plan(this.__wbg_ptr);
|
|
62
|
+
return ret;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* **Re-validate** the current (possibly repaired) EPUB with epubveri and
|
|
66
|
+
* return the result in the shared envelope shape — the same independent
|
|
67
|
+
* check the CLI reports. `goal` is `"valid"` (the default: no fatals and no
|
|
68
|
+
* errors remain) or `"openable"` (no fatals remain — the book opens).
|
|
69
|
+
* @param {string | null} [goal]
|
|
70
|
+
* @returns {Report}
|
|
71
|
+
*/
|
|
72
|
+
report(goal) {
|
|
73
|
+
var ptr0 = isLikeNone(goal) ? 0 : passStringToWasm0(goal, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
74
|
+
var len0 = WASM_VECTOR_LEN;
|
|
75
|
+
const ret = wasm.session_report(this.__wbg_ptr, ptr0, len0);
|
|
76
|
+
if (ret[2]) {
|
|
77
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
78
|
+
}
|
|
79
|
+
return takeFromExternrefTable0(ret[0]);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The repaired EPUB's bytes — download these as `<name>_fixed.epub`.
|
|
83
|
+
* @returns {Uint8Array}
|
|
84
|
+
*/
|
|
85
|
+
result_bytes() {
|
|
86
|
+
const ret = wasm.session_result_bytes(this.__wbg_ptr);
|
|
87
|
+
if (ret[3]) {
|
|
88
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
89
|
+
}
|
|
90
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
91
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
92
|
+
return v1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Symbol.dispose) Session.prototype[Symbol.dispose] = Session.prototype.free;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The version string — the same one the CLI's `-V` and the json envelope's
|
|
99
|
+
* `tool_version` print, git build metadata included.
|
|
100
|
+
* @returns {string}
|
|
101
|
+
*/
|
|
102
|
+
export function version() {
|
|
103
|
+
let deferred1_0;
|
|
104
|
+
let deferred1_1;
|
|
105
|
+
try {
|
|
106
|
+
const ret = wasm.version();
|
|
107
|
+
deferred1_0 = ret[0];
|
|
108
|
+
deferred1_1 = ret[1];
|
|
109
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
110
|
+
} finally {
|
|
111
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function __wbg_Error_92b29b0548f8b746(arg0, arg1) {
|
|
115
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
116
|
+
return ret;
|
|
117
|
+
}
|
|
118
|
+
export function __wbg_String_8564e559799eccda(arg0, arg1) {
|
|
119
|
+
const ret = String(arg1);
|
|
120
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
121
|
+
const len1 = WASM_VECTOR_LEN;
|
|
122
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
123
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
124
|
+
}
|
|
125
|
+
export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
|
|
126
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
127
|
+
}
|
|
128
|
+
export function __wbg_new_32b398fb48b6d94a() {
|
|
129
|
+
const ret = new Array();
|
|
130
|
+
return ret;
|
|
131
|
+
}
|
|
132
|
+
export function __wbg_new_da52cf8fe3429cb2() {
|
|
133
|
+
const ret = new Object();
|
|
134
|
+
return ret;
|
|
135
|
+
}
|
|
136
|
+
export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
|
|
137
|
+
arg0[arg1] = arg2;
|
|
138
|
+
}
|
|
139
|
+
export function __wbg_set_8a16b38e4805b298(arg0, arg1, arg2) {
|
|
140
|
+
arg0[arg1 >>> 0] = arg2;
|
|
141
|
+
}
|
|
142
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
143
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
144
|
+
const ret = arg0;
|
|
145
|
+
return ret;
|
|
146
|
+
}
|
|
147
|
+
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
148
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
149
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
150
|
+
return ret;
|
|
151
|
+
}
|
|
152
|
+
export function __wbindgen_cast_0000000000000003(arg0) {
|
|
153
|
+
// Cast intrinsic for `U64 -> Externref`.
|
|
154
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
export function __wbindgen_init_externref_table() {
|
|
158
|
+
const table = wasm.__wbindgen_externrefs;
|
|
159
|
+
const offset = table.grow(4);
|
|
160
|
+
table.set(0, undefined);
|
|
161
|
+
table.set(offset + 0, undefined);
|
|
162
|
+
table.set(offset + 1, null);
|
|
163
|
+
table.set(offset + 2, true);
|
|
164
|
+
table.set(offset + 3, false);
|
|
165
|
+
}
|
|
166
|
+
const SessionFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
167
|
+
? { register: () => {}, unregister: () => {} }
|
|
168
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_session_free(ptr, 1));
|
|
169
|
+
|
|
170
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
171
|
+
ptr = ptr >>> 0;
|
|
172
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let cachedDataViewMemory0 = null;
|
|
176
|
+
function getDataViewMemory0() {
|
|
177
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
178
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
179
|
+
}
|
|
180
|
+
return cachedDataViewMemory0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function getStringFromWasm0(ptr, len) {
|
|
184
|
+
return decodeText(ptr >>> 0, len);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let cachedUint8ArrayMemory0 = null;
|
|
188
|
+
function getUint8ArrayMemory0() {
|
|
189
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
190
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
191
|
+
}
|
|
192
|
+
return cachedUint8ArrayMemory0;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function isLikeNone(x) {
|
|
196
|
+
return x === undefined || x === null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
200
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
201
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
202
|
+
WASM_VECTOR_LEN = arg.length;
|
|
203
|
+
return ptr;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
207
|
+
if (realloc === undefined) {
|
|
208
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
209
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
210
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
211
|
+
WASM_VECTOR_LEN = buf.length;
|
|
212
|
+
return ptr;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let len = arg.length;
|
|
216
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
217
|
+
|
|
218
|
+
const mem = getUint8ArrayMemory0();
|
|
219
|
+
|
|
220
|
+
let offset = 0;
|
|
221
|
+
|
|
222
|
+
for (; offset < len; offset++) {
|
|
223
|
+
const code = arg.charCodeAt(offset);
|
|
224
|
+
if (code > 0x7F) break;
|
|
225
|
+
mem[ptr + offset] = code;
|
|
226
|
+
}
|
|
227
|
+
if (offset !== len) {
|
|
228
|
+
if (offset !== 0) {
|
|
229
|
+
arg = arg.slice(offset);
|
|
230
|
+
}
|
|
231
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
232
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
233
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
234
|
+
|
|
235
|
+
offset += ret.written;
|
|
236
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
WASM_VECTOR_LEN = offset;
|
|
240
|
+
return ptr;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function takeFromExternrefTable0(idx) {
|
|
244
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
245
|
+
wasm.__externref_table_dealloc(idx);
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
250
|
+
cachedTextDecoder.decode();
|
|
251
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
252
|
+
let numBytesDecoded = 0;
|
|
253
|
+
function decodeText(ptr, len) {
|
|
254
|
+
numBytesDecoded += len;
|
|
255
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
256
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
257
|
+
cachedTextDecoder.decode();
|
|
258
|
+
numBytesDecoded = len;
|
|
259
|
+
}
|
|
260
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const cachedTextEncoder = new TextEncoder();
|
|
264
|
+
|
|
265
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
266
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
267
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
268
|
+
view.set(buf);
|
|
269
|
+
return {
|
|
270
|
+
read: arg.length,
|
|
271
|
+
written: buf.length
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
let WASM_VECTOR_LEN = 0;
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
let wasm;
|
|
280
|
+
export function __wbg_set_wasm(val) {
|
|
281
|
+
wasm = val;
|
|
282
|
+
}
|
package/epubsana_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@veripublica/epubsana-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly bindings for epubsana — repair EPUB defects in the browser, no upload.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.6.0",
|
|
6
6
|
"license": "AGPL-3.0-only OR LicenseRef-veripublica-Commercial",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"epubsana_wasm_bg.wasm",
|
|
13
13
|
"epubsana_wasm.js",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"epubsana_wasm_bg.js",
|
|
15
|
+
"epubsana_wasm.d.ts"
|
|
16
16
|
],
|
|
17
17
|
"main": "epubsana_wasm.js",
|
|
18
18
|
"homepage": "https://github.com/veripublica/epubsana",
|
|
19
19
|
"types": "epubsana_wasm.d.ts",
|
|
20
20
|
"sideEffects": [
|
|
21
|
+
"./epubsana_wasm.js",
|
|
21
22
|
"./snippets/*"
|
|
22
23
|
],
|
|
23
24
|
"keywords": [
|
package/LICENSE-COMMERCIAL.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Commercial Licensing
|
|
2
|
-
|
|
3
|
-
`epubsana` is dual-licensed:
|
|
4
|
-
|
|
5
|
-
- **AGPL-3.0-only** (see [`LICENSE`](./LICENSE)) — free to use, including in
|
|
6
|
-
commercial products, as long as your product also complies with the AGPL
|
|
7
|
-
(in particular, the network-use clause: if you offer this software's
|
|
8
|
-
functionality over a network, you must make your complete corresponding
|
|
9
|
-
source available to users of that service).
|
|
10
|
-
- **Commercial license** (`LicenseRef-veripublica-Commercial`) — for
|
|
11
|
-
organizations that want to embed `epubsana` in a closed-source or
|
|
12
|
-
proprietary product without AGPL's copyleft/source-disclosure obligations.
|
|
13
|
-
|
|
14
|
-
If the AGPL doesn't work for your use case (e.g. you're shipping `epubsana`
|
|
15
|
-
inside a closed-source e-reader, retailer ingestion pipeline, or SaaS product
|
|
16
|
-
you don't want to open-source), contact the copyright holder for commercial
|
|
17
|
-
licensing terms:
|
|
18
|
-
|
|
19
|
-
**Baris Kayadelen** — baris@kayadelen.com
|
|
20
|
-
|
|
21
|
-
This document is a summary, not a license grant. Commercial terms are
|
|
22
|
-
negotiated and granted separately in writing.
|