docxodus 3.9.0 → 4.0.1
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/dist/docxodus.worker.d.ts +11 -0
- package/dist/docxodus.worker.d.ts.map +1 -0
- package/dist/docxodus.worker.js +384 -0
- package/dist/docxodus.worker.js.map +1 -0
- package/dist/index.d.ts +36 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +289 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wasm/_framework/Docxodus.wasm +0 -0
- package/dist/wasm/_framework/DocxodusWasm.wasm +0 -0
- package/dist/wasm/_framework/System.Private.CoreLib.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Json.wasm +0 -0
- package/dist/wasm/_framework/blazor.boot.json +7 -7
- package/dist/wasm/_framework/dotnet.native.wasm +0 -0
- package/dist/worker-proxy.bundle.js +170 -0
- package/dist/worker-proxy.d.ts +107 -0
- package/dist/worker-proxy.d.ts.map +1 -0
- package/dist/worker-proxy.js +229 -0
- package/dist/worker-proxy.js.map +1 -0
- package/package.json +8 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/worker-proxy.ts
|
|
2
|
+
function generateId() {
|
|
3
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
4
|
+
}
|
|
5
|
+
async function toBytes(document2) {
|
|
6
|
+
if (document2 instanceof Uint8Array) {
|
|
7
|
+
return document2;
|
|
8
|
+
}
|
|
9
|
+
const buffer = await document2.arrayBuffer();
|
|
10
|
+
return new Uint8Array(buffer);
|
|
11
|
+
}
|
|
12
|
+
function deriveWasmBasePath() {
|
|
13
|
+
if (typeof document !== "undefined") {
|
|
14
|
+
const scripts = document.querySelectorAll('script[src*="docxodus"]');
|
|
15
|
+
if (scripts.length > 0) {
|
|
16
|
+
const src = scripts[0].src;
|
|
17
|
+
const base = src.substring(0, src.lastIndexOf("/") + 1);
|
|
18
|
+
return base + "wasm/";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return "/wasm/";
|
|
22
|
+
}
|
|
23
|
+
async function createWorkerDocxodus(options) {
|
|
24
|
+
const wasmBasePath = options?.wasmBasePath ?? deriveWasmBasePath();
|
|
25
|
+
let workerUrl;
|
|
26
|
+
const workerScriptPath = new URL("./docxodus.worker.js", import.meta.url).href;
|
|
27
|
+
const worker = new Worker(workerScriptPath, { type: "module" });
|
|
28
|
+
const pendingRequests = /* @__PURE__ */ new Map();
|
|
29
|
+
let isWorkerActive = true;
|
|
30
|
+
worker.onmessage = (event) => {
|
|
31
|
+
const response = event.data;
|
|
32
|
+
if (response.type === "ready") {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const pending = pendingRequests.get(response.id);
|
|
36
|
+
if (pending) {
|
|
37
|
+
pendingRequests.delete(response.id);
|
|
38
|
+
if (response.success) {
|
|
39
|
+
pending.resolve(response);
|
|
40
|
+
} else {
|
|
41
|
+
pending.reject(new Error(response.error || "Unknown error"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
worker.onerror = (error) => {
|
|
46
|
+
for (const pending of pendingRequests.values()) {
|
|
47
|
+
pending.reject(new Error(`Worker error: ${error.message}`));
|
|
48
|
+
}
|
|
49
|
+
pendingRequests.clear();
|
|
50
|
+
isWorkerActive = false;
|
|
51
|
+
};
|
|
52
|
+
function sendRequest(request, transfer) {
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
if (!isWorkerActive) {
|
|
55
|
+
reject(new Error("Worker has been terminated"));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
pendingRequests.set(request.id, { resolve, reject });
|
|
59
|
+
if (transfer && transfer.length > 0) {
|
|
60
|
+
worker.postMessage(request, transfer);
|
|
61
|
+
} else {
|
|
62
|
+
worker.postMessage(request);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const initResponse = await sendRequest({
|
|
67
|
+
id: generateId(),
|
|
68
|
+
type: "init",
|
|
69
|
+
wasmBasePath
|
|
70
|
+
});
|
|
71
|
+
if (!initResponse.success) {
|
|
72
|
+
worker.terminate();
|
|
73
|
+
throw new Error(`Failed to initialize worker: ${initResponse.error}`);
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
async convertDocxToHtml(document2, options2) {
|
|
77
|
+
const bytes = await toBytes(document2);
|
|
78
|
+
const response = await sendRequest(
|
|
79
|
+
{
|
|
80
|
+
id: generateId(),
|
|
81
|
+
type: "convertDocxToHtml",
|
|
82
|
+
documentBytes: bytes,
|
|
83
|
+
options: options2
|
|
84
|
+
},
|
|
85
|
+
[bytes.buffer]
|
|
86
|
+
);
|
|
87
|
+
return response.html;
|
|
88
|
+
},
|
|
89
|
+
async compareDocuments(original, modified, options2) {
|
|
90
|
+
const originalBytes = await toBytes(original);
|
|
91
|
+
const modifiedBytes = await toBytes(modified);
|
|
92
|
+
const response = await sendRequest(
|
|
93
|
+
{
|
|
94
|
+
id: generateId(),
|
|
95
|
+
type: "compareDocuments",
|
|
96
|
+
originalBytes,
|
|
97
|
+
modifiedBytes,
|
|
98
|
+
options: options2
|
|
99
|
+
},
|
|
100
|
+
[originalBytes.buffer, modifiedBytes.buffer]
|
|
101
|
+
);
|
|
102
|
+
return response.documentBytes;
|
|
103
|
+
},
|
|
104
|
+
async compareDocumentsToHtml(original, modified, options2) {
|
|
105
|
+
const originalBytes = await toBytes(original);
|
|
106
|
+
const modifiedBytes = await toBytes(modified);
|
|
107
|
+
const response = await sendRequest(
|
|
108
|
+
{
|
|
109
|
+
id: generateId(),
|
|
110
|
+
type: "compareDocumentsToHtml",
|
|
111
|
+
originalBytes,
|
|
112
|
+
modifiedBytes,
|
|
113
|
+
options: options2
|
|
114
|
+
},
|
|
115
|
+
[originalBytes.buffer, modifiedBytes.buffer]
|
|
116
|
+
);
|
|
117
|
+
return response.html;
|
|
118
|
+
},
|
|
119
|
+
async getRevisions(document2, options2) {
|
|
120
|
+
const bytes = await toBytes(document2);
|
|
121
|
+
const response = await sendRequest(
|
|
122
|
+
{
|
|
123
|
+
id: generateId(),
|
|
124
|
+
type: "getRevisions",
|
|
125
|
+
documentBytes: bytes,
|
|
126
|
+
options: options2
|
|
127
|
+
},
|
|
128
|
+
[bytes.buffer]
|
|
129
|
+
);
|
|
130
|
+
return response.revisions;
|
|
131
|
+
},
|
|
132
|
+
async getDocumentMetadata(document2) {
|
|
133
|
+
const bytes = await toBytes(document2);
|
|
134
|
+
const response = await sendRequest(
|
|
135
|
+
{
|
|
136
|
+
id: generateId(),
|
|
137
|
+
type: "getDocumentMetadata",
|
|
138
|
+
documentBytes: bytes
|
|
139
|
+
},
|
|
140
|
+
[bytes.buffer]
|
|
141
|
+
);
|
|
142
|
+
return response.metadata;
|
|
143
|
+
},
|
|
144
|
+
async getVersion() {
|
|
145
|
+
const response = await sendRequest({
|
|
146
|
+
id: generateId(),
|
|
147
|
+
type: "getVersion"
|
|
148
|
+
});
|
|
149
|
+
return response.version;
|
|
150
|
+
},
|
|
151
|
+
terminate() {
|
|
152
|
+
isWorkerActive = false;
|
|
153
|
+
worker.terminate();
|
|
154
|
+
for (const pending of pendingRequests.values()) {
|
|
155
|
+
pending.reject(new Error("Worker terminated"));
|
|
156
|
+
}
|
|
157
|
+
pendingRequests.clear();
|
|
158
|
+
},
|
|
159
|
+
isActive() {
|
|
160
|
+
return isWorkerActive;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function isWorkerSupported() {
|
|
165
|
+
return typeof Worker !== "undefined";
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
createWorkerDocxodus,
|
|
169
|
+
isWorkerSupported
|
|
170
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Proxy - Main thread interface for the Docxodus Web Worker
|
|
3
|
+
*
|
|
4
|
+
* This module provides a Promise-based API that mirrors the main API but
|
|
5
|
+
* executes all WASM operations in a Web Worker, keeping the main thread free.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createWorkerDocxodus } from 'docxodus/worker';
|
|
10
|
+
*
|
|
11
|
+
* // Create worker instance
|
|
12
|
+
* const docxodus = await createWorkerDocxodus();
|
|
13
|
+
*
|
|
14
|
+
* // Use the same API as the main module, but non-blocking!
|
|
15
|
+
* const html = await docxodus.convertDocxToHtml(docxFile);
|
|
16
|
+
*
|
|
17
|
+
* // Clean up when done
|
|
18
|
+
* docxodus.terminate();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { WorkerDocxodusOptions, ConversionOptions, CompareOptions, GetRevisionsOptions, Revision, VersionInfo, DocumentMetadata } from "./types.js";
|
|
22
|
+
/**
|
|
23
|
+
* A worker-based Docxodus instance.
|
|
24
|
+
*
|
|
25
|
+
* Provides the same API as the main module but executes all operations
|
|
26
|
+
* in a Web Worker for non-blocking UI.
|
|
27
|
+
*/
|
|
28
|
+
export interface WorkerDocxodus {
|
|
29
|
+
/**
|
|
30
|
+
* Convert a DOCX document to HTML.
|
|
31
|
+
* @param document - DOCX file as File object or Uint8Array
|
|
32
|
+
* @param options - Conversion options
|
|
33
|
+
* @returns HTML string
|
|
34
|
+
*/
|
|
35
|
+
convertDocxToHtml(document: File | Uint8Array, options?: ConversionOptions): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Compare two DOCX documents and return the redlined result.
|
|
38
|
+
* @param original - Original DOCX document
|
|
39
|
+
* @param modified - Modified DOCX document
|
|
40
|
+
* @param options - Comparison options
|
|
41
|
+
* @returns Redlined DOCX as Uint8Array
|
|
42
|
+
*/
|
|
43
|
+
compareDocuments(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<Uint8Array>;
|
|
44
|
+
/**
|
|
45
|
+
* Compare two DOCX documents and return the result as HTML.
|
|
46
|
+
* @param original - Original DOCX document
|
|
47
|
+
* @param modified - Modified DOCX document
|
|
48
|
+
* @param options - Comparison options
|
|
49
|
+
* @returns HTML string with redlined content
|
|
50
|
+
*/
|
|
51
|
+
compareDocumentsToHtml(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Get revisions from a compared document.
|
|
54
|
+
* @param document - A document that has tracked changes
|
|
55
|
+
* @param options - Revision extraction options
|
|
56
|
+
* @returns Array of revisions
|
|
57
|
+
*/
|
|
58
|
+
getRevisions(document: File | Uint8Array, options?: GetRevisionsOptions): Promise<Revision[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Get document metadata for lazy loading pagination.
|
|
61
|
+
* This is a fast operation that extracts structure without full HTML rendering.
|
|
62
|
+
* @param document - DOCX file as File object or Uint8Array
|
|
63
|
+
* @returns Document metadata including sections, dimensions, and content counts
|
|
64
|
+
*/
|
|
65
|
+
getDocumentMetadata(document: File | Uint8Array): Promise<DocumentMetadata>;
|
|
66
|
+
/**
|
|
67
|
+
* Get version information about the library.
|
|
68
|
+
* @returns Version information
|
|
69
|
+
*/
|
|
70
|
+
getVersion(): Promise<VersionInfo>;
|
|
71
|
+
/**
|
|
72
|
+
* Terminate the worker.
|
|
73
|
+
* After calling this, the instance cannot be used anymore.
|
|
74
|
+
*/
|
|
75
|
+
terminate(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Check if the worker is still active.
|
|
78
|
+
*/
|
|
79
|
+
isActive(): boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create a worker-based Docxodus instance.
|
|
83
|
+
*
|
|
84
|
+
* This function spawns a Web Worker that loads the WASM runtime independently.
|
|
85
|
+
* All operations are executed in the worker, keeping the main thread responsive.
|
|
86
|
+
*
|
|
87
|
+
* @param options - Configuration options
|
|
88
|
+
* @returns A Promise that resolves to a WorkerDocxodus instance
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Basic usage
|
|
93
|
+
* const docxodus = await createWorkerDocxodus();
|
|
94
|
+
* const html = await docxodus.convertDocxToHtml(docxFile);
|
|
95
|
+
*
|
|
96
|
+
* // With custom WASM path
|
|
97
|
+
* const docxodus = await createWorkerDocxodus({
|
|
98
|
+
* wasmBasePath: '/assets/wasm/'
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare function createWorkerDocxodus(options?: WorkerDocxodusOptions): Promise<WorkerDocxodus>;
|
|
103
|
+
/**
|
|
104
|
+
* Check if Web Workers are supported in the current environment.
|
|
105
|
+
*/
|
|
106
|
+
export declare function isWorkerSupported(): boolean;
|
|
107
|
+
//# sourceMappingURL=worker-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-proxy.d.ts","sourceRoot":"","sources":["../src/worker-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EASV,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAuCpB;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,iBAAiB,CACf,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;OAMG;IACH,gBAAgB,CACd,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvB;;;;;;OAMG;IACH,sBAAsB,CACpB,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,YAAY,CACV,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEvB;;;;;OAKG;IACH,mBAAmB,CAAC,QAAQ,EAAE,IAAI,GAAG,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE5E;;;OAGG;IACH,UAAU,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAEnC;;;OAGG;IACH,SAAS,IAAI,IAAI,CAAC;IAElB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,CAAC,EAAE,qBAAqB,GAC9B,OAAO,CAAC,cAAc,CAAC,CAiNzB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker Proxy - Main thread interface for the Docxodus Web Worker
|
|
3
|
+
*
|
|
4
|
+
* This module provides a Promise-based API that mirrors the main API but
|
|
5
|
+
* executes all WASM operations in a Web Worker, keeping the main thread free.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createWorkerDocxodus } from 'docxodus/worker';
|
|
10
|
+
*
|
|
11
|
+
* // Create worker instance
|
|
12
|
+
* const docxodus = await createWorkerDocxodus();
|
|
13
|
+
*
|
|
14
|
+
* // Use the same API as the main module, but non-blocking!
|
|
15
|
+
* const html = await docxodus.convertDocxToHtml(docxFile);
|
|
16
|
+
*
|
|
17
|
+
* // Clean up when done
|
|
18
|
+
* docxodus.terminate();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Generate a unique request ID.
|
|
23
|
+
*/
|
|
24
|
+
function generateId() {
|
|
25
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert a File or Uint8Array to Uint8Array.
|
|
29
|
+
*/
|
|
30
|
+
async function toBytes(document) {
|
|
31
|
+
if (document instanceof Uint8Array) {
|
|
32
|
+
return document;
|
|
33
|
+
}
|
|
34
|
+
const buffer = await document.arrayBuffer();
|
|
35
|
+
return new Uint8Array(buffer);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derive the WASM base path from the current module URL.
|
|
39
|
+
*/
|
|
40
|
+
function deriveWasmBasePath() {
|
|
41
|
+
// Try to get the base path from the current script URL
|
|
42
|
+
if (typeof document !== "undefined") {
|
|
43
|
+
// Browser: look for docxodus script tag or use current location
|
|
44
|
+
const scripts = document.querySelectorAll('script[src*="docxodus"]');
|
|
45
|
+
if (scripts.length > 0) {
|
|
46
|
+
const src = scripts[0].src;
|
|
47
|
+
const base = src.substring(0, src.lastIndexOf("/") + 1);
|
|
48
|
+
return base + "wasm/";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Default fallback
|
|
52
|
+
return "/wasm/";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a worker-based Docxodus instance.
|
|
56
|
+
*
|
|
57
|
+
* This function spawns a Web Worker that loads the WASM runtime independently.
|
|
58
|
+
* All operations are executed in the worker, keeping the main thread responsive.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration options
|
|
61
|
+
* @returns A Promise that resolves to a WorkerDocxodus instance
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Basic usage
|
|
66
|
+
* const docxodus = await createWorkerDocxodus();
|
|
67
|
+
* const html = await docxodus.convertDocxToHtml(docxFile);
|
|
68
|
+
*
|
|
69
|
+
* // With custom WASM path
|
|
70
|
+
* const docxodus = await createWorkerDocxodus({
|
|
71
|
+
* wasmBasePath: '/assets/wasm/'
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export async function createWorkerDocxodus(options) {
|
|
76
|
+
// Determine WASM base path
|
|
77
|
+
const wasmBasePath = options?.wasmBasePath ?? deriveWasmBasePath();
|
|
78
|
+
// Determine worker script path
|
|
79
|
+
// The worker bundle should be in the same directory as this module
|
|
80
|
+
let workerUrl;
|
|
81
|
+
// Try to create worker from bundled script or blob
|
|
82
|
+
// For now, we'll use a blob URL to inline the worker path
|
|
83
|
+
const workerScriptPath = new URL("./docxodus.worker.js", import.meta.url)
|
|
84
|
+
.href;
|
|
85
|
+
// Create the worker
|
|
86
|
+
const worker = new Worker(workerScriptPath, { type: "module" });
|
|
87
|
+
// Track pending requests
|
|
88
|
+
const pendingRequests = new Map();
|
|
89
|
+
// Track if worker is active
|
|
90
|
+
let isWorkerActive = true;
|
|
91
|
+
// Handle worker messages
|
|
92
|
+
worker.onmessage = (event) => {
|
|
93
|
+
const response = event.data;
|
|
94
|
+
// Handle ready signal
|
|
95
|
+
if (response.type === "ready") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Handle normal responses
|
|
99
|
+
const pending = pendingRequests.get(response.id);
|
|
100
|
+
if (pending) {
|
|
101
|
+
pendingRequests.delete(response.id);
|
|
102
|
+
if (response.success) {
|
|
103
|
+
pending.resolve(response);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
pending.reject(new Error(response.error || "Unknown error"));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
// Handle worker errors
|
|
111
|
+
worker.onerror = (error) => {
|
|
112
|
+
// Reject all pending requests
|
|
113
|
+
for (const pending of pendingRequests.values()) {
|
|
114
|
+
pending.reject(new Error(`Worker error: ${error.message}`));
|
|
115
|
+
}
|
|
116
|
+
pendingRequests.clear();
|
|
117
|
+
isWorkerActive = false;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Send a request to the worker and wait for response.
|
|
121
|
+
*/
|
|
122
|
+
function sendRequest(request, transfer) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
if (!isWorkerActive) {
|
|
125
|
+
reject(new Error("Worker has been terminated"));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
pendingRequests.set(request.id, { resolve, reject });
|
|
129
|
+
if (transfer && transfer.length > 0) {
|
|
130
|
+
worker.postMessage(request, transfer);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
worker.postMessage(request);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Initialize the worker
|
|
138
|
+
const initResponse = await sendRequest({
|
|
139
|
+
id: generateId(),
|
|
140
|
+
type: "init",
|
|
141
|
+
wasmBasePath,
|
|
142
|
+
});
|
|
143
|
+
if (!initResponse.success) {
|
|
144
|
+
worker.terminate();
|
|
145
|
+
throw new Error(`Failed to initialize worker: ${initResponse.error}`);
|
|
146
|
+
}
|
|
147
|
+
// Return the WorkerDocxodus instance
|
|
148
|
+
return {
|
|
149
|
+
async convertDocxToHtml(document, options) {
|
|
150
|
+
const bytes = await toBytes(document);
|
|
151
|
+
const response = await sendRequest({
|
|
152
|
+
id: generateId(),
|
|
153
|
+
type: "convertDocxToHtml",
|
|
154
|
+
documentBytes: bytes,
|
|
155
|
+
options,
|
|
156
|
+
}, [bytes.buffer]);
|
|
157
|
+
return response.html;
|
|
158
|
+
},
|
|
159
|
+
async compareDocuments(original, modified, options) {
|
|
160
|
+
const originalBytes = await toBytes(original);
|
|
161
|
+
const modifiedBytes = await toBytes(modified);
|
|
162
|
+
const response = await sendRequest({
|
|
163
|
+
id: generateId(),
|
|
164
|
+
type: "compareDocuments",
|
|
165
|
+
originalBytes,
|
|
166
|
+
modifiedBytes,
|
|
167
|
+
options,
|
|
168
|
+
}, [originalBytes.buffer, modifiedBytes.buffer]);
|
|
169
|
+
return response.documentBytes;
|
|
170
|
+
},
|
|
171
|
+
async compareDocumentsToHtml(original, modified, options) {
|
|
172
|
+
const originalBytes = await toBytes(original);
|
|
173
|
+
const modifiedBytes = await toBytes(modified);
|
|
174
|
+
const response = await sendRequest({
|
|
175
|
+
id: generateId(),
|
|
176
|
+
type: "compareDocumentsToHtml",
|
|
177
|
+
originalBytes,
|
|
178
|
+
modifiedBytes,
|
|
179
|
+
options,
|
|
180
|
+
}, [originalBytes.buffer, modifiedBytes.buffer]);
|
|
181
|
+
return response.html;
|
|
182
|
+
},
|
|
183
|
+
async getRevisions(document, options) {
|
|
184
|
+
const bytes = await toBytes(document);
|
|
185
|
+
const response = await sendRequest({
|
|
186
|
+
id: generateId(),
|
|
187
|
+
type: "getRevisions",
|
|
188
|
+
documentBytes: bytes,
|
|
189
|
+
options,
|
|
190
|
+
}, [bytes.buffer]);
|
|
191
|
+
return response.revisions;
|
|
192
|
+
},
|
|
193
|
+
async getDocumentMetadata(document) {
|
|
194
|
+
const bytes = await toBytes(document);
|
|
195
|
+
const response = await sendRequest({
|
|
196
|
+
id: generateId(),
|
|
197
|
+
type: "getDocumentMetadata",
|
|
198
|
+
documentBytes: bytes,
|
|
199
|
+
}, [bytes.buffer]);
|
|
200
|
+
return response.metadata;
|
|
201
|
+
},
|
|
202
|
+
async getVersion() {
|
|
203
|
+
const response = await sendRequest({
|
|
204
|
+
id: generateId(),
|
|
205
|
+
type: "getVersion",
|
|
206
|
+
});
|
|
207
|
+
return response.version;
|
|
208
|
+
},
|
|
209
|
+
terminate() {
|
|
210
|
+
isWorkerActive = false;
|
|
211
|
+
worker.terminate();
|
|
212
|
+
// Reject any pending requests
|
|
213
|
+
for (const pending of pendingRequests.values()) {
|
|
214
|
+
pending.reject(new Error("Worker terminated"));
|
|
215
|
+
}
|
|
216
|
+
pendingRequests.clear();
|
|
217
|
+
},
|
|
218
|
+
isActive() {
|
|
219
|
+
return isWorkerActive;
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Check if Web Workers are supported in the current environment.
|
|
225
|
+
*/
|
|
226
|
+
export function isWorkerSupported() {
|
|
227
|
+
return typeof Worker !== "undefined";
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=worker-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-proxy.js","sourceRoot":"","sources":["../src/worker-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoBH;;GAEG;AACH,SAAS,UAAU;IACjB,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AACpE,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,OAAO,CAAC,QAA2B;IAChD,IAAI,QAAQ,YAAY,UAAU,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC5C,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB;IACzB,uDAAuD;IACvD,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACpC,gEAAgE;QAChE,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,CAAC;QACrE,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvB,MAAM,GAAG,GAAI,OAAO,CAAC,CAAC,CAAuB,CAAC,GAAG,CAAC;YAClD,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,OAAO,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EAAE,CAAC;gBAC/C,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;YACjD,CAAC;YACD,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QAED,QAAQ;YACN,OAAO,cAAc,CAAC;QACxB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docxodus",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "DOCX document comparison and HTML conversion in the browser using WebAssembly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"./react": {
|
|
15
15
|
"import": "./dist/react.js",
|
|
16
16
|
"types": "./dist/react.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./worker": {
|
|
19
|
+
"import": "./dist/worker-proxy.js",
|
|
20
|
+
"types": "./dist/worker-proxy.d.ts"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
@@ -23,8 +27,9 @@
|
|
|
23
27
|
"build:wasm": "../scripts/build-wasm.sh",
|
|
24
28
|
"build:ts": "tsc",
|
|
25
29
|
"build:pagination-bundle": "esbuild src/pagination.ts --bundle --format=iife --global-name=DocxodusPagination --outfile=dist/pagination.bundle.js",
|
|
26
|
-
"build": "
|
|
27
|
-
"
|
|
30
|
+
"build:worker-bundle": "esbuild src/docxodus.worker.ts --bundle --format=esm --outfile=dist/docxodus.worker.js && esbuild src/worker-proxy.ts --bundle --format=esm --outfile=dist/worker-proxy.bundle.js",
|
|
31
|
+
"build": "npm run build:wasm && npm run build:ts && npm run build:pagination-bundle && npm run build:worker-bundle",
|
|
32
|
+
"pretest": "cp tests/test-harness.html dist/wasm/ && cp tests/worker-test-harness.html dist/wasm/ && cp dist/pagination.bundle.js dist/wasm/ && cp dist/docxodus.worker.js dist/wasm/ && cp dist/worker-proxy.bundle.js dist/wasm/worker-proxy.js",
|
|
28
33
|
"test": "playwright test",
|
|
29
34
|
"test:ui": "playwright test --ui",
|
|
30
35
|
"prepublishOnly": "npm run build"
|