/** * Format-based Search for DOCX Documents * * Provides the ability to search for text runs that match specific formatting * criteria (bold, italic, font, color, style, etc.) and optionally match text patterns. * * @stability experimental * * @example * ```ts * import { searchByFormat, type FormatCriteria } from "excelts/word"; * * // Find all bold red text * const results = searchByFormat(doc, { bold: true, color: "FF0000" }); * * // Find all text in "Heading1" style * const headings = searchByFormat(doc, { paragraphStyle: "Heading1" }); * * // Find specific text with specific formatting * const results = searchByFormat(doc, { bold: true, textMatch: /TODO/i }); * ``` */ import type { DocxDocument, RunProperties } from "../types.js"; /** Criteria for matching text formatting. All fields are optional — they act as AND filters. */ export interface FormatCriteria { /** Match bold text. */ readonly bold?: boolean; /** Match italic text. */ readonly italic?: boolean; /** Match underlined text (any style). */ readonly underline?: boolean; /** Match strikethrough text. */ readonly strike?: boolean; /** Match text with this font (case-insensitive). */ readonly font?: string; /** Match text with this font size in half-points. */ readonly size?: number; /** Match text with this color (hex, case-insensitive, without '#'). */ readonly color?: string; /** Match text with this highlight color. */ readonly highlight?: string; /** Match text with superscript. */ readonly superscript?: boolean; /** Match text with subscript. */ readonly subscript?: boolean; /** Match text with all-caps. */ readonly caps?: boolean; /** Match text with small-caps. */ readonly smallCaps?: boolean; /** Match text with hidden attribute. */ readonly hidden?: boolean; /** Match runs whose paragraph has this style name/id. */ readonly paragraphStyle?: string; /** Match runs with this character style name/id. */ readonly characterStyle?: string; /** Optional text pattern (string or regex) to additionally filter by content. */ readonly textMatch?: string | RegExp; } /** A single format search result. */ export interface FormatSearchResult { /** Index in the document body (for BodyContent). */ readonly bodyIndex: number; /** Paragraph index within the body content (for tables, the cell paragraph). */ readonly paragraphIndex: number; /** Index of the matching run within the paragraph's children. */ readonly runIndex: number; /** The matched text. */ readonly text: string; /** The run's properties (formatting). */ readonly properties: RunProperties | undefined; /** The paragraph style (if any). */ readonly paragraphStyle: string | undefined; /** Location context for display. */ readonly location: "body" | "header" | "footer" | "footnote" | "endnote"; } /** * Search a document for text runs matching specific formatting criteria. * * @param doc - The document to search. * @param criteria - Formatting criteria (all specified fields must match). * @returns Array of matching results. */ export declare function searchByFormat(doc: DocxDocument, criteria: FormatCriteria): FormatSearchResult[]; /** * Count the number of runs matching specific formatting criteria. * * @param doc - The document to search. * @param criteria - Formatting criteria. * @returns The count of matching runs. */ export declare function countByFormat(doc: DocxDocument, criteria: FormatCriteria): number; /** * Get all unique formatting styles used in the document. * Useful for understanding what formats exist before searching. * * @param doc - The document to analyze. * @returns Array of unique RunProperties objects found. */ export declare function getUsedFormats(doc: DocxDocument): RunProperties[];