/** * Describes the position of a named capture group match within the modified text. * * Used to track where dynamic "expected" regions (e.g., year, holder name) * appear in `modifiedText` so they can be tagged with distinct styling. */ export interface CaptureRange { /** The name of the capture group (e.g., `"year"`, `"holder"`). */ name: string; /** The start index (inclusive) in `modifiedText`. */ start: number; /** The end index (exclusive) in `modifiedText`. */ end: number; } /** * A single segment of a diff result, optionally tagged as an "expected" region. * * - `operation` follows diff-match-patch conventions: `-1` = remove, `0` = equal, `1` = insert. * - When `expected` is set, this segment matched a named capture group and should * render with "expected" styling rather than insert/remove colors. */ export interface DisplayDiff { /** The diff operation: `-1` (remove), `0` (equal), or `1` (insert). */ operation: number; /** The text content of this diff segment. */ text: string; /** If set, the name of the capture group this segment matched (e.g., `"year"`). */ expected?: string; } /** * The result of matching expected patterns against modified text. * * Returned by {@link extractCaptures} when all capture groups successfully match. */ export interface PatternMatchResult { /** The template with capture group syntax replaced by actual captured values. */ resolvedText: string; /** A map of capture group names to their matched values. */ captures: Record; /** The positions of each capture in `modifiedText`. */ captureRanges: CaptureRange[]; } interface ParsedGroup { name: string; pattern: string; } /** * Information about a group's position in the original template line. */ interface LineGroup { name: string; pattern: string; /** Index within the line where the full group syntax starts. */ indexInLine: number; } /** * Immutable extraction metadata for one template line containing groups. */ interface CompiledLinePattern { lineText: string; groups: LineGroup[]; regex: RegExp; } /** * Compiled result of parsing named capture groups from a template. * * Returned by {@link parseExpectedPatterns}; carries the immutable metadata * reused by {@link extractCaptures} for repeated extraction against modified text. */ export interface ParseResult { /** * @internal Engine detail — not part of the stable public API; may change in * any future release. Parsed capture groups in source order. */ groups: ParsedGroup[]; /** * @internal Engine detail — not part of the stable public API; may change in * any future release. Literal text and full group syntax interleaved in source order. */ parts: string[]; /** * @internal Engine detail — not part of the stable public API; may change in * any future release. Ordered source matches retained from the single template scan. */ matches: GroupMatch[]; /** Template text with named groups replaced by readable placeholders. */ cleanedText: string; /** * @internal Engine detail — not part of the stable public API; may change in * any future release. Ordered, compiled extraction plans for lines containing named groups. */ linePatterns: CompiledLinePattern[]; } /** * Represents a named capture group match found by the iterative parser. */ interface GroupMatch { /** The full `(?pattern)` string. */ fullMatch: string; /** The capture group name. */ name: string; /** The pattern inside the group (between `>` and closing `)`). */ pattern: string; /** The start index of the full match in the source text. */ index: number; } /** * Parses and compiles `(?pattern)` named capture groups from text. * * Extracts all named capture groups and retains the immutable metadata used by * repeated capture extraction, including cleaned fallback text and line regexes. * * @param text - The template text containing named capture group syntax. * @returns The compiled parse result, or null if no named groups are found. */ export declare const parseExpectedPatterns: (text: string) => ParseResult | null; /** * Replaces named capture groups with readable placeholders. * * This standalone compatibility helper scans its input once. Component updates * use the precomputed `cleanedText` on {@link parseExpectedPatterns} instead. * * @param text - Template text that may contain named capture group syntax. * @returns The template with each valid group replaced by ``. * @example * ```ts * cleanTemplate('Copyright (?\\d{4})') // 'Copyright ' * ``` */ export declare const cleanTemplate: (text: string) => string; /** * Result of extracting capture values and positions from modified text. * * Returned by {@link extractCaptures} when every compiled line pattern matches. */ export interface ExtractResult { resolvedText: string; captures: Record; captureRangesInText2: CaptureRange[]; } /** * Extracts captures from modifiedText using context-anchored, gap-flexible regexes. * * Reuses compiled per-line regexes to search text2 with the `d` flag for * `match.indices`, then builds resolvedText from the retained source matches. * * @param originalText - The template text containing named capture groups. * @param modifiedText - The actual text (text2) to extract captures from. * @param parseResult - The result of parsing capture groups from originalText. * @returns The resolved text, captures, and capture ranges in text2, * or null if any line's regex fails to match. */ export declare const extractCaptures: (originalText: string, modifiedText: string, parseResult: ParseResult) => ExtractResult | null; /** * Walks through diffs and tags segments that overlap with capture ranges in text2. * * Tracks position in text2 (modifiedText) as it processes each diff segment: * - **Equal (0):** Advances text2Pos. Splits at capture boundaries and tags * overlapping parts with the capture group name. * - **Insert (1):** Advances text2Pos only. Checks for overlap with capture * ranges and tags overlapping parts. * - **Remove (-1):** Does not advance text2Pos. Passes through as-is. * * @param diffs - The diff tuples from diff-match-patch (resolvedText vs modifiedText). * @param captureRanges - The capture ranges with positions in text2. * @returns An array of DisplayDiff objects with expected group tagging applied. */ export declare const tagExpectedRegions: (diffs: [number, string][], captureRanges: CaptureRange[]) => DisplayDiff[]; export {};