UNPKG

modern-text

Version:

Measure and render text in a way that describes the DOM.

87 lines (69 loc) 3.92 kB
import { NormalizedStyle, NormalizedHighlight } from 'modern-idoc'; import { BoundingBox, Path2DDrawStyle, Path2D, Matrix3, Path2DSet } from 'modern-path2d'; import { T as Text, a as TextPlugin, b as TextOptions, M as MeasureResult, c as TextRenderOptions } from './shared/modern-text.BAfGVPZ9.js'; export { C as Character, F as Fragment, f as MeasuredCharacter, e as MeasuredFragment, d as MeasuredParagraph, g as Measurer, P as Paragraph, h as TextEventMap, m as measureDOMResult, t as textDefaultStyle } from './shared/modern-text.BAfGVPZ9.js'; import 'modern-font'; declare function parseColor(ctx: CanvasRenderingContext2D, source: string | CanvasGradient | CanvasPattern, box: BoundingBox): string | CanvasGradient | CanvasPattern; declare function uploadColor(style: NormalizedStyle, box: BoundingBox, ctx: CanvasRenderingContext2D): void; interface LinearGradient { x0: number; y0: number; x1: number; y1: number; stops: { offset: number; color: string; }[]; } interface DrawShapePathsOptions extends NormalizedStyle, Omit<Partial<Path2DDrawStyle>, 'fill' | 'outline'> { ctx: CanvasRenderingContext2D; path: Path2D; fontSize: number; clipRect?: BoundingBox; } declare function drawPath(options: DrawShapePathsOptions): void; declare function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, boundingBox: BoundingBox): void; declare function uploadColors(ctx: CanvasRenderingContext2D, text: Text): void; declare function definePlugin(options: TextPlugin): TextPlugin; declare function measureText(options: TextOptions, load: true): Promise<MeasureResult>; declare function measureText(options: TextOptions): MeasureResult; type RenderTextOptions = TextOptions & TextRenderOptions; declare function renderText(options: RenderTextOptions, load: true): Promise<void>; declare function renderText(options: RenderTextOptions): void; declare function backgroundPlugin(): TextPlugin; declare function getHighlightStyle(style: NormalizedStyle): NormalizedHighlight; declare function highlightPlugin(): TextPlugin; declare function listStylePlugin(): TextPlugin; declare function outlinePlugin(): TextPlugin; declare function renderPlugin(): TextPlugin; declare function getTransform2D(text: Text, style: NormalizedStyle): Matrix3; declare function textDecorationPlugin(): TextPlugin; interface SVGLoader { loaded: Map<string, string>; needsLoad: (source: string) => boolean; load: (svg: string) => Promise<void>; } declare function createSVGLoader(): SVGLoader; interface SVGParser { parsed: Map<string, { dom: SVGElement; pathSet: Path2DSet; }>; parse: (svg: string) => { dom: SVGElement; pathSet: Path2DSet; }; } declare function createSVGParser(loader: SVGLoader): SVGParser; interface ValueContext { total: number; fontSize: number; } declare function parseValueNumber(value: string | number, ctx: ValueContext): number; declare function parseColormap(colormap: 'none' | Record<string, string>): Record<string, string>; declare function isEqualObject(obj1: Record<string, any>, obj2: Record<string, any>): boolean; declare function isEqualValue(val1: any, val2: any): boolean; declare function hexToRgb(hex: string): string | null; declare function filterEmpty(val: Record<string, any> | undefined): Record<string, any> | undefined; export { MeasureResult, Text, TextOptions, TextPlugin, TextRenderOptions, backgroundPlugin, createSVGLoader, createSVGParser, definePlugin, drawPath, filterEmpty, getHighlightStyle, getTransform2D, hexToRgb, highlightPlugin, isEqualObject, isEqualValue, listStylePlugin, measureText, outlinePlugin, parseColor, parseColormap, parseValueNumber, renderPlugin, renderText, setupView, textDecorationPlugin, uploadColor, uploadColors }; export type { DrawShapePathsOptions, LinearGradient, RenderTextOptions, SVGLoader, SVGParser };