← All packages

API reference

@searsuite/sear-render-metrics

Platform-neutral text shaping and glyph measurement contracts.

16 exportsderived from source

classRenderContextTextShapersource ↗
class RenderContextTextShaper extends TextShaper

Portable fallback backed by the host's render-neutral text measurements.

constructorconstructor
RenderContextTextShaper(context: RenderContext): RenderContextTextShaper
context: RenderContext
Inherited members 3

Inherited from TextShaper.

classTextMeasurementManagersource ↗
class TextMeasurementManager

Owns reusable semantic text measurements for one editor runtime.

constructorconstructor
TextMeasurementManager(textShaper: TextShaper): TextMeasurementManager
textShaper: TextShaper
propertysymbolstatic
readonly symbol: typeof symbol

DI token for resolving the editor-local text measurement manager.

methodclear
clear(): void

Clears semantic measurements without taking ownership of the text shaper.

methodmeasureSpace
measureSpace(font: string): TextShapeResult

Measures one space for a font and reuses the editor-local result.

font: string
classTextShapersource ↗
class TextShaper

Abstract adapter boundary for HarfBuzz, Skia, browser-native, or platform text-shaping implementations.

Concrete adapters translate the normalized request to their shaping library and return engine-neutral glyph/cluster data.

constructorconstructor
TextShaper(): TextShaper
propertysymbolstatic
readonly symbol: symbol

DI token for resolving the editor-local text-shaper provider.

methodclearCache
clearCache(): void

Clears all cached shaping results owned by this adapter.

methodshape
shape(input: TextShapeInput): TextShapeResult

Shapes one homogeneous text run, reusing an identical cached request.

input: TextShapeInput
classWebTextShapersource ↗
class WebTextShaper extends TextShaper

Browser-native TextShaper backed by Canvas2D.

Canvas2D preserves the browser's native shaping for complete text runs but does not expose glyph ids or glyph ranges. Results therefore contain grapheme clusters and caret measurements while leaving glyphs empty. Call clearCache() after an asynchronously loaded font becomes available.

constructorconstructor
WebTextShaper(context: WebTextShaperContext): WebTextShaper

Creates a Web text shaper over a host-owned Canvas2D context.

context: WebTextShaperContext
Inherited members 3

Inherited from TextShaper.

classWebTextShaperErrorsource ↗
class WebTextShaperError extends SearError

Error raised when a Web text-shaping request cannot be represented by Canvas2D.

constructorconstructor
WebTextShaperError(message: string, details?: SearErrorDetails): WebTextShaperError

Creates a Web text-shaper error with stable diagnostics.

message: string
details: SearErrorDetails
propertycode
readonly code: "WEB_TEXT_SHAPER_ERROR"

Stable machine-readable identifier for this error category.

Inherited members 9

Inherited from SearError.

interfaceFontDescriptorInputsource ↗
interface FontDescriptorInput

Structured font values supplied by editor configuration and host contexts.

propertyfontFamily
readonly fontFamily: string
propertyfontSize
readonly fontSize: number
interfaceShapedCaretStopsource ↗
interface ShapedCaretStop

A logical caret boundary produced by the shaping implementation.

propertytextOffset
readonly textOffset: number

UTF-16 source-text offset for this caret boundary.

propertyx
readonly x: number

Advance position in the shaped run's logical direction.

interfaceShapedGlyphsource ↗
interface ShapedGlyph

One positioned glyph returned by a text-shaping implementation.

propertycluster
readonly cluster: number

UTF-16 offset of the source text cluster represented by this glyph.

propertyglyphId
readonly glyphId: number
propertyxAdvance
readonly xAdvance: number
propertyxOffset
readonly xOffset: number
propertyyAdvance
readonly yAdvance: number
propertyyOffset
readonly yOffset: number
interfaceShapedTextClustersource ↗
interface ShapedTextCluster

Mapping between source text and the glyph range generated for it.

propertyglyphEnd
readonly glyphEnd: number
propertyglyphStart
readonly glyphStart: number
propertytextEnd
readonly textEnd: number
propertytextStart
readonly textStart: number
interfaceTextShapeInputsource ↗
interface TextShapeInput

Input passed to a text-shaper implementation. Offsets are UTF-16 offsets.

propertydirection
readonly direction?: TextShapeDirection
propertyfeatures
readonly features?: Readonly<Record<string, TextShapeFeatureValue>>

Explicit OpenType feature settings, for example { liga: true, kern: true }.

propertyfont
readonly font: string

Font descriptor understood by the selected shaping implementation.

propertylanguage
readonly language?: string

ISO/BCP language tag, when known.

propertyscript
readonly script?: string

OpenType script tag, when known.

propertytext
readonly text: string
propertyvariations
readonly variations?: Readonly<Record<string, number>>

Variation-axis values for variable fonts, keyed by four-character axis tag.

interfaceTextShapeResultsource ↗
interface TextShapeResult

Engine-neutral result of shaping one homogeneous text run.

propertycaretStops
readonly caretStops: readonly ShapedCaretStop[]
propertyclusters
readonly clusters: readonly ShapedTextCluster[]
propertyfontAscent
readonly fontAscent?: number
propertyfontDescent
readonly fontDescent?: number
propertyfontLineGap
readonly fontLineGap?: number
propertyglyphs
readonly glyphs: readonly ShapedGlyph[]
propertyheight
readonly height: number

Total vertical advance, normally zero for horizontal text.

propertywidth
readonly width: number

Total horizontal advance of the shaped run.

interfaceWebTextShaperContextsource ↗
interface WebTextShaperContext

Native text settings and operations required by the Web adapter.

propertydirection
direction: CanvasDirection
propertyfont
font: string
propertyfontKerning
fontKerning?: CanvasFontKerning
methodmeasureText
measureText(text: string): TextMetrics
text: string
methodrestore
restore(): void
methodsave
save(): void
typeTextShapeDirectionsource ↗
type TextShapeDirection = "ltr" | "rtl"

Direction of a shaped text run in logical document order.

typeTextShapeFeatureValuesource ↗
type TextShapeFeatureValue = boolean | number

OpenType feature value accepted by a text-shaper adapter.

functioncreateFontDescriptorsource ↗
createFontDescriptor(input: FontDescriptorInput): string

Creates the low-level font descriptor consumed by text shaping and rendering.

input: FontDescriptorInput
functioncreateWebTextShaperContextsource ↗
createWebTextShaperContext(renderContext: RenderContext): WebTextShaperContext

Adapts the shared render context to the Web shaper contract.

renderContext: RenderContext