docxodus 5.4.1 → 5.5.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/dist/index.d.ts +171 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +277 -4
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +95 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +33 -0
- 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.Collections.Concurrent.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.NonGeneric.wasm +0 -0
- package/dist/wasm/_framework/System.Collections.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.Console.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/dist/wasm/_framework/System.Diagnostics.Process.wasm +0 -0
- package/dist/wasm/_framework/System.IO.Compression.wasm +0 -0
- package/dist/wasm/_framework/System.Linq.Expressions.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.wasm +0 -0
- package/dist/wasm/_framework/System.Net.Primitives.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.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.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/dist/wasm/_framework/System.Runtime.wasm +0 -0
- package/dist/wasm/_framework/System.Security.Cryptography.wasm +0 -0
- package/dist/wasm/_framework/System.Text.Encoding.Extensions.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.Thread.wasm +0 -0
- package/dist/wasm/_framework/System.Threading.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.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.wasm +0 -0
- package/dist/wasm/_framework/blazor.boot.json +40 -39
- package/dist/wasm/_framework/dotnet.js +1 -1
- package/dist/wasm/_framework/dotnet.js.map +1 -1
- package/dist/wasm/_framework/dotnet.native.js +1 -1
- package/dist/wasm/_framework/dotnet.native.wasm +0 -0
- package/dist/wasm/_framework/dotnet.runtime.js +1 -1
- package/dist/wasm/_framework/dotnet.runtime.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult, GetRevisionsOptions, FormatChangeDetails, Annotation, AddAnnotationRequest, AddAnnotationResponse, RemoveAnnotationResponse, AnnotationOptions, DocumentStructure, DocumentElement, TableColumnInfo, AnnotationTarget, AddAnnotationWithTargetRequest, DocumentMetadata, SectionMetadata, OpenContractDocExport, PawlsPage, PawlsPageBoundary, PawlsToken, OpenContractsAnnotation, OpenContractsSinglePageAnnotation, BoundingBox, TokenId, TextSpan, OpenContractsRelationship, AnnotationLabel, ExternalAnnotationSet, ExternalAnnotationValidationResult, ExternalAnnotationValidationIssue, ExternalAnnotationProjectionSettings } from "./types.js";
|
|
2
|
-
import { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement } from "./types.js";
|
|
1
|
+
import type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult, GetRevisionsOptions, FormatChangeDetails, Annotation, AddAnnotationRequest, AddAnnotationResponse, RemoveAnnotationResponse, AnnotationOptions, DocumentStructure, DocumentElement, TableColumnInfo, AnnotationTarget, AddAnnotationWithTargetRequest, DocumentMetadata, SectionMetadata, OpenContractDocExport, PawlsPage, PawlsPageBoundary, PawlsToken, OpenContractsAnnotation, OpenContractsSinglePageAnnotation, BoundingBox, TokenId, TextSpan, OpenContractsRelationship, AnnotationLabel, ExternalAnnotationSet, ExternalAnnotationValidationResult, ExternalAnnotationValidationIssue, ExternalAnnotationProjectionSettings, ComparisonLogEntry, CompareResultWithLog, CompareToHtmlResultWithLog } from "./types.js";
|
|
2
|
+
import { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, ComparisonLogLevel, ComparisonLogCodes, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement } from "./types.js";
|
|
3
3
|
export type { PageDimensions, MeasuredBlock, PageInfo, PaginationResult, PaginationOptions, } from "./pagination.js";
|
|
4
4
|
export { PaginationEngine, paginateHtml } from "./pagination.js";
|
|
5
|
-
export type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult, GetRevisionsOptions, FormatChangeDetails, Annotation, AddAnnotationRequest, AddAnnotationResponse, RemoveAnnotationResponse, AnnotationOptions, DocumentStructure, DocumentElement, TableColumnInfo, AnnotationTarget, AddAnnotationWithTargetRequest, DocumentMetadata, SectionMetadata, OpenContractDocExport, PawlsPage, PawlsPageBoundary, PawlsToken, OpenContractsAnnotation, OpenContractsSinglePageAnnotation, BoundingBox, TokenId, TextSpan, OpenContractsRelationship, AnnotationLabel, ExternalAnnotationSet, ExternalAnnotationValidationResult, ExternalAnnotationValidationIssue, ExternalAnnotationProjectionSettings, };
|
|
6
|
-
export { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement, };
|
|
5
|
+
export type { ConversionOptions, CompareOptions, Revision, VersionInfo, ErrorResponse, CompareResult, GetRevisionsOptions, FormatChangeDetails, Annotation, AddAnnotationRequest, AddAnnotationResponse, RemoveAnnotationResponse, AnnotationOptions, DocumentStructure, DocumentElement, TableColumnInfo, AnnotationTarget, AddAnnotationWithTargetRequest, DocumentMetadata, SectionMetadata, OpenContractDocExport, PawlsPage, PawlsPageBoundary, PawlsToken, OpenContractsAnnotation, OpenContractsSinglePageAnnotation, BoundingBox, TokenId, TextSpan, OpenContractsRelationship, AnnotationLabel, ExternalAnnotationSet, ExternalAnnotationValidationResult, ExternalAnnotationValidationIssue, ExternalAnnotationProjectionSettings, ComparisonLogEntry, CompareResultWithLog, CompareToHtmlResultWithLog, };
|
|
6
|
+
export { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, ComparisonLogLevel, ComparisonLogCodes, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement, };
|
|
7
7
|
/**
|
|
8
8
|
* Current base path for WASM files.
|
|
9
9
|
* Empty string means auto-detect from module URL.
|
|
@@ -92,6 +92,63 @@ export declare function compareDocuments(original: File | Uint8Array, modified:
|
|
|
92
92
|
* @throws Error if comparison fails
|
|
93
93
|
*/
|
|
94
94
|
export declare function compareDocumentsToHtml(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Compare two DOCX documents with logging enabled.
|
|
97
|
+
* Returns both the redlined document and a log of any warnings/errors encountered.
|
|
98
|
+
* This allows the comparison to continue past recoverable issues (like orphaned footnotes)
|
|
99
|
+
* while providing visibility into what was fixed or skipped.
|
|
100
|
+
*
|
|
101
|
+
* @param original - Original DOCX document
|
|
102
|
+
* @param modified - Modified DOCX document
|
|
103
|
+
* @param options - Comparison options
|
|
104
|
+
* @returns Result with document bytes and log entries
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const result = await compareDocumentsWithLog(original, modified, {
|
|
109
|
+
* authorName: "Reviewer",
|
|
110
|
+
* detailThreshold: 0.15
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* if (result.success) {
|
|
114
|
+
* // Use result.document (Uint8Array)
|
|
115
|
+
* if (result.hasWarnings) {
|
|
116
|
+
* console.log("Warnings during comparison:");
|
|
117
|
+
* for (const entry of result.log) {
|
|
118
|
+
* console.log(` [${entry.level}] ${entry.code}: ${entry.message}`);
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* } else {
|
|
122
|
+
* console.error(`Comparison failed: ${result.error}`);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function compareDocumentsWithLog(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<CompareResultWithLog>;
|
|
127
|
+
/**
|
|
128
|
+
* Compare two DOCX documents to HTML with logging enabled.
|
|
129
|
+
* Returns both the HTML output and a log of any warnings/errors encountered.
|
|
130
|
+
*
|
|
131
|
+
* @param original - Original DOCX document
|
|
132
|
+
* @param modified - Modified DOCX document
|
|
133
|
+
* @param options - Comparison options
|
|
134
|
+
* @returns Result with HTML and log entries
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const result = await compareDocumentsToHtmlWithLog(original, modified, {
|
|
139
|
+
* authorName: "Reviewer",
|
|
140
|
+
* renderTrackedChanges: true
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* if (result.success) {
|
|
144
|
+
* document.getElementById("viewer").innerHTML = result.html;
|
|
145
|
+
* if (result.hasWarnings) {
|
|
146
|
+
* console.log(`${result.log.length} warnings during comparison`);
|
|
147
|
+
* }
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function compareDocumentsToHtmlWithLog(original: File | Uint8Array, modified: File | Uint8Array, options?: CompareOptions): Promise<CompareToHtmlResultWithLog>;
|
|
95
152
|
/**
|
|
96
153
|
* Get revisions from a compared document.
|
|
97
154
|
*
|
|
@@ -551,4 +608,114 @@ export declare function findTextOccurrences(documentText: string, searchText: st
|
|
|
551
608
|
start: number;
|
|
552
609
|
end: number;
|
|
553
610
|
}>;
|
|
611
|
+
/**
|
|
612
|
+
* Project external annotations onto already-converted HTML.
|
|
613
|
+
* This avoids full DOCX re-conversion when only annotations change.
|
|
614
|
+
*
|
|
615
|
+
* Workflow:
|
|
616
|
+
* 1. Convert DOCX to HTML once using `convertDocxToHtml()`
|
|
617
|
+
* 2. Use this function to overlay annotations on the cached HTML
|
|
618
|
+
* 3. When annotations change, call this again with the same base HTML
|
|
619
|
+
*
|
|
620
|
+
* @param html - HTML string (previously converted via convertDocxToHtml)
|
|
621
|
+
* @param annotationSet - The external annotation set to project
|
|
622
|
+
* @param projectionOptions - Projection settings (CSS prefix, label mode, etc.)
|
|
623
|
+
* @returns HTML string with annotations projected
|
|
624
|
+
* @throws Error if projection fails
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* ```typescript
|
|
628
|
+
* // Step 1: Convert once
|
|
629
|
+
* const baseHtml = await convertDocxToHtml(docxFile);
|
|
630
|
+
*
|
|
631
|
+
* // Step 2: Project annotations (fast, no DOCX re-conversion)
|
|
632
|
+
* const annotatedHtml = await projectAnnotationsOntoHtml(baseHtml, annotationSet);
|
|
633
|
+
*
|
|
634
|
+
* // Step 3: When annotations change, project again on the same base HTML
|
|
635
|
+
* annotationSet.labelledText.push(newAnnotation);
|
|
636
|
+
* const updatedHtml = await projectAnnotationsOntoHtml(baseHtml, annotationSet);
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
export declare function projectAnnotationsOntoHtml(html: string, annotationSet: ExternalAnnotationSet, projectionOptions?: ExternalAnnotationProjectionSettings): Promise<string>;
|
|
640
|
+
/**
|
|
641
|
+
* Add a single annotation to existing HTML without re-converting the document.
|
|
642
|
+
* This is the fastest way to add one annotation to already-rendered HTML.
|
|
643
|
+
*
|
|
644
|
+
* @param html - HTML string (with or without existing annotations)
|
|
645
|
+
* @param annotation - The annotation to add
|
|
646
|
+
* @param label - Label definition for the annotation (optional, for color/text)
|
|
647
|
+
* @param projectionOptions - Projection settings
|
|
648
|
+
* @returns HTML string with the annotation added
|
|
649
|
+
* @throws Error if operation fails
|
|
650
|
+
*
|
|
651
|
+
* @example
|
|
652
|
+
* ```typescript
|
|
653
|
+
* const annotation = createAnnotation("ann-new", "CLAUSE", set.content, 100, 150);
|
|
654
|
+
* const label = { id: "CLAUSE", text: "Clause", color: "#FF5722" };
|
|
655
|
+
* const updatedHtml = await addAnnotationToHtml(currentHtml, annotation, label);
|
|
656
|
+
* ```
|
|
657
|
+
*/
|
|
658
|
+
export declare function addAnnotationToHtml(html: string, annotation: OpenContractsAnnotation, label?: AnnotationLabel, projectionOptions?: ExternalAnnotationProjectionSettings): Promise<string>;
|
|
659
|
+
/**
|
|
660
|
+
* Remove a single annotation from HTML by annotation ID.
|
|
661
|
+
* Unwraps annotation spans back to plain text.
|
|
662
|
+
*
|
|
663
|
+
* @param html - HTML string with annotations
|
|
664
|
+
* @param annotationId - ID of the annotation to remove
|
|
665
|
+
* @param cssClassPrefix - CSS class prefix used for annotations (default: "ext-annot-")
|
|
666
|
+
* @returns HTML string with the annotation removed
|
|
667
|
+
* @throws Error if operation fails
|
|
668
|
+
*
|
|
669
|
+
* @example
|
|
670
|
+
* ```typescript
|
|
671
|
+
* const updatedHtml = await removeAnnotationFromHtml(currentHtml, "ann-001");
|
|
672
|
+
* ```
|
|
673
|
+
*/
|
|
674
|
+
export declare function removeAnnotationFromHtml(html: string, annotationId: string, cssClassPrefix?: string): Promise<string>;
|
|
675
|
+
/**
|
|
676
|
+
* Generate CSS to hide annotations with specific label IDs.
|
|
677
|
+
* Enables CSS-based label filtering without re-rendering HTML.
|
|
678
|
+
*
|
|
679
|
+
* Apply the returned CSS to your document (e.g., via a `<style>` element)
|
|
680
|
+
* to hide/show annotations by label. This is much faster than re-projecting
|
|
681
|
+
* all annotations.
|
|
682
|
+
*
|
|
683
|
+
* @param hiddenLabelIds - Array of label IDs to hide
|
|
684
|
+
* @param cssClassPrefix - CSS class prefix (default: "ext-annot-")
|
|
685
|
+
* @returns CSS string that hides the specified labels
|
|
686
|
+
* @throws Error if operation fails
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* // Hide annotations with label "DRAFT" and "INTERNAL"
|
|
691
|
+
* const css = await generateAnnotationVisibilityCss(["DRAFT", "INTERNAL"]);
|
|
692
|
+
*
|
|
693
|
+
* // Apply to a <style> element in the DOM
|
|
694
|
+
* const styleEl = document.getElementById("visibility-overrides");
|
|
695
|
+
* styleEl.textContent = css;
|
|
696
|
+
*
|
|
697
|
+
* // To show all annotations again, clear the style:
|
|
698
|
+
* styleEl.textContent = "";
|
|
699
|
+
* ```
|
|
700
|
+
*/
|
|
701
|
+
export declare function generateAnnotationVisibilityCss(hiddenLabelIds: string[], cssClassPrefix?: string): Promise<string>;
|
|
702
|
+
/**
|
|
703
|
+
* Generate annotation CSS for a set of labels.
|
|
704
|
+
* Useful when managing CSS separately from HTML content.
|
|
705
|
+
*
|
|
706
|
+
* @param labels - Label definitions (keyed by label ID)
|
|
707
|
+
* @param projectionOptions - Projection settings
|
|
708
|
+
* @returns CSS string for the annotation styles
|
|
709
|
+
* @throws Error if operation fails
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```typescript
|
|
713
|
+
* const labels = {
|
|
714
|
+
* "CLAUSE": { id: "CLAUSE", text: "Clause", color: "#FF5722" },
|
|
715
|
+
* "TERM": { id: "TERM", text: "Term", color: "#2196F3" },
|
|
716
|
+
* };
|
|
717
|
+
* const css = await generateAnnotationCss(labels);
|
|
718
|
+
* ```
|
|
719
|
+
*/
|
|
720
|
+
export declare function generateAnnotationCss(labels: Record<string, AnnotationLabel>, projectionOptions?: ExternalAnnotationProjectionSettings): Promise<string>;
|
|
554
721
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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,EAEb,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,8BAA8B,EAC9B,gBAAgB,EAChB,eAAe,EAEf,qBAAqB,EACrB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACvB,iCAAiC,EACjC,WAAW,EACX,OAAO,EACP,QAAQ,EACR,yBAAyB,EAEzB,eAAe,EACf,qBAAqB,EACrB,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,
|
|
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,EAEb,mBAAmB,EACnB,mBAAmB,EACnB,UAAU,EACV,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,8BAA8B,EAC9B,gBAAgB,EAChB,eAAe,EAEf,qBAAqB,EACrB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACvB,iCAAiC,EACjC,WAAW,EACX,OAAO,EACP,QAAQ,EACR,yBAAyB,EAEzB,eAAe,EACf,qBAAqB,EACrB,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,EAEpC,kBAAkB,EAClB,oBAAoB,EACpB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,MAAM,EACN,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,eAAe,EACf,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,cAAc,EACd,aAAa,EACb,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAA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ationLabelMode, RevisionType, DocumentElementType, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement, } from "./types.js";
|
|
1
|
+
import { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, ComparisonLogLevel, ComparisonLogCodes, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange, findElementById, findElementsByType, getParagraphs, getTables, getTableColumns, targetElement, targetParagraph, targetParagraphRange, targetRun, targetTable, targetTableRow, targetTableCell, targetTableColumn, targetSearch, targetSearchInElement, } from "./types.js";
|
|
2
2
|
export { PaginationEngine, paginateHtml } from "./pagination.js";
|
|
3
|
-
export { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange,
|
|
3
|
+
export { CommentRenderMode, PaginationMode, AnnotationLabelMode, RevisionType, DocumentElementType, ComparisonLogLevel, ComparisonLogCodes, isInsertion, isDeletion, isMove, isMoveSource, isMoveDestination, findMovePair, isFormatChange,
|
|
4
4
|
// Document structure helpers
|
|
5
5
|
findElementById, findElementsByType, getParagraphs, getTables, getTableColumns,
|
|
6
6
|
// Annotation target factory functions
|
|
@@ -287,15 +287,122 @@ export async function compareDocumentsToHtml(original, modified, options) {
|
|
|
287
287
|
const modifiedBytes = await toBytes(modified);
|
|
288
288
|
// Yield to browser before heavy WASM work - allows loading states to render
|
|
289
289
|
await yieldToMain();
|
|
290
|
-
// Use the new options method if renderTrackedChanges is explicitly set
|
|
291
290
|
const renderTrackedChanges = options?.renderTrackedChanges ?? true;
|
|
292
|
-
|
|
291
|
+
let result;
|
|
292
|
+
// Use full method when detailThreshold or caseInsensitive are specified
|
|
293
|
+
if (options?.detailThreshold !== undefined || options?.caseInsensitive !== undefined) {
|
|
294
|
+
result = exports.DocumentComparer.CompareDocumentsToHtmlFull(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus", options?.detailThreshold ?? 0.15, options?.caseInsensitive ?? false, renderTrackedChanges);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
result = exports.DocumentComparer.CompareDocumentsToHtmlWithOptions(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus", renderTrackedChanges);
|
|
298
|
+
}
|
|
293
299
|
if (isErrorResponse(result)) {
|
|
294
300
|
const error = parseError(result);
|
|
295
301
|
throw new Error(`Comparison failed: ${error.error}`);
|
|
296
302
|
}
|
|
297
303
|
return result;
|
|
298
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* Compare two DOCX documents with logging enabled.
|
|
307
|
+
* Returns both the redlined document and a log of any warnings/errors encountered.
|
|
308
|
+
* This allows the comparison to continue past recoverable issues (like orphaned footnotes)
|
|
309
|
+
* while providing visibility into what was fixed or skipped.
|
|
310
|
+
*
|
|
311
|
+
* @param original - Original DOCX document
|
|
312
|
+
* @param modified - Modified DOCX document
|
|
313
|
+
* @param options - Comparison options
|
|
314
|
+
* @returns Result with document bytes and log entries
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const result = await compareDocumentsWithLog(original, modified, {
|
|
319
|
+
* authorName: "Reviewer",
|
|
320
|
+
* detailThreshold: 0.15
|
|
321
|
+
* });
|
|
322
|
+
*
|
|
323
|
+
* if (result.success) {
|
|
324
|
+
* // Use result.document (Uint8Array)
|
|
325
|
+
* if (result.hasWarnings) {
|
|
326
|
+
* console.log("Warnings during comparison:");
|
|
327
|
+
* for (const entry of result.log) {
|
|
328
|
+
* console.log(` [${entry.level}] ${entry.code}: ${entry.message}`);
|
|
329
|
+
* }
|
|
330
|
+
* }
|
|
331
|
+
* } else {
|
|
332
|
+
* console.error(`Comparison failed: ${result.error}`);
|
|
333
|
+
* }
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
export async function compareDocumentsWithLog(original, modified, options) {
|
|
337
|
+
const exports = ensureInitialized();
|
|
338
|
+
const originalBytes = await toBytes(original);
|
|
339
|
+
const modifiedBytes = await toBytes(modified);
|
|
340
|
+
await yieldToMain();
|
|
341
|
+
const result = exports.DocumentComparer.CompareDocumentsWithLog(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus", options?.detailThreshold ?? 0.15, options?.caseInsensitive ?? false);
|
|
342
|
+
const parsed = JSON.parse(result);
|
|
343
|
+
return {
|
|
344
|
+
success: parsed.Success ?? parsed.success ?? false,
|
|
345
|
+
document: parsed.DocumentBase64 || parsed.documentBase64
|
|
346
|
+
? Uint8Array.from(atob(parsed.DocumentBase64 || parsed.documentBase64), c => c.charCodeAt(0))
|
|
347
|
+
: undefined,
|
|
348
|
+
error: parsed.Error ?? parsed.error,
|
|
349
|
+
log: convertLogEntries(parsed.Log || parsed.log || []),
|
|
350
|
+
hasWarnings: parsed.HasWarnings ?? parsed.hasWarnings ?? false,
|
|
351
|
+
hasErrors: parsed.HasErrors ?? parsed.hasErrors ?? false,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Compare two DOCX documents to HTML with logging enabled.
|
|
356
|
+
* Returns both the HTML output and a log of any warnings/errors encountered.
|
|
357
|
+
*
|
|
358
|
+
* @param original - Original DOCX document
|
|
359
|
+
* @param modified - Modified DOCX document
|
|
360
|
+
* @param options - Comparison options
|
|
361
|
+
* @returns Result with HTML and log entries
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```typescript
|
|
365
|
+
* const result = await compareDocumentsToHtmlWithLog(original, modified, {
|
|
366
|
+
* authorName: "Reviewer",
|
|
367
|
+
* renderTrackedChanges: true
|
|
368
|
+
* });
|
|
369
|
+
*
|
|
370
|
+
* if (result.success) {
|
|
371
|
+
* document.getElementById("viewer").innerHTML = result.html;
|
|
372
|
+
* if (result.hasWarnings) {
|
|
373
|
+
* console.log(`${result.log.length} warnings during comparison`);
|
|
374
|
+
* }
|
|
375
|
+
* }
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
export async function compareDocumentsToHtmlWithLog(original, modified, options) {
|
|
379
|
+
const exports = ensureInitialized();
|
|
380
|
+
const originalBytes = await toBytes(original);
|
|
381
|
+
const modifiedBytes = await toBytes(modified);
|
|
382
|
+
await yieldToMain();
|
|
383
|
+
const result = exports.DocumentComparer.CompareDocumentsToHtmlWithLog(originalBytes, modifiedBytes, options?.authorName ?? "Docxodus", options?.detailThreshold ?? 0.15, options?.caseInsensitive ?? false, options?.renderTrackedChanges ?? true);
|
|
384
|
+
const parsed = JSON.parse(result);
|
|
385
|
+
return {
|
|
386
|
+
success: parsed.Success ?? parsed.success ?? false,
|
|
387
|
+
html: parsed.Html ?? parsed.html,
|
|
388
|
+
error: parsed.Error ?? parsed.error,
|
|
389
|
+
log: convertLogEntries(parsed.Log || parsed.log || []),
|
|
390
|
+
hasWarnings: parsed.HasWarnings ?? parsed.hasWarnings ?? false,
|
|
391
|
+
hasErrors: parsed.HasErrors ?? parsed.hasErrors ?? false,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Convert log entries from PascalCase to camelCase.
|
|
396
|
+
*/
|
|
397
|
+
function convertLogEntries(entries) {
|
|
398
|
+
return entries.map((e) => ({
|
|
399
|
+
level: e.Level ?? e.level ?? "Info",
|
|
400
|
+
code: e.Code ?? e.code ?? "",
|
|
401
|
+
message: e.Message ?? e.message ?? "",
|
|
402
|
+
details: e.Details ?? e.details,
|
|
403
|
+
location: e.Location ?? e.location,
|
|
404
|
+
}));
|
|
405
|
+
}
|
|
299
406
|
/**
|
|
300
407
|
* Get revisions from a compared document.
|
|
301
408
|
*
|
|
@@ -1329,4 +1436,170 @@ function convertExternalAnnotationSet(parsed) {
|
|
|
1329
1436
|
docLabelDefinitions,
|
|
1330
1437
|
};
|
|
1331
1438
|
}
|
|
1439
|
+
// ============================================================================
|
|
1440
|
+
// Incremental Annotation Overlay API (Issue #106)
|
|
1441
|
+
// ============================================================================
|
|
1442
|
+
/**
|
|
1443
|
+
* Project external annotations onto already-converted HTML.
|
|
1444
|
+
* This avoids full DOCX re-conversion when only annotations change.
|
|
1445
|
+
*
|
|
1446
|
+
* Workflow:
|
|
1447
|
+
* 1. Convert DOCX to HTML once using `convertDocxToHtml()`
|
|
1448
|
+
* 2. Use this function to overlay annotations on the cached HTML
|
|
1449
|
+
* 3. When annotations change, call this again with the same base HTML
|
|
1450
|
+
*
|
|
1451
|
+
* @param html - HTML string (previously converted via convertDocxToHtml)
|
|
1452
|
+
* @param annotationSet - The external annotation set to project
|
|
1453
|
+
* @param projectionOptions - Projection settings (CSS prefix, label mode, etc.)
|
|
1454
|
+
* @returns HTML string with annotations projected
|
|
1455
|
+
* @throws Error if projection fails
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```typescript
|
|
1459
|
+
* // Step 1: Convert once
|
|
1460
|
+
* const baseHtml = await convertDocxToHtml(docxFile);
|
|
1461
|
+
*
|
|
1462
|
+
* // Step 2: Project annotations (fast, no DOCX re-conversion)
|
|
1463
|
+
* const annotatedHtml = await projectAnnotationsOntoHtml(baseHtml, annotationSet);
|
|
1464
|
+
*
|
|
1465
|
+
* // Step 3: When annotations change, project again on the same base HTML
|
|
1466
|
+
* annotationSet.labelledText.push(newAnnotation);
|
|
1467
|
+
* const updatedHtml = await projectAnnotationsOntoHtml(baseHtml, annotationSet);
|
|
1468
|
+
* ```
|
|
1469
|
+
*/
|
|
1470
|
+
export async function projectAnnotationsOntoHtml(html, annotationSet, projectionOptions) {
|
|
1471
|
+
const exports = ensureInitialized();
|
|
1472
|
+
await yieldToMain();
|
|
1473
|
+
const annotationSetJson = JSON.stringify(annotationSet);
|
|
1474
|
+
const result = exports.DocumentConverter.ProjectAnnotationsOntoHtml(html, annotationSetJson, projectionOptions?.cssClassPrefix ?? "ext-annot-", projectionOptions?.labelMode ?? AnnotationLabelMode.Above);
|
|
1475
|
+
if (isErrorResponse(result)) {
|
|
1476
|
+
const error = parseError(result);
|
|
1477
|
+
throw new Error(`Failed to project annotations: ${error.error}`);
|
|
1478
|
+
}
|
|
1479
|
+
const parsed = JSON.parse(result);
|
|
1480
|
+
return parsed.Html ?? parsed.html;
|
|
1481
|
+
}
|
|
1482
|
+
/**
|
|
1483
|
+
* Add a single annotation to existing HTML without re-converting the document.
|
|
1484
|
+
* This is the fastest way to add one annotation to already-rendered HTML.
|
|
1485
|
+
*
|
|
1486
|
+
* @param html - HTML string (with or without existing annotations)
|
|
1487
|
+
* @param annotation - The annotation to add
|
|
1488
|
+
* @param label - Label definition for the annotation (optional, for color/text)
|
|
1489
|
+
* @param projectionOptions - Projection settings
|
|
1490
|
+
* @returns HTML string with the annotation added
|
|
1491
|
+
* @throws Error if operation fails
|
|
1492
|
+
*
|
|
1493
|
+
* @example
|
|
1494
|
+
* ```typescript
|
|
1495
|
+
* const annotation = createAnnotation("ann-new", "CLAUSE", set.content, 100, 150);
|
|
1496
|
+
* const label = { id: "CLAUSE", text: "Clause", color: "#FF5722" };
|
|
1497
|
+
* const updatedHtml = await addAnnotationToHtml(currentHtml, annotation, label);
|
|
1498
|
+
* ```
|
|
1499
|
+
*/
|
|
1500
|
+
export async function addAnnotationToHtml(html, annotation, label, projectionOptions) {
|
|
1501
|
+
const exports = ensureInitialized();
|
|
1502
|
+
await yieldToMain();
|
|
1503
|
+
const annotationJson = JSON.stringify(annotation);
|
|
1504
|
+
const labelJson = label ? JSON.stringify(label) : "";
|
|
1505
|
+
const result = exports.DocumentConverter.AddAnnotationToHtml(html, annotationJson, labelJson, projectionOptions?.cssClassPrefix ?? "ext-annot-", projectionOptions?.labelMode ?? AnnotationLabelMode.Above);
|
|
1506
|
+
if (isErrorResponse(result)) {
|
|
1507
|
+
const error = parseError(result);
|
|
1508
|
+
throw new Error(`Failed to add annotation to HTML: ${error.error}`);
|
|
1509
|
+
}
|
|
1510
|
+
const parsed = JSON.parse(result);
|
|
1511
|
+
return parsed.Html ?? parsed.html;
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Remove a single annotation from HTML by annotation ID.
|
|
1515
|
+
* Unwraps annotation spans back to plain text.
|
|
1516
|
+
*
|
|
1517
|
+
* @param html - HTML string with annotations
|
|
1518
|
+
* @param annotationId - ID of the annotation to remove
|
|
1519
|
+
* @param cssClassPrefix - CSS class prefix used for annotations (default: "ext-annot-")
|
|
1520
|
+
* @returns HTML string with the annotation removed
|
|
1521
|
+
* @throws Error if operation fails
|
|
1522
|
+
*
|
|
1523
|
+
* @example
|
|
1524
|
+
* ```typescript
|
|
1525
|
+
* const updatedHtml = await removeAnnotationFromHtml(currentHtml, "ann-001");
|
|
1526
|
+
* ```
|
|
1527
|
+
*/
|
|
1528
|
+
export async function removeAnnotationFromHtml(html, annotationId, cssClassPrefix) {
|
|
1529
|
+
const exports = ensureInitialized();
|
|
1530
|
+
await yieldToMain();
|
|
1531
|
+
const result = exports.DocumentConverter.RemoveAnnotationFromHtml(html, annotationId, cssClassPrefix ?? "ext-annot-");
|
|
1532
|
+
if (isErrorResponse(result)) {
|
|
1533
|
+
const error = parseError(result);
|
|
1534
|
+
throw new Error(`Failed to remove annotation from HTML: ${error.error}`);
|
|
1535
|
+
}
|
|
1536
|
+
const parsed = JSON.parse(result);
|
|
1537
|
+
return parsed.Html ?? parsed.html;
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Generate CSS to hide annotations with specific label IDs.
|
|
1541
|
+
* Enables CSS-based label filtering without re-rendering HTML.
|
|
1542
|
+
*
|
|
1543
|
+
* Apply the returned CSS to your document (e.g., via a `<style>` element)
|
|
1544
|
+
* to hide/show annotations by label. This is much faster than re-projecting
|
|
1545
|
+
* all annotations.
|
|
1546
|
+
*
|
|
1547
|
+
* @param hiddenLabelIds - Array of label IDs to hide
|
|
1548
|
+
* @param cssClassPrefix - CSS class prefix (default: "ext-annot-")
|
|
1549
|
+
* @returns CSS string that hides the specified labels
|
|
1550
|
+
* @throws Error if operation fails
|
|
1551
|
+
*
|
|
1552
|
+
* @example
|
|
1553
|
+
* ```typescript
|
|
1554
|
+
* // Hide annotations with label "DRAFT" and "INTERNAL"
|
|
1555
|
+
* const css = await generateAnnotationVisibilityCss(["DRAFT", "INTERNAL"]);
|
|
1556
|
+
*
|
|
1557
|
+
* // Apply to a <style> element in the DOM
|
|
1558
|
+
* const styleEl = document.getElementById("visibility-overrides");
|
|
1559
|
+
* styleEl.textContent = css;
|
|
1560
|
+
*
|
|
1561
|
+
* // To show all annotations again, clear the style:
|
|
1562
|
+
* styleEl.textContent = "";
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
export async function generateAnnotationVisibilityCss(hiddenLabelIds, cssClassPrefix) {
|
|
1566
|
+
const exports = ensureInitialized();
|
|
1567
|
+
await yieldToMain();
|
|
1568
|
+
const result = exports.DocumentConverter.GenerateAnnotationVisibilityCss(JSON.stringify(hiddenLabelIds), cssClassPrefix ?? "ext-annot-");
|
|
1569
|
+
if (isErrorResponse(result)) {
|
|
1570
|
+
const error = parseError(result);
|
|
1571
|
+
throw new Error(`Failed to generate visibility CSS: ${error.error}`);
|
|
1572
|
+
}
|
|
1573
|
+
const parsed = JSON.parse(result);
|
|
1574
|
+
return parsed.Css ?? parsed.css;
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* Generate annotation CSS for a set of labels.
|
|
1578
|
+
* Useful when managing CSS separately from HTML content.
|
|
1579
|
+
*
|
|
1580
|
+
* @param labels - Label definitions (keyed by label ID)
|
|
1581
|
+
* @param projectionOptions - Projection settings
|
|
1582
|
+
* @returns CSS string for the annotation styles
|
|
1583
|
+
* @throws Error if operation fails
|
|
1584
|
+
*
|
|
1585
|
+
* @example
|
|
1586
|
+
* ```typescript
|
|
1587
|
+
* const labels = {
|
|
1588
|
+
* "CLAUSE": { id: "CLAUSE", text: "Clause", color: "#FF5722" },
|
|
1589
|
+
* "TERM": { id: "TERM", text: "Term", color: "#2196F3" },
|
|
1590
|
+
* };
|
|
1591
|
+
* const css = await generateAnnotationCss(labels);
|
|
1592
|
+
* ```
|
|
1593
|
+
*/
|
|
1594
|
+
export async function generateAnnotationCss(labels, projectionOptions) {
|
|
1595
|
+
const exports = ensureInitialized();
|
|
1596
|
+
await yieldToMain();
|
|
1597
|
+
const result = exports.DocumentConverter.GenerateAnnotationCss(JSON.stringify(labels), projectionOptions?.cssClassPrefix ?? "ext-annot-", projectionOptions?.labelMode ?? AnnotationLabelMode.Above);
|
|
1598
|
+
if (isErrorResponse(result)) {
|
|
1599
|
+
const error = parseError(result);
|
|
1600
|
+
throw new Error(`Failed to generate annotation CSS: ${error.error}`);
|
|
1601
|
+
}
|
|
1602
|
+
const parsed = JSON.parse(result);
|
|
1603
|
+
return parsed.Css ?? parsed.css;
|
|
1604
|
+
}
|
|
1332
1605
|
//# sourceMappingURL=index.js.map
|