import type { Bidi, BidiDirection } from 'bidi-js'; import type { FontResolver, FontResolverResult, FontStyle, FontWeight, UserFont } from './FontResolver.js'; import type { GlyphBoundsChunk, GlyphBoundsRect } from './GlyphsGeometry.js'; export type PercentageAnchor = `${number}%`; export type AnchorXValue = number | 'left' | 'center' | 'right' | PercentageAnchor; export type AnchorYValue = number | 'top' | 'top-baseline' | 'top-cap' | 'top-ex' | 'middle' | 'bottom-baseline' | 'bottom' | PercentageAnchor; export type TextAlignment = 'left' | 'center' | 'right' | 'justify'; export type TextWhiteSpace = 'normal' | 'nowrap'; export type TextOverflowWrap = 'normal' | 'break-word'; export interface TypesetParams { readonly text?: string; readonly font?: string | UserFont | readonly UserFont[]; readonly lang?: string; readonly sdfGlyphSize?: number; readonly fontSize?: number; readonly fontWeight?: FontWeight; readonly fontStyle?: FontStyle; readonly letterSpacing?: number; readonly lineHeight?: 'normal' | number; readonly maxWidth?: number; readonly direction?: BidiDirection; readonly textAlign?: TextAlignment; readonly textIndent?: number; readonly whiteSpace?: TextWhiteSpace; readonly overflowWrap?: TextOverflowWrap; readonly anchorX?: AnchorXValue; readonly anchorY?: AnchorYValue; readonly metricsOnly?: boolean; readonly unicodeFontsURL?: string | null; readonly preResolvedFonts?: FontResolverResult | null; readonly includeCaretPositions?: boolean; readonly chunkedBoundsSize?: number; readonly colorRanges?: Readonly> | null; /** Passed through the worker request for TextBuilder; layout itself does not consume it. */ readonly gpuAccelerateSDF?: boolean; } export type TypesetBounds = GlyphBoundsRect; export type TypesetChunkedBounds = GlyphBoundsChunk; export interface TypesetGlyphData { readonly path: string; readonly pathBounds: TypesetBounds; } export type TypesetGlyphDataByFont = Record>; export interface TypesetFontData { readonly src: string; readonly unitsPerEm: number; readonly ascender: number; readonly descender: number; readonly lineHeight: number; readonly capHeight: number; readonly xHeight: number; } export interface TypesetTimings { fontLoad: number; typesetting: number; quads?: number; sdf?: Record; sdfTotal?: number; total?: number; } export interface TypesetResult { /** Glyph ids are mutable because TextBuilder replaces them with atlas indices in-place. */ glyphIds: Uint16Array | null; glyphFontIndices: Uint8Array | null; glyphPositions: Float32Array | null; glyphData: TypesetGlyphDataByFont | null; fontData: TypesetFontData[]; caretPositions: Float32Array | null; glyphColors: Uint8Array | null; chunkedBounds: TypesetChunkedBounds[] | null; fontSize: number; topBaseline: number; blockBounds: TypesetBounds; visibleBounds: TypesetBounds | null; timings: TypesetTimings; } export interface TypesetRenderResult extends TypesetResult { glyphIds: Uint16Array; glyphFontIndices: Uint8Array; glyphPositions: Float32Array; glyphData: TypesetGlyphDataByFont; chunkedBounds: TypesetChunkedBounds[]; visibleBounds: TypesetBounds; } export interface TypesetMetricsResult extends TypesetResult { glyphIds: null; glyphFontIndices: null; glyphPositions: null; glyphData: null; caretPositions: null; glyphColors: null; chunkedBounds: null; visibleBounds: null; } export interface TypesetMeasurement { readonly width: number; readonly height: number; } export type TypesetterTypesetFunction = (params: TypesetParams, callback: (result: TypesetResult) => void) => void; export type TypesetterMeasureFunction = (params: TypesetParams, callback: (measurement: TypesetMeasurement) => void) => void; export interface Typesetter { readonly typeset: TypesetterTypesetFunction; readonly measure: TypesetterMeasureFunction; } /** * Factory function that creates a self-contained environment for processing text typesetting requests. * * This function deliberately has no runtime closure dependencies: worker-module serialization injects * both dependencies and evaluates the function source in an isolated global scope. */ export declare function createTypesetter(resolveFonts: FontResolver, bidi: Bidi): Typesetter;