import * as THREE from "three" ; /**
 * Unit of measurement used to specify a font's size.
 */ export enum FontUnit { Em , Pixel , Point , Percent } /**
 * Pair of unit and size specifying a font's size.
 */ export interface FontSize { unit : FontUnit ; size : number ; backgroundSize : number ; } /**
 * Style to be used when rendering glyphs.
 */ export enum FontStyle { Regular , Bold , Italic , BoldItalic } /**
 * Variant to be used when rendering.
 */ export enum FontVariant { Regular , AllCaps , SmallCaps } /**
 * Vertical alignment to be used when placing text.
 */ export enum VerticalAlignment { Above = 0.0 , Center = - 0.5 , Below = - 1.0 } /**
 * Horizontal alignment to be used when placing text.
 */ export enum HorizontalAlignment { Left = 0.0 , Center = - 0.5 , Right = - 1.0 } /**
 * Vertical position of text area relative to the placement context (point, line).
 */ export enum VerticalPlacement { Top = 0.0 , Center = - 0.5 , Bottom = - 1.0 } note export enum HorizontalPlacement { Left = - 1.0 , Center = - 0.5 , Right = 0.0 } export interface TextPlacement { v : VerticalPlacement ; h : HorizontalPlacement ; } export type TextPlacements = TextPlacement [ ] ; /**
 * Text wrapping rule used when `lineWidth` is reached.
 */ export enum WrappingMode { None , Character , Word } hidden internal export function hAlignFromPlacement ( hP ) { return ( hP as unknown ) as HorizontalAlignment ; } hidden internal export function vAlignFromPlacement ( vP ) { return ( vP as unknown ) as VerticalAlignment ; } hidden internal export function hPlacementFromAlignment ( hA ) { return ( hA as unknown ) as HorizontalPlacement ; } hidden internal export function vPlacementFromAlignment ( vA ) { return ( vA as unknown ) as VerticalPlacement ; } /**
 * Namespace containing default values for all members of [[TextRenderParameters]] and
 * [[TextLayoutParameters]].
 */ export namespace DefaultTextStyle { export const DEFAULT_FONT_NAME = "" ; export const DEFAULT_FONT_SIZE = { unit : Object . freeze ( FontUnit . Pixel ) , size : Object . freeze ( 16.0 ) , backgroundSize : Object . freeze ( 0.0 ) } ; export const DEFAULT_FONT_STYLE = FontStyle . Regular ; export const DEFAULT_FONT_VARIANT = FontVariant . Regular ; export const DEFAULT_ROTATION = 0.0 ; export const DEFAULT_COLOR = new THREE . Color ( 0x000000 ) ; export const DEFAULT_OPACITY = 1.0 ; export const DEFAULT_BACKGROUND_COLOR = new THREE . Color ( 0x000000 ) ; export const DEFAULT_BACKGROUND_OPACITY = 0.0 ; export const DEFAULT_TRACKING = 0.0 ; export const DEFAULT_LEADING = 0.0 ; export const DEFAULT_MAX_LINES = Infinity ; export const DEFAULT_LINE_WIDTH = Infinity ; export const DEFAULT_CANVAS_ROTATION = 0.0 ; export const DEFAULT_LINE_ROTATION = 0.0 ; export const DEFAULT_WRAPPING_MODE = WrappingMode . Word ; export const DEFAULT_VERTICAL_ALIGNMENT = VerticalAlignment . Above ; export const DEFAULT_HORIZONTAL_ALIGNMENT = HorizontalAlignment . Left ; export const DEFAULT_PLACEMENTS = [ ] ; } /**
 * [[TextCanvas]] text rendering parameters.
 */ export interface TextRenderParameters { fontName ? : string ; fontSize ? : FontSize ; fontStyle ? : FontStyle ; fontVariant ? : FontVariant ; rotation ? : number ; color ? : THREE . Color ; backgroundColor ? : THREE . Color ; opacity ? : number ; backgroundOpacity ? : number ; } /**
 * [[TextCanvas]] text rendering style.
 */ export class TextRenderStyle { private m_params : TextRenderParameters ; param params returns constructor ( params = { } ) { this . m_params = { fontName : params . fontName !== undefined ? params . fontName : DefaultTextStyle . DEFAULT_FONT_NAME , fontSize : params . fontSize !== undefined ? { ... params . fontSize } : { unit : DefaultTextStyle . DEFAULT_FONT_SIZE . unit , size : DefaultTextStyle . DEFAULT_FONT_SIZE . size , backgroundSize : DefaultTextStyle . DEFAULT_FONT_SIZE . backgroundSize } , fontStyle : params . fontStyle !== undefined ? params . fontStyle : DefaultTextStyle . DEFAULT_FONT_STYLE , fontVariant : params . fontVariant !== undefined ? params . fontVariant : DefaultTextStyle . DEFAULT_FONT_VARIANT , rotation : params . rotation !== undefined ? params . rotation : DefaultTextStyle . DEFAULT_ROTATION , color : params . color !== undefined ? params . color . clone ( ) : DefaultTextStyle . DEFAULT_COLOR . clone ( ) , opacity : params . opacity !== undefined ? params . opacity : DefaultTextStyle . DEFAULT_OPACITY , backgroundColor : params . backgroundColor !== undefined ? params . backgroundColor . clone ( ) : DefaultTextStyle . DEFAULT_BACKGROUND_COLOR . clone ( ) , backgroundOpacity : params . backgroundOpacity !== undefined ? params . backgroundOpacity : DefaultTextStyle . DEFAULT_BACKGROUND_OPACITY } ; } /**
     * Current [[TextRenderParameters]] for this style.
     */ get params ( ) : TextRenderParameters { return this . m_params ; } set params ( value ) { this . m_params = { ... this . m_params , ... value } ; } /**
     * Name of the preferred [[Font]] to be used when rendering.
     */ get fontName ( ) : string { return this . m_params . fontName ! ; } set fontName ( value ) { this . m_params . fontName = value ; } /**
     * Collection of unit and sizes to apply for the currently active [[Font]].
     */ get fontSize ( ) : FontSize { return this . m_params . fontSize ! ; } set fontSize ( value ) { this . m_params . fontSize = { ... value } ; } /**
     * Glyph style to apply for the currently active [[Font]].
     */ get fontStyle ( ) : FontStyle { return this . m_params . fontStyle ! ; } set fontStyle ( value ) { this . m_params . fontStyle = value ; } /**
     * Glyph variant to apply for the currently active [[Font]].
     */ get fontVariant ( ) : FontVariant { return this . m_params . fontVariant ! ; } set fontVariant ( value ) { this . m_params . fontVariant = value ; } /**
     * Glyph local rotation (radians).
     */ get rotation ( ) : number { return this . m_params . rotation ! ; } set rotation ( value ) { this . m_params . rotation = value ; } /**
     * Glyph color.
     */ get color ( ) : THREE . Color { return this . m_params . color ! ; } set color ( value ) { this . m_params . color ! . copy ( value ) ; } /**
     * Glyph background color.
     */ get backgroundColor ( ) : THREE . Color { return this . m_params . backgroundColor ! ; } set backgroundColor ( value ) { this . m_params . backgroundColor ! . copy ( value ) ; } /**
     * Glyph opacity.
     */ get opacity ( ) : number { return this . m_params . opacity ! ; } set opacity ( value ) { this . m_params . opacity = value ; } /**
     * Glyph background opacity.
     */ get backgroundOpacity ( ) : number { return this . m_params . backgroundOpacity ! ; } set backgroundOpacity ( value ) { this . m_params . backgroundOpacity = value ; } param params returns clone ( params = { } ) { return new TextRenderStyle ( { ... this . m_params , ... params } ) ; } param source returns copy ( source ) { this . m_params . fontName = source . fontName ; this . m_params . fontSize = { ... source . fontSize } ; this . m_params . fontStyle = source . fontStyle ; this . m_params . fontVariant = source . fontVariant ; this . m_params . rotation = source . rotation ; this . m_params . color ! . copy ( source . color ) ; this . m_params . backgroundColor ! . copy ( source . backgroundColor ) ; this . m_params . opacity = source . opacity ; this . m_params . backgroundOpacity = source . backgroundOpacity ; return this ; } } /**
 * [[TextCanvas]] text layout parameters.
 */ export interface TextLayoutParameters { tracking ? : number ; leading ? : number ; maxLines ? : number ; lineWidth ? : number ; canvasRotation ? : number ; lineRotation ? : number ; wrappingMode ? : WrappingMode ; verticalAlignment ? : VerticalAlignment ; horizontalAlignment ? : HorizontalAlignment ; placements ? : TextPlacements ; } /**
 * [[TextCanvas]] text rendering style.
 */ export class TextLayoutStyle { private m_params : TextLayoutParameters ; param params returns constructor ( params = { } ) { const { horizontalAlignment , verticalAlignment , placements } = resolvePlacementAndAlignment ( params . horizontalAlignment , params . verticalAlignment , params . placements ) ; this . m_params = { tracking : params . tracking !== undefined ? params . tracking : DefaultTextStyle . DEFAULT_TRACKING , leading : params . leading !== undefined ? params . leading : DefaultTextStyle . DEFAULT_LEADING , maxLines : params . maxLines !== undefined ? params . maxLines : DefaultTextStyle . DEFAULT_MAX_LINES , lineWidth : params . lineWidth !== undefined ? params . lineWidth : DefaultTextStyle . DEFAULT_LINE_WIDTH , canvasRotation : params . canvasRotation !== undefined ? params . canvasRotation : DefaultTextStyle . DEFAULT_CANVAS_ROTATION , lineRotation : params . lineRotation !== undefined ? params . lineRotation : DefaultTextStyle . DEFAULT_LINE_ROTATION , wrappingMode : params . wrappingMode !== undefined ? params . wrappingMode : DefaultTextStyle . DEFAULT_WRAPPING_MODE , verticalAlignment , horizontalAlignment , placements } ; } /**
     * Current [[TextLayoutParameters]] for this style.
     */ get params ( ) : TextLayoutParameters { return this . m_params ; } set params ( value ) { this . m_params = { ... this . m_params , ... value } ; } /**
     * Inter-glyph spacing (pixels). Scaled by [[FontSize]].
     */ get tracking ( ) : number { return this . m_params . tracking ! ; } set tracking ( value ) { this . m_params . tracking = value ; } /**
     * Inter-line spacing (pixels). Scaled by [[FontSize]].
     */ get leading ( ) : number { return this . m_params . leading ! ; } set leading ( value ) { this . m_params . leading = value ; } /**
     * Maximum number of lines to be considered when using [[TextCanvas]].
     */ get maxLines ( ) : number { return this . m_params . maxLines ! ; } set maxLines ( value ) { this . m_params . maxLines = value ; } /**
     * Maximum line width (pixels).
     */ get lineWidth ( ) : number { return this . m_params . lineWidth ! ; } set lineWidth ( value ) { this . m_params . lineWidth = value ; } /**
     * [[TextCanvas]] rotation (radians).
     */ get canvasRotation ( ) : number { return this . m_params . canvasRotation ! ; } set canvasRotation ( value ) { this . m_params . canvasRotation = value ; } /**
     * Line typesetting rotation (radians).
     */ get lineRotation ( ) : number { return this . m_params . lineRotation ! ; } set lineRotation ( value ) { this . m_params . lineRotation = value ; } /**
     * Wrapping (line-breaking) mode.
     */ get wrappingMode ( ) : WrappingMode { return this . m_params . wrappingMode ! ; } set wrappingMode ( value ) { this . m_params . wrappingMode = value ; } /**
     * Text position regarding the baseline.
     */ get verticalAlignment ( ) : VerticalAlignment { return this . m_params . verticalAlignment ! ; } set verticalAlignment ( value ) { this . m_params . verticalAlignment = value ; } /**
     * Text position inside a line.
     */ get horizontalAlignment ( ) : HorizontalAlignment { return this . m_params . horizontalAlignment ! ; } set horizontalAlignment ( value ) { this . m_params . horizontalAlignment = value ; } note get placements ( ) : TextPlacements { return this . m_params . placements ! ; } set placements ( value ) { const { horizontalAlignment , verticalAlignment , placements } = resolvePlacementAndAlignment ( this . horizontalAlignment , this . verticalAlignment , value ) ; this . m_params . horizontalAlignment = horizontalAlignment ; this . m_params . verticalAlignment = verticalAlignment ; this . m_params . placements = placements ; } param params returns clone ( params = { } ) { return new TextLayoutStyle ( { ... this . m_params , ... params } ) ; } param other returns copy ( other ) { this . params = { ... other . params } ; return this ; } } param hAlignment param vAlignment param placementsOpt internal export function resolvePlacementAndAlignment ( hAlignment ? , vAlignment ? , placementsOpt ? ) { const placements = placementsOpt ?. map ( v => ( { ... v } ) ) ?? DefaultTextStyle . DEFAULT_PLACEMENTS . map ( v => ( { ... v } ) ) ; const horizontalAlignment = placements . length > 0 ? hAlignFromPlacement ( placements [ 0 ] . h ) : hAlignment ?? DefaultTextStyle . DEFAULT_HORIZONTAL_ALIGNMENT ; const verticalAlignment = placements . length > 0 ? vAlignFromPlacement ( placements [ 0 ] . v ) : vAlignment ?? DefaultTextStyle . DEFAULT_VERTICAL_ALIGNMENT ; return { horizontalAlignment , verticalAlignment , placements } ; }