open-agreements
Version:
Open-source legal template filling CLI and library
69 lines • 3.73 kB
JavaScript
/**
* Document Comparison Engine
*
* Provides multiple comparison approaches:
* - Baseline A: WmlComparer wrapper (Docxodus WASM or dotnet CLI)
* - Baseline B: Pure TypeScript (diff-match-patch + OOXML renderer) - paragraph level (dev-only)
* - Atomizer: Pure TypeScript with atom-level comparison, move detection, format detection
*/
import { compareDocumentsAtomizer } from './baselines/atomizer/pipeline.js';
/**
* Compare two DOCX documents and produce a document with track changes.
*
* @param original - The original document (Buffer)
* @param revised - The revised document (Buffer)
* @param options - Comparison options
* @returns The comparison result with track changes markup
*/
export async function compareDocuments(original, revised, options = {}) {
const { engine = 'auto', author, date, reconstructionMode, premergeRuns } = options;
// Migration error for removed diffmatch engine
if (engine === 'diffmatch') {
throw new Error("The 'diffmatch' engine has been removed from the public API. " +
"Use engine: 'atomizer' (recommended) or 'auto'.");
}
// Atomizer engine (recommended) - character-level with move detection
if (engine === 'atomizer' || engine === 'auto') {
return compareDocumentsAtomizer(original, revised, {
author,
date,
reconstructionMode,
premergeRuns,
});
}
// WmlComparer engine requires --docxodus option at CLI level
throw new Error('WmlComparer engine is only available through the benchmark CLI. ' +
'Use engine: "atomizer" or "auto" for programmatic access.');
}
// Re-export shared utilities
export * from './shared/ooxml/namespaces.js';
export * from './shared/ooxml/types.js';
// Re-export core WmlComparer types
export * from './core-types.js';
// Re-export atomizer functions
export * from './atomizer.js';
// Re-export move detection
export * from './move-detection.js';
// Re-export format detection
export * from './format-detection.js';
// Re-export the formatting-fidelity comparison check
export * from './baselines/atomizer/formattingFidelity.js';
// Re-export numbering utilities
export * from './numbering.js';
// Re-export footnote utilities
export * from './footnotes.js';
// Re-export primitives (editing, DOM helpers, document operations)
export * from './primitives/index.js';
export { allocateRevisionId, buildPPrChangeElement, buildTcPrChangeElement, buildTrPrChangeElement, buildRPrChangeElement, createRevisionContainer, createRevisionContext, createRevisionIdState, escapeXmlAttr, formatDate, prepareElementForDeletion, wrapElementWithDel, wrapElementWithIns, } from './primitives/track-changes-emitter.js';
// Re-export the LibreOffice accept/reject oracle (gated reference voter; callers skip when
// `resolveSoffice()` is null). odf-core's round-trip tests drive it with `.odt` jobs.
export { resolveSoffice, runLibreOfficeOracle } from './integration/libreoffice-oracle.js';
// Synthetic-DOCX fixture builders re-exported for downstream packages' test suites
// (odf-core's DOCX→ODT conversion tests build their inputs with these). They live under
// `integration/` because `src/testing/**` is excluded from the package build.
export { buildSyntheticDocx, buildDocxFromParts, } from './integration/synthetic-docx-fixture.js';
// From-scratch generation (OpenSpec capability: docx-generation). Public as of
// the final phase of add-docx-generation: compatibility matrix recorded, all
// scenario coverage enforced strictly in CI.
export { generateDocx, GenerationSpecError, GenerationInternalError, checkGeneratedPackage, coverTermsTable, signatureBlock, } from './generation/index.js';
//# sourceMappingURL=index.js.map