open-agreements
Version:
Open-source legal template filling CLI and library
85 lines • 4.22 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 { CorrelationStatus, type ComparisonUnitAtom } from '../../core-types.js';
export declare const DELETION_LIKE_STATUSES: ReadonlySet<CorrelationStatus>;
export declare const INSERTION_LIKE_STATUSES: ReadonlySet<CorrelationStatus>;
/**
* Reorder merged atoms so that within each contiguous block of non-equal atoms,
* all deletion-like atoms come before all insertion-like atoms.
*
* This produces grouped tracked changes ("<del>old words</del><ins>new words</ins>")
* instead of alternating word-by-word pairs ("<del>old1</del><ins>new1</ins><del>old2</del>...").
*/
export declare function groupDeletionsBeforeInsertions(atoms: ComparisonUnitAtom[]): ComparisonUnitAtom[];
export declare function mergeAdjacentTrackChangeSiblings(root: Element): void;
/**
* Build a normalized content signature for a run's non-rPr children.
* On the del side, maps w:delText → w:t and w:delInstrText → w:instrText
* so that content from del wrappers can be compared to ins wrappers.
*/
export declare function normalizeRunContentSignature(run: Element, isDelSide: boolean): string;
/**
* Check if an adjacent w:del + w:ins pair is a no-op (identical text and formatting).
* Both wrappers must contain the same number of runs with matching rPr and content.
*/
export declare function isNoOpPair(del: Element, ins: Element): boolean;
/**
* Suppress no-op del/ins pairs — adjacent w:del + w:ins wrappers where the
* content and formatting are identical. These arise from field-adjacent atoms
* that are false-positive changes.
*
* When a no-op is detected, both wrappers are unwrapped, leaving the ins-side
* runs as plain (non-tracked) children. The del-side runs are removed.
*/
export declare function suppressNoOpChangePairs(root: Element): void;
/**
* Narrow whitespace predicate for bridging: returns true only if a w:r element's
* visible children are exclusively w:t elements with whitespace-only text content.
* Excludes w:tab, w:br, w:cr which have layout significance.
*/
export declare function isInlineWhitespaceOnlyRun(run: Element): boolean;
/**
* Merge track-change wrappers (w:del or w:ins) that are separated by a
* whitespace-only run. This groups "word-by-word" tracked changes into
* contiguous blocks for cleaner presentation.
*
* For w:del: clones the whitespace run, converts w:t→w:delText, and absorbs
* both the whitespace and the second wrapper's children into the first wrapper.
*
* For w:ins: moves the whitespace run into the first wrapper, then absorbs
* the second wrapper's children.
*
* Both projections (Accept All, Reject All) remain correct because each
* wrapper independently contains the whitespace it needs.
*/
export declare function mergeWhitespaceBridgedTrackChanges(root: Element): void;
/**
* Convert w:t → w:delText and w:instrText → w:delInstrText within a run,
* preserving xml:space attributes. Used for cloning whitespace runs into
* w:del wrappers during pair-chain coalescing.
*/
export declare function convertRunTextToDelText(run: Element): void;
/**
* Coalesce alternating del/ins pair chains separated by whitespace-only runs
* into single grouped del + ins wrappers.
*
* Pattern: [w:del, w:ins, ws-segment..., w:del, w:ins, ws-segment..., w:del, w:ins]
*
* For each whitespace segment between consecutive [del, ins] pairs:
* 1. Clone each ws-run → convert to delText → append to first del
* 2. Clone each ws-run → keep as w:t → append to first ins
* 3. Move nextDel's children into first del
* 4. Move nextIns's children into first ins
* 5. Remove original ws-runs, empty nextDel, empty nextIns from parent
*
* Safety invariants:
* - Only bridges when both del AND ins absorb the whitespace (both projections correct)
* - Incomplete tail [del, ins, ws, del] (no trailing ins) → stop chain, don't bridge
* - All wrappers in chain must share same w:author and w:date
*/
export declare function coalesceDelInsPairChains(root: Element): void;
//# sourceMappingURL=inPlaceModifier-postprocess.d.ts.map