/** * TextMeasurer — Server-side text measurement powered by @chenglou/pretext. * * Provides accurate multiline text height prediction and line counting * without a browser DOM. Uses @napi-rs/canvas to provide the Canvas * context that Pretext's prepare() phase requires. * * Usage: * const measurer = new TextMeasurer(); * const result = measurer.measure("Hello world", { maxWidth: 200 }); * // { height: 40, lineCount: 2 } */ export interface MeasureOptions { /** Maximum width in pixels for line wrapping. */ maxWidth: number; /** CSS font string (e.g., "16px Inter", "bold 14px sans-serif"). Default: "16px sans-serif". */ font?: string; /** Line height in pixels. Default: font-size * 1.5. */ lineHeight?: number; } export interface MeasureResult { /** Total height in pixels. */ height: number; /** Number of wrapped lines. */ lineCount: number; } export interface DetailedMeasureResult extends MeasureResult { /** Per-line text content and width. */ lines: Array<{ text: string; width: number; }>; } export interface OverflowCheck { /** Whether the text fits within the container. */ fits: boolean; /** Actual height needed. */ actualHeight: number; /** Container height. */ containerHeight: number; /** Number of lines. */ lineCount: number; /** How many pixels of overflow (negative = fits with room). */ overflow: number; } export interface BreakpointResult { /** Breakpoint name (e.g., "mobile", "tablet", "desktop"). */ breakpoint: string; /** Container width at this breakpoint. */ width: number; /** Whether text fits at this width. */ fits: boolean; /** Line count at this width. */ lineCount: number; /** Height at this width. */ height: number; } export declare class TextMeasurer { private cache; private approximateCache; private maxCacheSize; private initPromise; constructor(maxCacheSize?: number); /** Await canvas polyfill readiness. Optional — synchronous APIs fall back. */ ready(): Promise; /** Measure text: returns height and line count. */ measure(text: string, opts: MeasureOptions): MeasureResult; /** Measure text with per-line detail. */ measureDetailed(text: string, opts: MeasureOptions): DetailedMeasureResult; /** Check if text fits within a container. */ checkOverflow(text: string, opts: MeasureOptions & { containerHeight: number; }): OverflowCheck; /** Test text at multiple breakpoints. */ checkBreakpoints(text: string, opts?: { font?: string; lineHeight?: number; containerHeight?: number; breakpoints?: Record; }): BreakpointResult[]; /** Find the minimum width where text fits in a given number of lines. */ findMinWidth(text: string, opts: { maxLines: number; font?: string; lineHeight?: number; minWidth?: number; maxWidth?: number; }): number; /** Clear the internal measurement cache and Pretext's global cache. */ clearCache(): void; /** Get cache size for monitoring. */ get cacheSize(): number; private getPrepared; private trackApproximate; } export declare function getTextMeasurer(): TextMeasurer;