@veltdev/tiptap-velt-comments
Version:
Tiptap Extension to add Google Docs-style overlay comments to your Tiptap editor. Works with the Velt Collaboration SDK.
81 lines (80 loc) • 2.83 kB
TypeScript
/**
* Pure utility functions with zero side effects.
* These functions contain algorithmic logic extracted from legacy code.
*
* IMPORTANT: This module MUST NOT import any external SDKs or have side effects.
* All functions must be pure: input → output, deterministic, no mutations.
*/
/**
* Computes the KMP (Knuth-Morris-Pratt) failure function (LPS array).
* This is used for efficient pattern matching in text search.
*
* @param pattern The pattern string to compute the failure function for
* @returns Longest proper prefix array (LPS array)
*
* @example
* ```typescript
* const lps = computeKMPTable("abcabc");
* // Returns: [0, 0, 0, 1, 2, 3]
* ```
*/
export declare const computeKMPTable: (pattern: string) => number[];
/**
* Finds all occurrences of a pattern in text using the KMP algorithm.
*
* @param text The text to search in
* @param pattern The pattern to search for
* @param startPos Starting position offset (default: 0)
* @param maxOccurrences Maximum number of occurrences to find (optional)
* @returns Array of start positions (0-based indices in the text)
*
* @example
* ```typescript
* const positions = kmpSearch("abcabcabc", "abc", 0, 2);
* // Returns: [0, 3] (first 2 occurrences)
* ```
*/
export declare const kmpSearch: (text: string, pattern: string, startPos?: number, maxOccurrences?: number) => number[];
/**
* Maps text positions in a combined string back to document positions.
* Used when searching across multiple text nodes that have been concatenated.
*
* @param textNodes Array of text nodes with their document positions
* @param textPositions Positions in the combined text (from kmpSearch)
* @param patternLength Length of the pattern being searched for
* @returns Array of { from, to } ranges in document coordinates
*
* @example
* ```typescript
* const textNodes = [
* { text: "Hello ", pos: 0 },
* { text: "World", pos: 6 }
* ];
* const positions = [0]; // Found at start of combined text
* const ranges = mapTextPositionsToDocument(textNodes, positions, 5);
* // Returns: [{ from: 0, to: 5 }]
* ```
*/
export declare const mapTextPositionsToDocument: (textNodes: Array<{
text: string;
pos: number;
}>, textPositions: number[], patternLength: number) => Array<{
from: number;
to: number;
}>;
/**
* Compares two maps for equality.
* Checks if both maps have the same size and identical key-value pairs.
*
* @param map1 First map to compare
* @param map2 Second map to compare
* @returns True if maps are equal, false otherwise
*
* @example
* ```typescript
* const map1 = new Map([['a', true], ['b', false]]);
* const map2 = new Map([['a', true], ['b', false]]);
* areMapsEqual(map1, map2); // Returns: true
* ```
*/
export declare const areMapsEqual: <K, V>(map1: Map<K, V>, map2: Map<K, V>) => boolean;