docxodus 0.1.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 +209 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +188 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +134 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +262 -0
- package/dist/react.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/wasm/_framework/DocumentFormat.OpenXml.Framework.wasm +0 -0
- package/dist/wasm/_framework/DocumentFormat.OpenXml.wasm +0 -0
- package/dist/wasm/_framework/Docxodus.pdb +0 -0
- package/dist/wasm/_framework/Docxodus.wasm +0 -0
- package/dist/wasm/_framework/DocxodusWasm.pdb +0 -0
- package/dist/wasm/_framework/DocxodusWasm.wasm +0 -0
- package/dist/wasm/_framework/Microsoft.CSharp.wasm +0 -0
- package/dist/wasm/_framework/Microsoft.VisualBasic.Core.wasm +0 -0
- package/dist/wasm/_framework/Microsoft.VisualBasic.wasm +0 -0
- package/dist/wasm/_framework/Microsoft.Win32.Primitives.wasm +0 -0
- package/dist/wasm/_framework/Microsoft.Win32.Registry.wasm +0 -0
- package/dist/wasm/_framework/SkiaSharp.pdb +0 -0
- package/dist/wasm/_framework/SkiaSharp.wasm +0 -0
- package/dist/wasm/_framework/System.AppContext.wasm +0 -0
- package/dist/wasm/_framework/System.Buffers.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.Concurrent.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.Immutable.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.NonGeneric.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.Specialized.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.Annotations.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.DataAnnotations.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.EventBasedAsync.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.TypeConverter.wasm +0 -0
- package/dist/wasm/_framework/System.ComponentModel.wasm +0 -0
- package/dist/wasm/_framework/System.Configuration.wasm +0 -0
- package/dist/wasm/_framework/System.Console.wasm +0 -0
- package/dist/wasm/_framework/System.Core.wasm +0 -0
- package/dist/wasm/_framework/System.Data.Common.wasm +0 -0
- package/dist/wasm/_framework/System.Data.DataSetExtensions.wasm +0 -0
- package/dist/wasm/_framework/System.Data.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Contracts.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Debug.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.FileVersionInfo.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Process.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.StackTrace.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Tools.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.TraceSource.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Tracing.wasm +0 -0
- package/dist/wasm/_framework/System.Drawing.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.Drawing.wasm +0 -0
- package/dist/wasm/_framework/System.Dynamic.Runtime.wasm +0 -0
- package/dist/wasm/_framework/System.Formats.Asn1.wasm +0 -0
- package/dist/wasm/_framework/System.Formats.Tar.wasm +0 -0
- package/dist/wasm/_framework/System.Globalization.Calendars.wasm +0 -0
- package/dist/wasm/_framework/System.Globalization.Extensions.wasm +0 -0
- package/dist/wasm/_framework/System.Globalization.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.Brotli.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.FileSystem.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.ZipFile.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.wasm +0 -0
- package/dist/wasm/_framework/System.IO.FileSystem.AccessControl.wasm +0 -0
- package/dist/wasm/_framework/System.IO.FileSystem.DriveInfo.wasm +0 -0
- package/dist/wasm/_framework/System.IO.FileSystem.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.IO.FileSystem.Watcher.wasm +0 -0
- package/dist/wasm/_framework/System.IO.FileSystem.wasm +0 -0
- package/dist/wasm/_framework/System.IO.IsolatedStorage.wasm +0 -0
- package/dist/wasm/_framework/System.IO.MemoryMappedFiles.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Packaging.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Pipes.AccessControl.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Pipes.wasm +0 -0
- package/dist/wasm/_framework/System.IO.UnmanagedMemoryStream.wasm +0 -0
- package/dist/wasm/_framework/System.IO.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.Expressions.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.Parallel.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.Queryable.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.wasm +0 -0
- package/dist/wasm/_framework/System.Memory.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Http.Json.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Http.wasm +0 -0
- package/dist/wasm/_framework/System.Net.HttpListener.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Mail.wasm +0 -0
- package/dist/wasm/_framework/System.Net.NameResolution.wasm +0 -0
- package/dist/wasm/_framework/System.Net.NetworkInformation.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Ping.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Quic.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Requests.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Security.wasm +0 -0
- package/dist/wasm/_framework/System.Net.ServicePoint.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Sockets.wasm +0 -0
- package/dist/wasm/_framework/System.Net.WebClient.wasm +0 -0
- package/dist/wasm/_framework/System.Net.WebHeaderCollection.wasm +0 -0
- package/dist/wasm/_framework/System.Net.WebProxy.wasm +0 -0
- package/dist/wasm/_framework/System.Net.WebSockets.Client.wasm +0 -0
- package/dist/wasm/_framework/System.Net.WebSockets.wasm +0 -0
- package/dist/wasm/_framework/System.Net.wasm +0 -0
- package/dist/wasm/_framework/System.Numerics.Vectors.wasm +0 -0
- package/dist/wasm/_framework/System.Numerics.wasm +0 -0
- package/dist/wasm/_framework/System.ObjectModel.wasm +0 -0
- package/dist/wasm/_framework/System.Private.CoreLib.wasm +0 -0
- package/dist/wasm/_framework/System.Private.DataContractSerialization.wasm +0 -0
- package/dist/wasm/_framework/System.Private.Uri.wasm +0 -0
- package/dist/wasm/_framework/System.Private.Xml.Linq.wasm +0 -0
- package/dist/wasm/_framework/System.Private.Xml.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.DispatchProxy.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Emit.ILGeneration.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Emit.Lightweight.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Emit.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Extensions.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Metadata.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.TypeExtensions.wasm +0 -0
- package/dist/wasm/_framework/System.Reflection.wasm +0 -0
- package/dist/wasm/_framework/System.Resources.Reader.wasm +0 -0
- package/dist/wasm/_framework/System.Resources.ResourceManager.wasm +0 -0
- package/dist/wasm/_framework/System.Resources.Writer.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.CompilerServices.VisualC.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Extensions.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Handles.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.InteropServices.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Intrinsics.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Loader.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Numerics.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Serialization.Formatters.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Serialization.Json.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Serialization.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Serialization.Xml.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.Serialization.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.wasm +0 -0
- package/dist/wasm/_framework/System.Security.AccessControl.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Claims.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.Algorithms.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.Cng.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.Csp.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.Encoding.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.OpenSsl.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.Primitives.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.X509Certificates.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Principal.Windows.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Principal.wasm +0 -0
- package/dist/wasm/_framework/System.Security.SecureString.wasm +0 -0
- package/dist/wasm/_framework/System.Security.wasm +0 -0
- package/dist/wasm/_framework/System.ServiceModel.Web.wasm +0 -0
- package/dist/wasm/_framework/System.ServiceProcess.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Encoding.CodePages.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Encoding.Extensions.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Encoding.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Encodings.Web.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Json.wasm +0 -0
- package/dist/wasm/_framework/System.Text.RegularExpressions.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Channels.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Overlapped.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Tasks.Dataflow.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Tasks.Extensions.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Tasks.Parallel.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Tasks.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Thread.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.ThreadPool.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.Timer.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.wasm +0 -0
- package/dist/wasm/_framework/System.Transactions.Local.wasm +0 -0
- package/dist/wasm/_framework/System.Transactions.wasm +0 -0
- package/dist/wasm/_framework/System.ValueTuple.wasm +0 -0
- package/dist/wasm/_framework/System.Web.HttpUtility.wasm +0 -0
- package/dist/wasm/_framework/System.Web.wasm +0 -0
- package/dist/wasm/_framework/System.Windows.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.Linq.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.ReaderWriter.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.Serialization.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.XDocument.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.XPath.XDocument.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.XPath.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.XmlDocument.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.XmlSerializer.wasm +0 -0
- package/dist/wasm/_framework/System.Xml.wasm +0 -0
- package/dist/wasm/_framework/System.wasm +0 -0
- package/dist/wasm/_framework/WindowsBase.wasm +0 -0
- package/dist/wasm/_framework/blazor.boot.json +206 -0
- package/dist/wasm/_framework/dotnet.js +4 -0
- package/dist/wasm/_framework/dotnet.js.map +1 -0
- package/dist/wasm/_framework/dotnet.native.js +17 -0
- package/dist/wasm/_framework/dotnet.native.js.symbols +18688 -0
- package/dist/wasm/_framework/dotnet.native.wasm +0 -0
- package/dist/wasm/_framework/dotnet.runtime.js +4 -0
- package/dist/wasm/_framework/dotnet.runtime.js.map +1 -0
- package/dist/wasm/_framework/mscorlib.wasm +0 -0
- package/dist/wasm/_framework/netstandard.wasm +0 -0
- package/dist/wasm/_framework/supportFiles/0_runtimeconfig.bin +1 -0
- package/dist/wasm/index.html +237 -0
- package/dist/wasm/main.js +26 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Docxodus
|
|
2
|
+
|
|
3
|
+
DOCX document comparison and HTML conversion in the browser using WebAssembly.
|
|
4
|
+
|
|
5
|
+
Docxodus brings professional-grade document comparison (redlining) to JavaScript applications. Compare two Word documents and get tracked changes, or convert DOCX files to HTML - all running entirely in the browser with no server required.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Document Comparison**: Compare two DOCX files and generate a redlined document with tracked changes
|
|
10
|
+
- **HTML Conversion**: Convert DOCX documents to HTML for display in the browser
|
|
11
|
+
- **Revision Extraction**: Get structured data about all revisions in a compared document
|
|
12
|
+
- **100% Client-Side**: All processing happens in the browser using WebAssembly
|
|
13
|
+
- **React Hooks**: Ready-to-use hooks for React applications
|
|
14
|
+
- **TypeScript Support**: Full type definitions included
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install docxodus
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### Basic Usage
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
import { initialize, convertDocxToHtml, compareDocuments } from 'docxodus';
|
|
28
|
+
|
|
29
|
+
// Initialize the WASM runtime (call once at app startup)
|
|
30
|
+
await initialize('/path/to/wasm/');
|
|
31
|
+
|
|
32
|
+
// Convert DOCX to HTML
|
|
33
|
+
const html = await convertDocxToHtml(docxFile);
|
|
34
|
+
|
|
35
|
+
// Compare two documents
|
|
36
|
+
const redlinedDocx = await compareDocuments(originalFile, modifiedFile, {
|
|
37
|
+
authorName: 'Reviewer'
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### React Usage
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useDocxodus, useConversion, useComparison } from 'docxodus/react';
|
|
45
|
+
|
|
46
|
+
function DocumentViewer() {
|
|
47
|
+
const { isReady, isLoading, error, convertToHtml } = useDocxodus('/wasm/');
|
|
48
|
+
const [html, setHtml] = useState('');
|
|
49
|
+
|
|
50
|
+
const handleFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
51
|
+
const file = e.target.files?.[0];
|
|
52
|
+
if (file && isReady) {
|
|
53
|
+
const result = await convertToHtml(file);
|
|
54
|
+
setHtml(result);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (isLoading) return <div>Loading...</div>;
|
|
59
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<div>
|
|
63
|
+
<input type="file" accept=".docx" onChange={handleFile} />
|
|
64
|
+
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using the Comparison Hook
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { useComparison } from 'docxodus/react';
|
|
74
|
+
|
|
75
|
+
function DocumentComparer() {
|
|
76
|
+
const {
|
|
77
|
+
html,
|
|
78
|
+
isComparing,
|
|
79
|
+
error,
|
|
80
|
+
compareToHtml,
|
|
81
|
+
downloadResult
|
|
82
|
+
} = useComparison('/wasm/');
|
|
83
|
+
|
|
84
|
+
const handleCompare = async (original: File, modified: File) => {
|
|
85
|
+
await compareToHtml(original, modified, { authorName: 'Legal Team' });
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div>
|
|
90
|
+
{isComparing && <p>Comparing...</p>}
|
|
91
|
+
{error && <p>Error: {error.message}</p>}
|
|
92
|
+
{html && <div dangerouslySetInnerHTML={{ __html: html }} />}
|
|
93
|
+
<button onClick={() => downloadResult('comparison.docx')}>
|
|
94
|
+
Download Redlined DOCX
|
|
95
|
+
</button>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## API Reference
|
|
102
|
+
|
|
103
|
+
### Core Functions
|
|
104
|
+
|
|
105
|
+
#### `initialize(basePath?: string): Promise<void>`
|
|
106
|
+
Initialize the WASM runtime. Must be called before using any other functions.
|
|
107
|
+
|
|
108
|
+
#### `convertDocxToHtml(document: File | Uint8Array, options?: ConversionOptions): Promise<string>`
|
|
109
|
+
Convert a DOCX document to HTML.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
interface ConversionOptions {
|
|
113
|
+
pageTitle?: string; // HTML document title
|
|
114
|
+
cssPrefix?: string; // CSS class prefix (default: "docx-")
|
|
115
|
+
fabricateClasses?: boolean; // Generate CSS classes (default: true)
|
|
116
|
+
additionalCss?: string; // Extra CSS to include
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### `compareDocuments(original, modified, options?): Promise<Uint8Array>`
|
|
121
|
+
Compare two DOCX documents and return a redlined DOCX with tracked changes.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
interface CompareOptions {
|
|
125
|
+
authorName?: string; // Author name for revisions (default: "Docxodus")
|
|
126
|
+
detailThreshold?: number; // 0.0-1.0, lower = more detailed (default: 0.15)
|
|
127
|
+
caseInsensitive?: boolean; // Case-insensitive comparison (default: false)
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### `compareDocumentsToHtml(original, modified, options?): Promise<string>`
|
|
132
|
+
Compare documents and return the result as HTML.
|
|
133
|
+
|
|
134
|
+
#### `getRevisions(document: File | Uint8Array): Promise<Revision[]>`
|
|
135
|
+
Extract revision information from a compared document.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
interface Revision {
|
|
139
|
+
author: string;
|
|
140
|
+
date: string;
|
|
141
|
+
revisionType: string; // "Insertion", "Deletion", etc.
|
|
142
|
+
text: string;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### React Hooks
|
|
147
|
+
|
|
148
|
+
#### `useDocxodus(wasmBasePath?: string)`
|
|
149
|
+
Main hook providing all Docxodus functionality.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
- `isReady: boolean` - Whether WASM is loaded
|
|
153
|
+
- `isLoading: boolean` - Whether WASM is loading
|
|
154
|
+
- `error: Error | null` - Initialization error
|
|
155
|
+
- `convertToHtml()` - Convert DOCX to HTML
|
|
156
|
+
- `compare()` - Compare documents
|
|
157
|
+
- `compareToHtml()` - Compare and get HTML
|
|
158
|
+
- `getRevisions()` - Get revision list
|
|
159
|
+
|
|
160
|
+
#### `useConversion(wasmBasePath?: string)`
|
|
161
|
+
Simplified hook for DOCX to HTML conversion with state management.
|
|
162
|
+
|
|
163
|
+
#### `useComparison(wasmBasePath?: string)`
|
|
164
|
+
Simplified hook for document comparison with state management.
|
|
165
|
+
|
|
166
|
+
## Hosting WASM Files
|
|
167
|
+
|
|
168
|
+
The WASM files need to be served from your web server. After building:
|
|
169
|
+
|
|
170
|
+
1. Copy the contents of `dist/wasm/` to your public directory
|
|
171
|
+
2. Pass the path to `initialize()` or the React hooks
|
|
172
|
+
|
|
173
|
+
Example directory structure:
|
|
174
|
+
```
|
|
175
|
+
public/
|
|
176
|
+
wasm/
|
|
177
|
+
_framework/
|
|
178
|
+
dotnet.js
|
|
179
|
+
dotnet.native.wasm
|
|
180
|
+
... (other framework files)
|
|
181
|
+
main.js
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Bundle Size
|
|
185
|
+
|
|
186
|
+
| Component | Size (uncompressed) | Size (Brotli) |
|
|
187
|
+
|-----------|---------------------|---------------|
|
|
188
|
+
| dotnet.native.wasm | ~8 MB | ~3 MB |
|
|
189
|
+
| Managed assemblies | ~15 MB | ~5 MB |
|
|
190
|
+
| Total | ~37 MB | ~10-12 MB |
|
|
191
|
+
|
|
192
|
+
The WASM files are loaded on-demand and cached by the browser.
|
|
193
|
+
|
|
194
|
+
## Browser Support
|
|
195
|
+
|
|
196
|
+
- Chrome 89+
|
|
197
|
+
- Firefox 89+
|
|
198
|
+
- Safari 15+
|
|
199
|
+
- Edge 89+
|
|
200
|
+
|
|
201
|
+
Requires WebAssembly SIMD support.
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|
|
206
|
+
|
|
207
|
+
## Credits
|
|
208
|
+
|
|
209
|
+
Built on [Docxodus](https://github.com/JSv4/Redlines), a .NET library for document manipulation based on OpenXML-PowerTools.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult } from "./types.js";
|
|
2
|
+
export type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult, };
|
|
3
|
+
/**
|
|
4
|
+
* Get the path to the WASM files directory.
|
|
5
|
+
* Override this if you're hosting WASM files at a custom location.
|
|
6
|
+
*/
|
|
7
|
+
export declare let wasmBasePath: string;
|
|
8
|
+
/**
|
|
9
|
+
* Set custom base path for WASM files
|
|
10
|
+
*/
|
|
11
|
+
export declare function setWasmBasePath(path: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* Initialize the Docxodus WASM runtime.
|
|
14
|
+
* Must be called before using any conversion/comparison functions.
|
|
15
|
+
* Safe to call multiple times - will only initialize once.
|
|
16
|
+
*/
|
|
17
|
+
export declare function initialize(basePath?: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Convert a DOCX document to HTML.
|
|
20
|
+
*
|
|
21
|
+
* @param document - DOCX file as File object or Uint8Array
|
|
22
|
+
* @param options - Conversion options
|
|
23
|
+
* @returns HTML string
|
|
24
|
+
* @throws Error if conversion fails
|
|
25
|
+
*/
|
|
26
|
+
export declare function convertDocxToHtml(document: File | Uint8Array, options?: ConversionOptions): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Compare two DOCX documents and return the redlined result as a DOCX.
|
|
29
|
+
*
|
|
30
|
+
* @param original - Original DOCX document
|
|
31
|
+
* @param modified - Modified DOCX document
|
|
32
|
+
* @param options - Comparison options
|
|
33
|
+
* @returns Redlined DOCX as Uint8Array
|
|
34
|
+
* @throws Error if comparison fails
|
|
35
|
+
*/
|
|
36
|
+
export declare function compareDocuments(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<Uint8Array>;
|
|
37
|
+
/**
|
|
38
|
+
* Compare two DOCX documents and return the result as HTML.
|
|
39
|
+
*
|
|
40
|
+
* @param original - Original DOCX document
|
|
41
|
+
* @param modified - Modified DOCX document
|
|
42
|
+
* @param options - Comparison options
|
|
43
|
+
* @returns HTML string with redlined content
|
|
44
|
+
* @throws Error if comparison fails
|
|
45
|
+
*/
|
|
46
|
+
export declare function compareDocumentsToHtml(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Get revisions from a compared document.
|
|
49
|
+
*
|
|
50
|
+
* @param document - A document that has been through comparison (has tracked changes)
|
|
51
|
+
* @returns Array of revisions
|
|
52
|
+
* @throws Error if operation fails
|
|
53
|
+
*/
|
|
54
|
+
export declare function getRevisions(document: File | Uint8Array): Promise<Revision[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Get version information about the library.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getVersion(): VersionInfo;
|
|
59
|
+
/**
|
|
60
|
+
* Check if the WASM runtime is initialized.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isInitialized(): boolean;
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,EAEd,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,GACd,CAAC;AAKF;;;GAGG;AACH,eAAO,IAAI,YAAY,QAAK,CAAC;AAE7B;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAElD;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAajE;AA0DD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAwBjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,UAAU,CAAC,CA4BrB;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,QAAQ,EAAE,IAAI,GAAG,UAAU,EAC3B,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,IAAI,GAAG,UAAU,GAC1B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAkBrB;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,WAAW,CASxC;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
let wasmExports = null;
|
|
2
|
+
let initPromise = null;
|
|
3
|
+
/**
|
|
4
|
+
* Get the path to the WASM files directory.
|
|
5
|
+
* Override this if you're hosting WASM files at a custom location.
|
|
6
|
+
*/
|
|
7
|
+
export let wasmBasePath = "";
|
|
8
|
+
/**
|
|
9
|
+
* Set custom base path for WASM files
|
|
10
|
+
*/
|
|
11
|
+
export function setWasmBasePath(path) {
|
|
12
|
+
wasmBasePath = path.endsWith("/") ? path : path + "/";
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the Docxodus WASM runtime.
|
|
16
|
+
* Must be called before using any conversion/comparison functions.
|
|
17
|
+
* Safe to call multiple times - will only initialize once.
|
|
18
|
+
*/
|
|
19
|
+
export async function initialize(basePath) {
|
|
20
|
+
if (wasmExports)
|
|
21
|
+
return;
|
|
22
|
+
if (initPromise) {
|
|
23
|
+
return initPromise;
|
|
24
|
+
}
|
|
25
|
+
if (basePath) {
|
|
26
|
+
setWasmBasePath(basePath);
|
|
27
|
+
}
|
|
28
|
+
initPromise = loadWasm();
|
|
29
|
+
return initPromise;
|
|
30
|
+
}
|
|
31
|
+
async function loadWasm() {
|
|
32
|
+
const dotnetPath = wasmBasePath + "_framework/dotnet.js";
|
|
33
|
+
const { dotnet } = await import(/* webpackIgnore: true */ dotnetPath);
|
|
34
|
+
const { getAssemblyExports, getConfig } = await dotnet
|
|
35
|
+
.withDiagnosticTracing(false)
|
|
36
|
+
.create();
|
|
37
|
+
const config = getConfig();
|
|
38
|
+
const exports = await getAssemblyExports(config.mainAssemblyName);
|
|
39
|
+
wasmExports = {
|
|
40
|
+
DocumentConverter: exports.DocxodusWasm.DocumentConverter,
|
|
41
|
+
DocumentComparer: exports.DocxodusWasm.DocumentComparer,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ensureInitialized() {
|
|
45
|
+
if (!wasmExports) {
|
|
46
|
+
throw new Error("Docxodus not initialized. Call initialize() first and await it.");
|
|
47
|
+
}
|
|
48
|
+
return wasmExports;
|
|
49
|
+
}
|
|
50
|
+
function isErrorResponse(result) {
|
|
51
|
+
try {
|
|
52
|
+
const parsed = JSON.parse(result);
|
|
53
|
+
return typeof parsed === "object" && "Error" in parsed;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function parseError(result) {
|
|
60
|
+
const parsed = JSON.parse(result);
|
|
61
|
+
return {
|
|
62
|
+
error: parsed.Error || parsed.error,
|
|
63
|
+
type: parsed.Type || parsed.type,
|
|
64
|
+
stackTrace: parsed.StackTrace || parsed.stackTrace,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Convert a File or Uint8Array to Uint8Array
|
|
69
|
+
*/
|
|
70
|
+
async function toBytes(input) {
|
|
71
|
+
if (input instanceof Uint8Array) {
|
|
72
|
+
return input;
|
|
73
|
+
}
|
|
74
|
+
const buffer = await input.arrayBuffer();
|
|
75
|
+
return new Uint8Array(buffer);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Convert a DOCX document to HTML.
|
|
79
|
+
*
|
|
80
|
+
* @param document - DOCX file as File object or Uint8Array
|
|
81
|
+
* @param options - Conversion options
|
|
82
|
+
* @returns HTML string
|
|
83
|
+
* @throws Error if conversion fails
|
|
84
|
+
*/
|
|
85
|
+
export async function convertDocxToHtml(document, options) {
|
|
86
|
+
const exports = ensureInitialized();
|
|
87
|
+
const bytes = await toBytes(document);
|
|
88
|
+
let result;
|
|
89
|
+
if (options) {
|
|
90
|
+
result = exports.DocumentConverter.ConvertDocxToHtmlWithOptions(bytes, options.pageTitle ?? "Document", options.cssPrefix ?? "docx-", options.fabricateClasses ?? true, options.additionalCss ?? "");
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
result = exports.DocumentConverter.ConvertDocxToHtml(bytes);
|
|
94
|
+
}
|
|
95
|
+
if (isErrorResponse(result)) {
|
|
96
|
+
const error = parseError(result);
|
|
97
|
+
throw new Error(`Conversion failed: ${error.error}`);
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Compare two DOCX documents and return the redlined result as a DOCX.
|
|
103
|
+
*
|
|
104
|
+
* @param original - Original DOCX document
|
|
105
|
+
* @param modified - Modified DOCX document
|
|
106
|
+
* @param options - Comparison options
|
|
107
|
+
* @returns Redlined DOCX as Uint8Array
|
|
108
|
+
* @throws Error if comparison fails
|
|
109
|
+
*/
|
|
110
|
+
export async function compareDocuments(original, modified, options) {
|
|
111
|
+
const exports = ensureInitialized();
|
|
112
|
+
const originalBytes = await toBytes(original);
|
|
113
|
+
const modifiedBytes = await toBytes(modified);
|
|
114
|
+
let result;
|
|
115
|
+
if (options?.detailThreshold !== undefined || options?.caseInsensitive) {
|
|
116
|
+
result = exports.DocumentComparer.CompareDocumentsWithOptions(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus", options?.detailThreshold ?? 0.15, options?.caseInsensitive ?? false);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
result = exports.DocumentComparer.CompareDocuments(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus");
|
|
120
|
+
}
|
|
121
|
+
if (result.length === 0) {
|
|
122
|
+
throw new Error("Comparison failed - empty result");
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Compare two DOCX documents and return the result as HTML.
|
|
128
|
+
*
|
|
129
|
+
* @param original - Original DOCX document
|
|
130
|
+
* @param modified - Modified DOCX document
|
|
131
|
+
* @param options - Comparison options
|
|
132
|
+
* @returns HTML string with redlined content
|
|
133
|
+
* @throws Error if comparison fails
|
|
134
|
+
*/
|
|
135
|
+
export async function compareDocumentsToHtml(original, modified, options) {
|
|
136
|
+
const exports = ensureInitialized();
|
|
137
|
+
const originalBytes = await toBytes(original);
|
|
138
|
+
const modifiedBytes = await toBytes(modified);
|
|
139
|
+
const result = exports.DocumentComparer.CompareDocumentsToHtml(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus");
|
|
140
|
+
if (isErrorResponse(result)) {
|
|
141
|
+
const error = parseError(result);
|
|
142
|
+
throw new Error(`Comparison failed: ${error.error}`);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get revisions from a compared document.
|
|
148
|
+
*
|
|
149
|
+
* @param document - A document that has been through comparison (has tracked changes)
|
|
150
|
+
* @returns Array of revisions
|
|
151
|
+
* @throws Error if operation fails
|
|
152
|
+
*/
|
|
153
|
+
export async function getRevisions(document) {
|
|
154
|
+
const exports = ensureInitialized();
|
|
155
|
+
const bytes = await toBytes(document);
|
|
156
|
+
const result = exports.DocumentComparer.GetRevisionsJson(bytes);
|
|
157
|
+
if (isErrorResponse(result)) {
|
|
158
|
+
const error = parseError(result);
|
|
159
|
+
throw new Error(`Failed to get revisions: ${error.error}`);
|
|
160
|
+
}
|
|
161
|
+
const parsed = JSON.parse(result);
|
|
162
|
+
return (parsed.Revisions || parsed.revisions || []).map((r) => ({
|
|
163
|
+
author: r.Author || r.author,
|
|
164
|
+
date: r.Date || r.date,
|
|
165
|
+
revisionType: r.RevisionType || r.revisionType,
|
|
166
|
+
text: r.Text || r.text,
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Get version information about the library.
|
|
171
|
+
*/
|
|
172
|
+
export function getVersion() {
|
|
173
|
+
const exports = ensureInitialized();
|
|
174
|
+
const result = exports.DocumentConverter.GetVersion();
|
|
175
|
+
const parsed = JSON.parse(result);
|
|
176
|
+
return {
|
|
177
|
+
library: parsed.Library || parsed.library,
|
|
178
|
+
dotnetVersion: parsed.DotnetVersion || parsed.dotnetVersion,
|
|
179
|
+
platform: parsed.Platform || parsed.platform,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Check if the WASM runtime is initialized.
|
|
184
|
+
*/
|
|
185
|
+
export function isInitialized() {
|
|
186
|
+
return wasmExports !== null;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,IAAI,WAAW,GAA+B,IAAI,CAAC;AACnD,IAAI,WAAW,GAAyB,IAAI,CAAC;AAE7C;;;GAGG;AACH,MAAM,CAAC,IAAI,YAAY,GAAG,EAAE,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAiB;IAChD,IAAI,WAAW;QAAE,OAAO;IA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AI;KACvB,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC;IACpC,MAAM,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO;QACzC,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,aAAa;QAC3D,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ;KAC7C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,KAAK,IAAI,CAAC;AAC9B,CAAC"}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { ConversionOptions, CompareOptions, Revision } from "./types.js";
|
|
2
|
+
export type { ConversionOptions, CompareOptions, Revision };
|
|
3
|
+
export interface UseDocxodusResult {
|
|
4
|
+
/** Whether the WASM runtime is loaded and ready */
|
|
5
|
+
isReady: boolean;
|
|
6
|
+
/** Whether the runtime is currently loading */
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
/** Error that occurred during initialization, if any */
|
|
9
|
+
error: Error | null;
|
|
10
|
+
/** Convert DOCX to HTML */
|
|
11
|
+
convertToHtml: (document: File | Uint8Array, options?: ConversionOptions) => Promise<string>;
|
|
12
|
+
/** Compare two documents and return redlined DOCX */
|
|
13
|
+
compare: (original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions) => Promise<Uint8Array>;
|
|
14
|
+
/** Compare two documents and return HTML */
|
|
15
|
+
compareToHtml: (original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions) => Promise<string>;
|
|
16
|
+
/** Get revisions from a compared document */
|
|
17
|
+
getRevisions: (document: File | Uint8Array) => Promise<Revision[]>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* React hook for using Docxodus WASM functionality.
|
|
21
|
+
* Automatically initializes the WASM runtime on mount.
|
|
22
|
+
*
|
|
23
|
+
* @param wasmBasePath - Optional base path to WASM files
|
|
24
|
+
* @returns Object with ready state and document functions
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* function App() {
|
|
29
|
+
* const { isReady, isLoading, error, convertToHtml } = useDocxodus('/wasm/');
|
|
30
|
+
*
|
|
31
|
+
* const handleFile = async (file: File) => {
|
|
32
|
+
* if (!isReady) return;
|
|
33
|
+
* const html = await convertToHtml(file);
|
|
34
|
+
* setHtml(html);
|
|
35
|
+
* };
|
|
36
|
+
*
|
|
37
|
+
* if (isLoading) return <div>Loading WASM...</div>;
|
|
38
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
39
|
+
*
|
|
40
|
+
* return <input type="file" onChange={e => handleFile(e.target.files[0])} />;
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function useDocxodus(wasmBasePath?: string): UseDocxodusResult;
|
|
45
|
+
export interface UseConversionResult {
|
|
46
|
+
/** The converted HTML output */
|
|
47
|
+
html: string | null;
|
|
48
|
+
/** Whether a conversion is in progress */
|
|
49
|
+
isConverting: boolean;
|
|
50
|
+
/** Error from the last conversion attempt */
|
|
51
|
+
error: Error | null;
|
|
52
|
+
/** Convert a DOCX file to HTML */
|
|
53
|
+
convert: (document: File | Uint8Array, options?: ConversionOptions) => Promise<void>;
|
|
54
|
+
/** Clear the current result */
|
|
55
|
+
clear: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* React hook for DOCX to HTML conversion with state management.
|
|
59
|
+
*
|
|
60
|
+
* @param wasmBasePath - Optional base path to WASM files
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* function Converter() {
|
|
65
|
+
* const { html, isConverting, error, convert } = useConversion('/wasm/');
|
|
66
|
+
*
|
|
67
|
+
* return (
|
|
68
|
+
* <div>
|
|
69
|
+
* <input
|
|
70
|
+
* type="file"
|
|
71
|
+
* accept=".docx"
|
|
72
|
+
* onChange={e => e.target.files?.[0] && convert(e.target.files[0])}
|
|
73
|
+
* disabled={isConverting}
|
|
74
|
+
* />
|
|
75
|
+
* {isConverting && <p>Converting...</p>}
|
|
76
|
+
* {error && <p>Error: {error.message}</p>}
|
|
77
|
+
* {html && <div dangerouslySetInnerHTML={{ __html: html }} />}
|
|
78
|
+
* </div>
|
|
79
|
+
* );
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function useConversion(wasmBasePath?: string): UseConversionResult;
|
|
84
|
+
export interface UseComparisonResult {
|
|
85
|
+
/** The comparison result as a Uint8Array (redlined DOCX) */
|
|
86
|
+
result: Uint8Array | null;
|
|
87
|
+
/** The comparison result as HTML (if compareToHtml was used) */
|
|
88
|
+
html: string | null;
|
|
89
|
+
/** Revisions extracted from the comparison */
|
|
90
|
+
revisions: Revision[] | null;
|
|
91
|
+
/** Whether a comparison is in progress */
|
|
92
|
+
isComparing: boolean;
|
|
93
|
+
/** Error from the last comparison attempt */
|
|
94
|
+
error: Error | null;
|
|
95
|
+
/** Compare two documents and get redlined DOCX */
|
|
96
|
+
compare: (original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions) => Promise<void>;
|
|
97
|
+
/** Compare two documents and get HTML */
|
|
98
|
+
compareToHtml: (original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions) => Promise<void>;
|
|
99
|
+
/** Clear all results */
|
|
100
|
+
clear: () => void;
|
|
101
|
+
/** Download the result as a DOCX file */
|
|
102
|
+
downloadResult: (filename?: string) => void;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* React hook for document comparison with state management.
|
|
106
|
+
*
|
|
107
|
+
* @param wasmBasePath - Optional base path to WASM files
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* function Comparer() {
|
|
112
|
+
* const { html, isComparing, error, compareToHtml, downloadResult } = useComparison('/wasm/');
|
|
113
|
+
* const [original, setOriginal] = useState<File | null>(null);
|
|
114
|
+
* const [modified, setModified] = useState<File | null>(null);
|
|
115
|
+
*
|
|
116
|
+
* const handleCompare = () => {
|
|
117
|
+
* if (original && modified) {
|
|
118
|
+
* compareToHtml(original, modified, { authorName: 'User' });
|
|
119
|
+
* }
|
|
120
|
+
* };
|
|
121
|
+
*
|
|
122
|
+
* return (
|
|
123
|
+
* <div>
|
|
124
|
+
* <input type="file" onChange={e => setOriginal(e.target.files?.[0] ?? null)} />
|
|
125
|
+
* <input type="file" onChange={e => setModified(e.target.files?.[0] ?? null)} />
|
|
126
|
+
* <button onClick={handleCompare} disabled={isComparing}>Compare</button>
|
|
127
|
+
* {html && <div dangerouslySetInnerHTML={{ __html: html }} />}
|
|
128
|
+
* </div>
|
|
129
|
+
* );
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function useComparison(wasmBasePath?: string): UseComparisonResult;
|
|
134
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACT,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC;AAE5D,MAAM,WAAW,iBAAiB;IAChC,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;IACjB,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,wDAAwD;IACxD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,2BAA2B;IAC3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