get computedStyle()

in packages/core/src/text/paragraph.ts [51:83]


  get computedStyle(): ComputedParagraphStyle {

    const { defaultStyle } = ParagraphStyle

    const fontProps = this.font ? FontProps.from(this.font) : null
    const fontSize = fontProps?.['font-size'] ?? `${this.fontSize ?? defaultStyle.fontSize}px`
    const fontStyle = fontProps?.['font-style'] ?? this.fontStyle ?? defaultStyle.fontStyle
    const fontVariant = fontProps?.['font-variant'] ?? this.fontVariant ?? defaultStyle.fontVariant
    const fontWeight = fontProps?.['font-weight'] ?? this.fontWeight ?? defaultStyle.fontWeight
    const fontFamily = fontProps?.['font-family'] ?? this.fontFamily ?? defaultStyle.fontFamily

    const lineHeight = fontProps?.['line-height']
      ? FontProps.getLengthValue(String(fontProps?.['line-height']), 'px')
      : this.lineHeight ?? defaultStyle.lineHeight
    const font = `${fontStyle} ${fontVariant} ${fontWeight} ${fontSize} ${fontFamily}`
    const color = this.color ?? defaultStyle.color
    const maxLines = typeof this.maxLines === 'number'
      ? this.maxLines
      : this.maxLines === 'none'
        ? 0
        : defaultStyle.maxLines

    const textAlign = this.textAlign ?? defaultStyle.textAlign

    return {
      font,
      lineHeight,
      color,
      maxLines,
      textOverflow: defaultStyle.textOverflow,
      textAlign,
    }
  }