UNPKG

uicore-ts

Version:

UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha

82 lines (81 loc) 3.07 kB
export interface TextMeasurementStyle { font: string; fontSize: number; lineHeight: number; whiteSpace: string; paddingLeft: number; paddingRight: number; paddingTop: number; paddingBottom: number; letterSpacing: number; textTransform: string; } export declare class UITextMeasurement { private static _preparedCache; private static globalStyleCache; private static elementToCacheKey; private static _canvas; private static _context; private static measurementElement; private static generateStyleCacheKey; private static getSemanticCacheKey; private static getCanvasContext; private static getMeasurementElement; private static applyTextTransform; private static parseLineHeight; private static isPlainText; private static hasSimpleFormatting; private static getPreparedText; private static calculatePlainTextSizeViaPretext; private static _fontsLoadingSet; static measureTextWidth(text: string, font: string, letterSpacing?: number): number; private static wrapNormal; private static wrapPreservingWhitespace; private static wrapText; private static calculatePlainTextSizeViaCanvas; private static calculatePlainTextSize; private static measureWithDOM; static getElementStyles(element: HTMLElement, providedStyles?: TextMeasurementStyle): TextMeasurementStyle; /** * Calculate intrinsic content size for text. * * Routing: * plain text, no letter-spacing, pretext available → pretext (best accuracy + speed) * plain text, letter-spacing or no pretext → hand-rolled canvas * simple inline HTML (<b>/<i>/etc.) → same as above, tags stripped first * complex HTML → DOM measurement */ static calculateTextSize(element: HTMLElement, content: string, constrainingWidth?: number, constrainingHeight?: number, providedStyles?: TextMeasurementStyle): { width: number; height: number; }; /** * Clears all caches (prepared text, style, element, and canvas context). * Call on documentFontsDidLoad or app cleanup. */ static clearCaches(): void; /** * Invalidate cached styles for a specific element. * Also clears the pretext prepared-text cache conservatively since the * font string may have changed. */ static invalidateElement(element: HTMLElement): void; /** * Invalidate cache for elements with a specific CSS class. */ static invalidateClass(className: string): void; /** * Pre-warm the style cache by reading styles from representative elements. */ static prewarmCache(elements: HTMLElement[]): void; /** * Clean up all resources (call on app teardown). */ static cleanup(): void; } export interface UITextViewMeasurementMethods { intrinsicContentSizeEfficient(constrainingWidth?: number, constrainingHeight?: number): { width: number; height: number; }; }