open-agreements
Version:
Open-source legal template filling CLI and library
74 lines • 3.36 kB
TypeScript
/**
* In-Place AST Modifier
*
* Modifies the revised document's AST in-place to add track changes markup.
* This replaces the reconstruction-based approach with direct tree manipulation.
*/
import type { ComparisonUnitAtom } from '../../core-types.js';
import { CorrelationStatus } from '../../core-types.js';
interface ContainerResolutionContext {
body: Element;
lastProcessedParagraph: Element | null;
lastParaByContainer: Map<Element, Element>;
}
export declare class ContainerResolutionError extends Error {
constructor(message: string);
}
/** A single step in a structural path from a paragraph up to w:body. */
export interface ContainerPathStep {
tag: string;
index: number;
}
/**
* Compute the structural path from a paragraph to the document body.
* Walks `parentNode` from the paragraph, recording {tag, index} for each
* structural container (w:tc, w:tr, w:tbl). Stops at w:body.
* Returns innermost-first order.
*
* Uses original-tree nodes — safe because only the revised tree is mutated.
*/
export declare function getContainerPath(paragraph: Element): ContainerPathStep[];
/**
* Resolve a container path in the revised tree.
* Walks the path in reverse (outermost → innermost) from `body`.
* Returns the deepest container (typically w:tc), or null on mismatch.
*/
export declare function resolveContainerInRevised(path: ContainerPathStep[], body: Element): Element | null;
/**
* Validate that the revised tree has compatible topology at the given path.
* Checks row count and cell count match at the target position.
* Returns false if there's a structural mismatch (row/cell additions, gridSpan divergence).
*/
export declare function validateContainerTopology(path: ContainerPathStep[], body: Element): boolean;
/**
* Find the correct container and insertion anchor for a deleted/moved-source atom.
*
* For body-level atoms, returns ctx.body with the global lastProcessedParagraph anchor.
* For table-cell atoms, maps from the original tree container to the revised tree container
* by structural position, and uses the per-container anchor from lastParaByContainer.
*
* Returns null if container resolution fails (topology mismatch) — caller must throw
* ContainerResolutionError to trigger rebuild fallback.
*/
export declare function findTargetContainerForAtom(atom: ComparisonUnitAtom, ctx: ContainerResolutionContext): {
container: Element;
insertAfter: Element | null;
} | null;
/**
* Determine whether an atom is "whitespace-only" for paragraph-level classification.
*
* We treat pure whitespace runs/tabs/breaks as ignorable noise, because LCS alignment
* can mark them Equal even when a whole paragraph was inserted/deleted. If we don't
* ignore them, Word can end up with a stub paragraph after Accept/Reject All.
*/
export declare function isWhitespaceAtom(atom: ComparisonUnitAtom): boolean;
/**
* Returns true if every non-empty atom in this paragraph is of the specified status,
* ignoring whitespace-only atoms.
*
* Mirrors the rebuild reconstructor's whole-paragraph classification so that inplace
* output behaves the same under Word's Accept/Reject All.
*/
export declare function isEntireParagraphAtomsWithStatus(atoms: ComparisonUnitAtom[], status: CorrelationStatus): boolean;
export {};
//# sourceMappingURL=inPlaceModifier-containers.d.ts.map