docxodus 12.6.4 → 13.0.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/README.md +8 -5
- package/dist/canonical.d.ts.map +1 -1
- package/dist/canonical.js +7 -3
- package/dist/canonical.js.map +1 -1
- package/dist/conversion-options.d.ts +16 -0
- package/dist/conversion-options.d.ts.map +1 -0
- package/dist/conversion-options.js +31 -0
- package/dist/conversion-options.js.map +1 -0
- package/dist/core.d.ts +17 -9
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +23 -24
- package/dist/core.js.map +1 -1
- package/dist/docxodus.worker.js +2 -1073
- package/dist/docxodus.worker.js.map +7 -1
- package/dist/editor.bundle.js +35 -14296
- package/dist/editor.bundle.js.map +7 -0
- package/dist/editor.d.ts +33 -2
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +6739 -4773
- package/dist/editor.js.map +7 -1
- package/dist/embed.bundle.js +159 -18703
- package/dist/embed.bundle.js.map +7 -0
- package/dist/embed.d.ts +1 -1
- package/dist/embed.iife.js +37 -18595
- package/dist/embed.iife.js.map +7 -0
- package/dist/embed.js +1 -1
- package/dist/export-assets.json +27 -27
- package/dist/export-browser.bundle.js +1388 -477
- package/dist/export-browser.d.ts +20 -0
- package/dist/export-browser.d.ts.map +1 -1
- package/dist/export-browser.js +132 -37
- package/dist/export-browser.js.map +1 -1
- package/dist/font-runtime.d.ts.map +1 -1
- package/dist/font-runtime.js +54 -0
- package/dist/font-runtime.js.map +1 -1
- package/dist/line-metrics.d.ts +60 -0
- package/dist/line-metrics.d.ts.map +1 -0
- package/dist/line-metrics.js +343 -0
- package/dist/line-metrics.js.map +1 -0
- package/dist/pagination.bundle.js +3 -3214
- package/dist/pagination.bundle.js.map +7 -0
- package/dist/pagination.d.ts +86 -9
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +358 -55
- package/dist/pagination.js.map +1 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +63 -12
- package/dist/react.js.map +1 -1
- package/dist/render-report-v2.schema.json +29 -0
- package/dist/session.bundle.js +2 -2013
- package/dist/session.bundle.js.map +7 -0
- package/dist/session.d.ts +14 -5
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +62 -29
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +137 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -1
- package/dist/wasm/_framework/Docxodus.wasm +0 -0
- package/dist/wasm/_framework/Docxodus.wasm.br +0 -0
- package/dist/wasm/_framework/DocxodusWasm.wasm +0 -0
- package/dist/wasm/_framework/DocxodusWasm.wasm.br +0 -0
- package/dist/wasm/_framework/System.Collections.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.wasm.br +0 -0
- package/dist/wasm/_framework/System.IO.Compression.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.wasm.br +0 -0
- package/dist/wasm/_framework/System.Linq.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.wasm.br +0 -0
- package/dist/wasm/_framework/System.Memory.wasm +0 -0
- package/dist/wasm/_framework/System.Memory.wasm.br +0 -0
- package/dist/wasm/_framework/System.Private.CoreLib.wasm +0 -0
- package/dist/wasm/_framework/System.Private.CoreLib.wasm.br +0 -0
- package/dist/wasm/_framework/System.Private.Xml.Linq.wasm +0 -0
- package/dist/wasm/_framework/System.Private.Xml.Linq.wasm.br +0 -0
- package/dist/wasm/_framework/System.Text.RegularExpressions.wasm +0 -0
- package/dist/wasm/_framework/System.Text.RegularExpressions.wasm.br +0 -0
- package/dist/wasm/_framework/dotnet.boot.js +11 -11
- package/dist/wasm/_framework/dotnet.boot.js.br +0 -0
- package/dist/wasm/_framework/dotnet.native.wasm +0 -0
- package/dist/wasm/_framework/dotnet.native.wasm.br +0 -0
- package/dist/word-text.d.ts +14 -0
- package/dist/word-text.d.ts.map +1 -0
- package/dist/word-text.js +377 -0
- package/dist/word-text.js.map +1 -0
- package/dist/worker-proxy.bundle.js +2 -536
- package/dist/worker-proxy.bundle.js.map +7 -0
- package/dist/worker-proxy.d.ts +14 -1
- package/dist/worker-proxy.d.ts.map +1 -1
- package/dist/worker-proxy.js +357 -339
- package/dist/worker-proxy.js.map +1 -1
- package/package.json +13 -12
|
@@ -1,536 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (request === null || typeof request !== "object" || Array.isArray(request)) {
|
|
4
|
-
throw new RangeError("a verification request must be an object");
|
|
5
|
-
}
|
|
6
|
-
const { companionArtifacts, ...rest } = request;
|
|
7
|
-
const wire = { ...rest };
|
|
8
|
-
if (companionArtifacts !== void 0) {
|
|
9
|
-
wire.companionArtifacts = companionArtifacts.map(encodeCompanion);
|
|
10
|
-
}
|
|
11
|
-
return JSON.stringify(wire);
|
|
12
|
-
}
|
|
13
|
-
function encodeCompanion(artifact) {
|
|
14
|
-
const { bytes, ...rest } = artifact;
|
|
15
|
-
const wire = { ...rest };
|
|
16
|
-
if (bytes !== void 0) wire.bytesB64 = bytesToBase64(bytes);
|
|
17
|
-
return wire;
|
|
18
|
-
}
|
|
19
|
-
function bytesToBase64(bytes) {
|
|
20
|
-
if (typeof btoa === "function") {
|
|
21
|
-
let binary = "";
|
|
22
|
-
const chunkSize = 32768;
|
|
23
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
24
|
-
const chunk = bytes.subarray(i, i + chunkSize);
|
|
25
|
-
binary += String.fromCharCode.apply(null, chunk);
|
|
26
|
-
}
|
|
27
|
-
return btoa(binary);
|
|
28
|
-
}
|
|
29
|
-
return Buffer.from(bytes).toString("base64");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// src/worker-proxy.ts
|
|
33
|
-
var WorkerOperationError = class extends Error {
|
|
34
|
-
constructor(message, code) {
|
|
35
|
-
super(message);
|
|
36
|
-
this.name = "WorkerOperationError";
|
|
37
|
-
this.code = code;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
function workerError(message, code) {
|
|
41
|
-
return new WorkerOperationError(message || "Unknown error", code);
|
|
42
|
-
}
|
|
43
|
-
function workerErrorCode(error) {
|
|
44
|
-
return error instanceof WorkerOperationError ? error.code : void 0;
|
|
45
|
-
}
|
|
46
|
-
function generateId() {
|
|
47
|
-
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
48
|
-
}
|
|
49
|
-
async function toBytes(document2) {
|
|
50
|
-
if (document2 instanceof Uint8Array) {
|
|
51
|
-
return new Uint8Array(document2);
|
|
52
|
-
}
|
|
53
|
-
const buffer = await document2.arrayBuffer();
|
|
54
|
-
return new Uint8Array(buffer);
|
|
55
|
-
}
|
|
56
|
-
function deriveWasmBasePath() {
|
|
57
|
-
if (typeof document !== "undefined") {
|
|
58
|
-
const scripts = document.querySelectorAll('script[src*="docxodus"]');
|
|
59
|
-
if (scripts.length > 0) {
|
|
60
|
-
const src = scripts[0].src;
|
|
61
|
-
const base = src.substring(0, src.lastIndexOf("/") + 1);
|
|
62
|
-
return base + "wasm/";
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return "/wasm/";
|
|
66
|
-
}
|
|
67
|
-
async function createWorkerDocxodus(options) {
|
|
68
|
-
if (options?.signal?.aborted) {
|
|
69
|
-
throw new Error("Worker creation aborted");
|
|
70
|
-
}
|
|
71
|
-
const wasmBasePath = options?.wasmBasePath ?? deriveWasmBasePath();
|
|
72
|
-
const workerScriptPath = new URL("./docxodus.worker.js", import.meta.url).href;
|
|
73
|
-
const worker = new Worker(workerScriptPath, { type: "module" });
|
|
74
|
-
const pendingRequests = /* @__PURE__ */ new Map();
|
|
75
|
-
let isWorkerActive = true;
|
|
76
|
-
let abortListener;
|
|
77
|
-
const stopWorker = (message) => {
|
|
78
|
-
if (!isWorkerActive) return;
|
|
79
|
-
isWorkerActive = false;
|
|
80
|
-
worker.terminate();
|
|
81
|
-
for (const pending of pendingRequests.values()) {
|
|
82
|
-
pending.reject(new Error(message));
|
|
83
|
-
}
|
|
84
|
-
pendingRequests.clear();
|
|
85
|
-
if (abortListener && options?.signal) {
|
|
86
|
-
options.signal.removeEventListener("abort", abortListener);
|
|
87
|
-
abortListener = void 0;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
if (options?.signal) {
|
|
91
|
-
abortListener = () => stopWorker("Worker creation or operation aborted");
|
|
92
|
-
options.signal.addEventListener("abort", abortListener, { once: true });
|
|
93
|
-
}
|
|
94
|
-
let preparePromise = null;
|
|
95
|
-
worker.onmessage = (event) => {
|
|
96
|
-
const response = event.data;
|
|
97
|
-
if (response.type === "ready") {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const pending = pendingRequests.get(response.id);
|
|
101
|
-
if (pending) {
|
|
102
|
-
pendingRequests.delete(response.id);
|
|
103
|
-
if (response.success) {
|
|
104
|
-
pending.resolve(response);
|
|
105
|
-
} else {
|
|
106
|
-
pending.reject(workerError(response.error, response.errorCode));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
worker.onerror = (error) => {
|
|
111
|
-
stopWorker(`Worker error: ${error.message}`);
|
|
112
|
-
};
|
|
113
|
-
function sendRequest(request, transfer) {
|
|
114
|
-
return new Promise((resolve, reject) => {
|
|
115
|
-
if (!isWorkerActive) {
|
|
116
|
-
reject(new Error("Worker has been terminated"));
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
pendingRequests.set(request.id, { resolve, reject });
|
|
120
|
-
try {
|
|
121
|
-
if (transfer && transfer.length > 0) {
|
|
122
|
-
worker.postMessage(request, transfer);
|
|
123
|
-
} else {
|
|
124
|
-
worker.postMessage(request);
|
|
125
|
-
}
|
|
126
|
-
} catch (error) {
|
|
127
|
-
pendingRequests.delete(request.id);
|
|
128
|
-
reject(error instanceof Error ? error : new Error(String(error)));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
await sendRequest({
|
|
134
|
-
id: generateId(),
|
|
135
|
-
type: "init",
|
|
136
|
-
wasmBasePath
|
|
137
|
-
});
|
|
138
|
-
} catch (error) {
|
|
139
|
-
stopWorker("Worker initialization failed");
|
|
140
|
-
throw error;
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
async generatePackageManifest(document2, limits) {
|
|
144
|
-
const bytes = await toBytes(document2);
|
|
145
|
-
const response = await sendRequest(
|
|
146
|
-
{
|
|
147
|
-
id: generateId(),
|
|
148
|
-
type: "generatePackageManifest",
|
|
149
|
-
documentBytes: bytes,
|
|
150
|
-
limits,
|
|
151
|
-
representation: "object"
|
|
152
|
-
},
|
|
153
|
-
[bytes.buffer]
|
|
154
|
-
);
|
|
155
|
-
return response.manifest;
|
|
156
|
-
},
|
|
157
|
-
async verifyDeliverable(document2, baseline, request) {
|
|
158
|
-
const bytes = await toBytes(document2);
|
|
159
|
-
const baselineBytes = baseline === void 0 ? void 0 : await toBytes(baseline);
|
|
160
|
-
const transfer = [bytes.buffer];
|
|
161
|
-
if (baselineBytes !== void 0) transfer.push(baselineBytes.buffer);
|
|
162
|
-
const response = await sendRequest(
|
|
163
|
-
{
|
|
164
|
-
id: generateId(),
|
|
165
|
-
type: "verifyDeliverable",
|
|
166
|
-
documentBytes: bytes,
|
|
167
|
-
baselineBytes,
|
|
168
|
-
requestJson: request === void 0 ? void 0 : serializeVerificationRequest(request)
|
|
169
|
-
},
|
|
170
|
-
transfer
|
|
171
|
-
);
|
|
172
|
-
if (!response.success || !response.verification) {
|
|
173
|
-
throw new Error(response.error ?? "verifyDeliverable failed");
|
|
174
|
-
}
|
|
175
|
-
return response.verification;
|
|
176
|
-
},
|
|
177
|
-
async proveRedlineReversibility(baseline, intendedFinal, redline) {
|
|
178
|
-
const baselineBytes = await toBytes(baseline);
|
|
179
|
-
const intendedFinalBytes = await toBytes(intendedFinal);
|
|
180
|
-
const redlineBytes = await toBytes(redline);
|
|
181
|
-
const response = await sendRequest(
|
|
182
|
-
{
|
|
183
|
-
id: generateId(),
|
|
184
|
-
type: "proveRedlineReversibility",
|
|
185
|
-
baselineBytes,
|
|
186
|
-
intendedFinalBytes,
|
|
187
|
-
redlineBytes
|
|
188
|
-
},
|
|
189
|
-
[baselineBytes.buffer, intendedFinalBytes.buffer, redlineBytes.buffer]
|
|
190
|
-
);
|
|
191
|
-
if (!response.success || !response.proof) {
|
|
192
|
-
throw new Error(response.error ?? "proveRedlineReversibility failed");
|
|
193
|
-
}
|
|
194
|
-
return response.proof;
|
|
195
|
-
},
|
|
196
|
-
async getSemanticChanges(left, right, settings) {
|
|
197
|
-
const leftBytes = await toBytes(left);
|
|
198
|
-
const rightBytes = await toBytes(right);
|
|
199
|
-
const response = await sendRequest(
|
|
200
|
-
{
|
|
201
|
-
id: generateId(),
|
|
202
|
-
type: "getSemanticChanges",
|
|
203
|
-
leftBytes,
|
|
204
|
-
rightBytes,
|
|
205
|
-
settings
|
|
206
|
-
},
|
|
207
|
-
[leftBytes.buffer, rightBytes.buffer]
|
|
208
|
-
);
|
|
209
|
-
return response.semanticChanges;
|
|
210
|
-
},
|
|
211
|
-
async createExternalAnnotationSet(document2, documentId) {
|
|
212
|
-
const bytes = await toBytes(document2);
|
|
213
|
-
const response = await sendRequest(
|
|
214
|
-
{ id: generateId(), type: "createExternalAnnotationSet", documentBytes: bytes, documentId },
|
|
215
|
-
[bytes.buffer]
|
|
216
|
-
);
|
|
217
|
-
if (!response.success || !response.annotationSet) {
|
|
218
|
-
throw new Error(response.error ?? "createExternalAnnotationSet failed");
|
|
219
|
-
}
|
|
220
|
-
return response.annotationSet;
|
|
221
|
-
},
|
|
222
|
-
async validateExternalAnnotations(document2, annotationSet) {
|
|
223
|
-
const bytes = await toBytes(document2);
|
|
224
|
-
const response = await sendRequest(
|
|
225
|
-
{ id: generateId(), type: "validateExternalAnnotations", documentBytes: bytes, annotationSet },
|
|
226
|
-
[bytes.buffer]
|
|
227
|
-
);
|
|
228
|
-
if (!response.success || !response.validation) {
|
|
229
|
-
throw new Error(response.error ?? "validateExternalAnnotations failed");
|
|
230
|
-
}
|
|
231
|
-
return response.validation;
|
|
232
|
-
},
|
|
233
|
-
async projectAnnotationsOntoHtml(html, annotationSet, projectionOptions) {
|
|
234
|
-
const response = await sendRequest({
|
|
235
|
-
id: generateId(),
|
|
236
|
-
type: "projectAnnotationsOntoHtml",
|
|
237
|
-
html,
|
|
238
|
-
annotationSet,
|
|
239
|
-
projectionOptions
|
|
240
|
-
});
|
|
241
|
-
if (!response.success || response.html === void 0) {
|
|
242
|
-
throw new Error(response.error ?? "projectAnnotationsOntoHtml failed");
|
|
243
|
-
}
|
|
244
|
-
return response.html;
|
|
245
|
-
},
|
|
246
|
-
async convertDocxToHtmlWithExternalAnnotations(document2, annotationSet, conversionOptions, projectionOptions) {
|
|
247
|
-
const bytes = await toBytes(document2);
|
|
248
|
-
const response = await sendRequest(
|
|
249
|
-
{
|
|
250
|
-
id: generateId(),
|
|
251
|
-
type: "convertDocxToHtmlWithExternalAnnotations",
|
|
252
|
-
documentBytes: bytes,
|
|
253
|
-
annotationSet,
|
|
254
|
-
conversionOptions,
|
|
255
|
-
projectionOptions
|
|
256
|
-
},
|
|
257
|
-
[bytes.buffer]
|
|
258
|
-
);
|
|
259
|
-
if (!response.success || response.html === void 0) {
|
|
260
|
-
throw new Error(response.error ?? "convertDocxToHtmlWithExternalAnnotations failed");
|
|
261
|
-
}
|
|
262
|
-
return response.html;
|
|
263
|
-
},
|
|
264
|
-
async exportToOpenContract(document2) {
|
|
265
|
-
const bytes = await toBytes(document2);
|
|
266
|
-
const response = await sendRequest(
|
|
267
|
-
{ id: generateId(), type: "exportToOpenContract", documentBytes: bytes },
|
|
268
|
-
[bytes.buffer]
|
|
269
|
-
);
|
|
270
|
-
if (!response.success || !response.export) {
|
|
271
|
-
throw new Error(response.error ?? "exportToOpenContract failed");
|
|
272
|
-
}
|
|
273
|
-
return response.export;
|
|
274
|
-
},
|
|
275
|
-
async generatePackageManifestJson(document2, limits) {
|
|
276
|
-
const bytes = await toBytes(document2);
|
|
277
|
-
const response = await sendRequest(
|
|
278
|
-
{
|
|
279
|
-
id: generateId(),
|
|
280
|
-
type: "generatePackageManifest",
|
|
281
|
-
documentBytes: bytes,
|
|
282
|
-
limits,
|
|
283
|
-
representation: "json"
|
|
284
|
-
},
|
|
285
|
-
[bytes.buffer]
|
|
286
|
-
);
|
|
287
|
-
if (response.manifestJson === void 0) {
|
|
288
|
-
throw new Error("Package manifest worker response omitted canonical JSON");
|
|
289
|
-
}
|
|
290
|
-
return response.manifestJson;
|
|
291
|
-
},
|
|
292
|
-
async projectReviewProfile(document2, profile, maximumOutputBytes) {
|
|
293
|
-
const bytes = await toBytes(document2);
|
|
294
|
-
const response = await sendRequest(
|
|
295
|
-
{
|
|
296
|
-
id: generateId(),
|
|
297
|
-
type: "projectReviewProfile",
|
|
298
|
-
documentBytes: bytes,
|
|
299
|
-
profile,
|
|
300
|
-
maximumOutputBytes
|
|
301
|
-
},
|
|
302
|
-
[bytes.buffer]
|
|
303
|
-
);
|
|
304
|
-
if (!response.documentBytes || response.documentBytes.byteLength === 0) {
|
|
305
|
-
throw new Error(`Failed to derive the ${profile} review profile`);
|
|
306
|
-
}
|
|
307
|
-
return response.documentBytes;
|
|
308
|
-
},
|
|
309
|
-
async convertDocxToHtml(document2, options2, maximumOutputBytes) {
|
|
310
|
-
const bytes = await toBytes(document2);
|
|
311
|
-
const response = await sendRequest(
|
|
312
|
-
{
|
|
313
|
-
id: generateId(),
|
|
314
|
-
type: "convertDocxToHtml",
|
|
315
|
-
documentBytes: bytes,
|
|
316
|
-
options: options2,
|
|
317
|
-
maximumOutputBytes
|
|
318
|
-
},
|
|
319
|
-
[bytes.buffer]
|
|
320
|
-
);
|
|
321
|
-
return response.html;
|
|
322
|
-
},
|
|
323
|
-
async compareDocuments(original, modified, options2) {
|
|
324
|
-
const originalBytes = await toBytes(original);
|
|
325
|
-
const modifiedBytes = await toBytes(modified);
|
|
326
|
-
const response = await sendRequest(
|
|
327
|
-
{
|
|
328
|
-
id: generateId(),
|
|
329
|
-
type: "compareDocuments",
|
|
330
|
-
originalBytes,
|
|
331
|
-
modifiedBytes,
|
|
332
|
-
options: options2
|
|
333
|
-
},
|
|
334
|
-
[originalBytes.buffer, modifiedBytes.buffer]
|
|
335
|
-
);
|
|
336
|
-
return response.documentBytes;
|
|
337
|
-
},
|
|
338
|
-
async compareDocumentsToHtml(original, modified, options2) {
|
|
339
|
-
const originalBytes = await toBytes(original);
|
|
340
|
-
const modifiedBytes = await toBytes(modified);
|
|
341
|
-
const response = await sendRequest(
|
|
342
|
-
{
|
|
343
|
-
id: generateId(),
|
|
344
|
-
type: "compareDocumentsToHtml",
|
|
345
|
-
originalBytes,
|
|
346
|
-
modifiedBytes,
|
|
347
|
-
options: options2
|
|
348
|
-
},
|
|
349
|
-
[originalBytes.buffer, modifiedBytes.buffer]
|
|
350
|
-
);
|
|
351
|
-
return response.html;
|
|
352
|
-
},
|
|
353
|
-
async getRevisions(document2) {
|
|
354
|
-
const bytes = await toBytes(document2);
|
|
355
|
-
const response = await sendRequest(
|
|
356
|
-
{
|
|
357
|
-
id: generateId(),
|
|
358
|
-
type: "getRevisions",
|
|
359
|
-
documentBytes: bytes
|
|
360
|
-
},
|
|
361
|
-
[bytes.buffer]
|
|
362
|
-
);
|
|
363
|
-
return response.revisions;
|
|
364
|
-
},
|
|
365
|
-
async getComments(document2) {
|
|
366
|
-
const bytes = await toBytes(document2);
|
|
367
|
-
const response = await sendRequest(
|
|
368
|
-
{ id: generateId(), type: "getComments", documentBytes: bytes },
|
|
369
|
-
[bytes.buffer]
|
|
370
|
-
);
|
|
371
|
-
return response.comments;
|
|
372
|
-
},
|
|
373
|
-
async getDocumentMetadata(document2) {
|
|
374
|
-
const bytes = await toBytes(document2);
|
|
375
|
-
const response = await sendRequest(
|
|
376
|
-
{
|
|
377
|
-
id: generateId(),
|
|
378
|
-
type: "getDocumentMetadata",
|
|
379
|
-
documentBytes: bytes
|
|
380
|
-
},
|
|
381
|
-
[bytes.buffer]
|
|
382
|
-
);
|
|
383
|
-
return response.metadata;
|
|
384
|
-
},
|
|
385
|
-
async getVersion() {
|
|
386
|
-
const response = await sendRequest({
|
|
387
|
-
id: generateId(),
|
|
388
|
-
type: "getVersion"
|
|
389
|
-
});
|
|
390
|
-
return response.version;
|
|
391
|
-
},
|
|
392
|
-
prepare() {
|
|
393
|
-
if (preparePromise) {
|
|
394
|
-
return preparePromise;
|
|
395
|
-
}
|
|
396
|
-
preparePromise = sendRequest({
|
|
397
|
-
id: generateId(),
|
|
398
|
-
type: "prepare"
|
|
399
|
-
}).then(() => void 0);
|
|
400
|
-
preparePromise.catch(() => {
|
|
401
|
-
preparePromise = null;
|
|
402
|
-
});
|
|
403
|
-
return preparePromise;
|
|
404
|
-
},
|
|
405
|
-
async openDocxSession(document2, settings) {
|
|
406
|
-
const bytes = await toBytes(document2);
|
|
407
|
-
const settingsJson = settings ? JSON.stringify(settings) : "";
|
|
408
|
-
const openResponse = await sendRequest(
|
|
409
|
-
{
|
|
410
|
-
id: generateId(),
|
|
411
|
-
type: "sessionOpen",
|
|
412
|
-
documentBytes: bytes,
|
|
413
|
-
settingsJson
|
|
414
|
-
},
|
|
415
|
-
[bytes.buffer]
|
|
416
|
-
);
|
|
417
|
-
if (!openResponse.success || openResponse.handle === void 0) {
|
|
418
|
-
throw new Error(
|
|
419
|
-
`Failed to open worker DocxSession: ${openResponse.error ?? "unknown error"}`
|
|
420
|
-
);
|
|
421
|
-
}
|
|
422
|
-
const handle = openResponse.handle;
|
|
423
|
-
return {
|
|
424
|
-
async getPackageManifest() {
|
|
425
|
-
const res = await sendRequest({
|
|
426
|
-
id: generateId(),
|
|
427
|
-
type: "sessionGetPackageManifest",
|
|
428
|
-
handle
|
|
429
|
-
});
|
|
430
|
-
if (!res.success || !res.manifest) {
|
|
431
|
-
throw new Error(res.error ?? "sessionGetPackageManifest failed");
|
|
432
|
-
}
|
|
433
|
-
return res.manifest;
|
|
434
|
-
},
|
|
435
|
-
async getSemanticChanges() {
|
|
436
|
-
const res = await sendRequest({
|
|
437
|
-
id: generateId(),
|
|
438
|
-
type: "sessionGetSemanticChanges",
|
|
439
|
-
handle
|
|
440
|
-
});
|
|
441
|
-
if (!res.success || !res.semanticChanges) {
|
|
442
|
-
throw new Error(res.error ?? "sessionGetSemanticChanges failed");
|
|
443
|
-
}
|
|
444
|
-
return res.semanticChanges;
|
|
445
|
-
},
|
|
446
|
-
async verifyDeliverable(request) {
|
|
447
|
-
const res = await sendRequest({
|
|
448
|
-
id: generateId(),
|
|
449
|
-
type: "sessionVerifyDeliverable",
|
|
450
|
-
handle,
|
|
451
|
-
requestJson: request === void 0 ? void 0 : serializeVerificationRequest(request)
|
|
452
|
-
});
|
|
453
|
-
if (!res.success || !res.verification) {
|
|
454
|
-
throw new Error(res.error ?? "sessionVerifyDeliverable failed");
|
|
455
|
-
}
|
|
456
|
-
return res.verification;
|
|
457
|
-
},
|
|
458
|
-
async addAnnotation(anchorId, span, annotation) {
|
|
459
|
-
const res = await sendRequest({
|
|
460
|
-
id: generateId(),
|
|
461
|
-
type: "sessionAddAnnotation",
|
|
462
|
-
handle,
|
|
463
|
-
anchorId,
|
|
464
|
-
spanJson: span ? JSON.stringify(span) : "",
|
|
465
|
-
annotationJson: JSON.stringify(annotation)
|
|
466
|
-
});
|
|
467
|
-
if (!res.success) {
|
|
468
|
-
throw new Error(res.error ?? "sessionAddAnnotation failed");
|
|
469
|
-
}
|
|
470
|
-
return res.result;
|
|
471
|
-
},
|
|
472
|
-
async removeAnnotation(annotationId) {
|
|
473
|
-
const res = await sendRequest({
|
|
474
|
-
id: generateId(),
|
|
475
|
-
type: "sessionRemoveAnnotation",
|
|
476
|
-
handle,
|
|
477
|
-
annotationId
|
|
478
|
-
});
|
|
479
|
-
if (!res.success) {
|
|
480
|
-
throw new Error(res.error ?? "sessionRemoveAnnotation failed");
|
|
481
|
-
}
|
|
482
|
-
return res.result;
|
|
483
|
-
},
|
|
484
|
-
async updateAnnotation(annotationId, update) {
|
|
485
|
-
const res = await sendRequest({
|
|
486
|
-
id: generateId(),
|
|
487
|
-
type: "sessionUpdateAnnotation",
|
|
488
|
-
handle,
|
|
489
|
-
annotationId,
|
|
490
|
-
updateJson: JSON.stringify(update)
|
|
491
|
-
});
|
|
492
|
-
if (!res.success) {
|
|
493
|
-
throw new Error(res.error ?? "sessionUpdateAnnotation failed");
|
|
494
|
-
}
|
|
495
|
-
return res.result;
|
|
496
|
-
},
|
|
497
|
-
async moveAnnotation(annotationId, newAnchorId, newSpan) {
|
|
498
|
-
const res = await sendRequest({
|
|
499
|
-
id: generateId(),
|
|
500
|
-
type: "sessionMoveAnnotation",
|
|
501
|
-
handle,
|
|
502
|
-
annotationId,
|
|
503
|
-
newAnchorId,
|
|
504
|
-
newSpanJson: newSpan ? JSON.stringify(newSpan) : ""
|
|
505
|
-
});
|
|
506
|
-
if (!res.success) {
|
|
507
|
-
throw new Error(res.error ?? "sessionMoveAnnotation failed");
|
|
508
|
-
}
|
|
509
|
-
return res.result;
|
|
510
|
-
},
|
|
511
|
-
async close() {
|
|
512
|
-
await sendRequest({
|
|
513
|
-
id: generateId(),
|
|
514
|
-
type: "sessionClose",
|
|
515
|
-
handle
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
},
|
|
520
|
-
terminate() {
|
|
521
|
-
stopWorker("Worker terminated");
|
|
522
|
-
},
|
|
523
|
-
isActive() {
|
|
524
|
-
return isWorkerActive;
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function isWorkerSupported() {
|
|
529
|
-
return typeof Worker !== "undefined";
|
|
530
|
-
}
|
|
531
|
-
export {
|
|
532
|
-
WorkerOperationError,
|
|
533
|
-
createWorkerDocxodus,
|
|
534
|
-
isWorkerSupported,
|
|
535
|
-
workerErrorCode
|
|
536
|
-
};
|
|
1
|
+
function h(o){if(o===null||typeof o!="object"||Array.isArray(o))throw new RangeError("a verification request must be an object");let{companionArtifacts:u,...f}=o,k={...f};return u!==void 0&&(k.companionArtifacts=u.map(U)),JSON.stringify(k)}function U(o){let{bytes:u,...f}=o,k={...f};return u!==void 0&&(k.bytesB64=F(u)),k}function F(o){if(typeof btoa=="function"){let u="";for(let k=0;k<o.length;k+=32768){let A=o.subarray(k,k+32768);u+=String.fromCharCode.apply(null,A)}return btoa(u)}return Buffer.from(o).toString("base64")}var x=class extends Error{constructor(u,f){super(u),this.name="WorkerOperationError",this.code=f}};function P(o,u){return new x(o||"Unknown error",u)}function l(o,u){let f=o[u];if(f==null)throw P(`The worker's "${o.type??"unknown"}" response reported success without its ${String(u)}`,"missing_result");return f}function C(o,u){if(o!==void 0&&!(Number.isFinite(o)&&o>0))throw new RangeError(`${u} must be a positive, finite number of milliseconds; got ${o}`);return o}function B(o){return o instanceof x?o.code:void 0}function a(){return`${Date.now()}-${Math.random().toString(36).slice(2,11)}`}async function p(o){if(o instanceof Uint8Array)return new Uint8Array(o);let u=await o.arrayBuffer();return new Uint8Array(u)}function O(){if(typeof document<"u"){let o=document.querySelectorAll('script[src*="docxodus"]');if(o.length>0){let u=o[0].src;return u.substring(0,u.lastIndexOf("/")+1)+"wasm/"}}return"/wasm/"}async function V(o){if(o?.signal?.aborted)throw new Error("Worker creation aborted");let u=C(o?.requestTimeoutMs,"requestTimeoutMs"),f=o?.wasmBasePath??O(),k=new URL("./docxodus.worker.js",import.meta.url).href,A=new Worker(k,{type:"module"}),v=new Map,W=!0,w,S=m=>{if(W){W=!1,A.terminate();for(let r of v.values())r.reject(new Error(m));v.clear(),w&&o?.signal&&(o.signal.removeEventListener("abort",w),w=void 0)}};o?.signal&&(w=()=>S("Worker creation or operation aborted"),o.signal.addEventListener("abort",w,{once:!0}));let b=null;A.onmessage=m=>{let r=m.data;if(r.type==="ready")return;let e=v.get(r.id);e&&(v.delete(r.id),r.success?e.resolve(r):e.reject(P(r.error,r.errorCode)))},A.onerror=m=>{S(`Worker error: ${m.message}`)},A.onmessageerror=()=>{for(let m of[...v.values()])m.reject(P("A worker response could not be deserialized, so every request in flight was rejected","message_error"))};function E(m,r,e){return new Promise((t,n)=>{if(!W){n(new Error("Worker has been terminated"));return}let i=e?.signal;if(i?.aborted){n(P(`The worker request "${m.type}" was aborted before it was sent`,"aborted"));return}let s=e?.timeoutMs??u,c,d,y=()=>{v.delete(m.id),c!==void 0&&clearTimeout(c),d&&i?.removeEventListener("abort",d)};v.set(m.id,{resolve:g=>{y(),t(g)},reject:g=>{y(),n(g)}});let R=g=>v.get(m.id)?.reject(g);s!==void 0&&(c=setTimeout(()=>R(P(`The worker request "${m.type}" timed out after ${s} ms`,"timeout")),s)),i&&(d=()=>R(P(`The worker request "${m.type}" was aborted`,"aborted")),i.addEventListener("abort",d,{once:!0}));try{r&&r.length>0?A.postMessage(m,r):A.postMessage(m)}catch(g){R(g instanceof Error?g:new Error(String(g)))}})}try{await E({id:a(),type:"init",wasmBasePath:f})}catch(m){throw S("Worker initialization failed"),m}let D=m=>{let r=(e,t)=>E(e,t,m);return{async generatePackageManifest(e,t){let n=await p(e),i=await r({id:a(),type:"generatePackageManifest",documentBytes:n,limits:t,representation:"object"},[n.buffer]);return l(i,"manifest")},async verifyDeliverable(e,t,n){let i=await p(e),s=t===void 0?void 0:await p(t),c=[i.buffer];s!==void 0&&c.push(s.buffer);let d=await r({id:a(),type:"verifyDeliverable",documentBytes:i,baselineBytes:s,requestJson:n===void 0?void 0:h(n)},c);return l(d,"verification")},async proveRedlineReversibility(e,t,n){let i=await p(e),s=await p(t),c=await p(n),d=await r({id:a(),type:"proveRedlineReversibility",baselineBytes:i,intendedFinalBytes:s,redlineBytes:c},[i.buffer,s.buffer,c.buffer]);return l(d,"proof")},async getSemanticChanges(e,t,n){let i=await p(e),s=await p(t),c=await r({id:a(),type:"getSemanticChanges",leftBytes:i,rightBytes:s,settings:n},[i.buffer,s.buffer]);return l(c,"semanticChanges")},async createExternalAnnotationSet(e,t){let n=await p(e),i=await r({id:a(),type:"createExternalAnnotationSet",documentBytes:n,documentId:t},[n.buffer]);return l(i,"annotationSet")},async validateExternalAnnotations(e,t){let n=await p(e),i=await r({id:a(),type:"validateExternalAnnotations",documentBytes:n,annotationSet:t},[n.buffer]);return l(i,"validation")},async projectAnnotationsOntoHtml(e,t,n){let i=await r({id:a(),type:"projectAnnotationsOntoHtml",html:e,annotationSet:t,projectionOptions:n});return l(i,"html")},async convertDocxToHtmlWithExternalAnnotations(e,t,n,i){let s=await p(e),c=await r({id:a(),type:"convertDocxToHtmlWithExternalAnnotations",documentBytes:s,annotationSet:t,conversionOptions:n,projectionOptions:i},[s.buffer]);return l(c,"html")},async exportToOpenContract(e){let t=await p(e),n=await r({id:a(),type:"exportToOpenContract",documentBytes:t},[t.buffer]);return l(n,"export")},async generatePackageManifestJson(e,t){let n=await p(e),i=await r({id:a(),type:"generatePackageManifest",documentBytes:n,limits:t,representation:"json"},[n.buffer]);return l(i,"manifestJson")},async projectReviewProfile(e,t,n){let i=await p(e),s=await r({id:a(),type:"projectReviewProfile",documentBytes:i,profile:t,maximumOutputBytes:n},[i.buffer]);if(!s.documentBytes||s.documentBytes.byteLength===0)throw new Error(`Failed to derive the ${t} review profile`);return s.documentBytes},async convertDocxToHtml(e,t,n){let i=await p(e),s=await r({id:a(),type:"convertDocxToHtml",documentBytes:i,options:t,maximumOutputBytes:n},[i.buffer]);return l(s,"html")},async compareDocuments(e,t,n){let i=await p(e),s=await p(t),c=await r({id:a(),type:"compareDocuments",originalBytes:i,modifiedBytes:s,options:n},[i.buffer,s.buffer]);return l(c,"documentBytes")},async compareDocumentsToHtml(e,t,n){let i=await p(e),s=await p(t),c=await r({id:a(),type:"compareDocumentsToHtml",originalBytes:i,modifiedBytes:s,options:n},[i.buffer,s.buffer]);return l(c,"html")},async getRevisions(e){let t=await p(e),n=await r({id:a(),type:"getRevisions",documentBytes:t},[t.buffer]);return l(n,"revisions")},async getComments(e){let t=await p(e),n=await r({id:a(),type:"getComments",documentBytes:t},[t.buffer]);return l(n,"comments")},async getDocumentMetadata(e){let t=await p(e),n=await r({id:a(),type:"getDocumentMetadata",documentBytes:t},[t.buffer]);return l(n,"metadata")},async getVersion(){let e=await r({id:a(),type:"getVersion"});return l(e,"version")},prepare(){return b||(b=r({id:a(),type:"prepare"}).then(()=>{}),b.catch(()=>{b=null}),b)},async openDocxSession(e,t){let n=await p(e),i=t?JSON.stringify(t):"",s=await r({id:a(),type:"sessionOpen",documentBytes:n,settingsJson:i},[n.buffer]),c=l(s,"handle");return{async getPackageManifest(){let d=await r({id:a(),type:"sessionGetPackageManifest",handle:c});return l(d,"manifest")},async getSemanticChanges(){let d=await r({id:a(),type:"sessionGetSemanticChanges",handle:c});return l(d,"semanticChanges")},async verifyDeliverable(d){let y=await r({id:a(),type:"sessionVerifyDeliverable",handle:c,requestJson:d===void 0?void 0:h(d)});return l(y,"verification")},async addAnnotation(d,y,R){let g=await r({id:a(),type:"sessionAddAnnotation",handle:c,anchorId:d,spanJson:y?JSON.stringify(y):"",annotationJson:JSON.stringify(R)});return l(g,"result")},async removeAnnotation(d){let y=await r({id:a(),type:"sessionRemoveAnnotation",handle:c,annotationId:d});return l(y,"result")},async updateAnnotation(d,y){let R=await r({id:a(),type:"sessionUpdateAnnotation",handle:c,annotationId:d,updateJson:JSON.stringify(y)});return l(R,"result")},async moveAnnotation(d,y,R){let g=await r({id:a(),type:"sessionMoveAnnotation",handle:c,annotationId:d,newAnchorId:y,newSpanJson:R?JSON.stringify(R):""});return l(g,"result")},async close(){await E({id:a(),type:"sessionClose",handle:c},void 0,{timeoutMs:m?.timeoutMs})}}},terminate(){S("Worker terminated")},withRequestOptions(e){return C(e.timeoutMs,"timeoutMs"),D({...m,...e})},isActive(){return W}}};return D()}function j(){return typeof Worker<"u"}export{x as WorkerOperationError,V as createWorkerDocxodus,j as isWorkerSupported,B as workerErrorCode};
|
|
2
|
+
//# sourceMappingURL=worker-proxy.bundle.js.map
|