Text.d.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle } from '../core/types';
  2. import TSpan from './TSpan';
  3. import ZRImage from './Image';
  4. import Rect from './shape/Rect';
  5. import BoundingRect from '../core/BoundingRect';
  6. import { MatrixArray } from '../core/matrix';
  7. import Displayable, { DisplayableStatePropNames, DisplayableProps } from './Displayable';
  8. import { ZRenderType } from '../zrender';
  9. import Animator from '../animation/Animator';
  10. import Transformable from '../core/Transformable';
  11. import { ElementCommonState } from '../Element';
  12. import { GroupLike } from './Group';
  13. export interface TextStylePropsPart {
  14. text?: string;
  15. fill?: string;
  16. stroke?: string;
  17. strokeNoScale?: boolean;
  18. opacity?: number;
  19. fillOpacity?: number;
  20. strokeOpacity?: number;
  21. lineWidth?: number;
  22. lineDash?: false | number[];
  23. lineDashOffset?: number;
  24. borderDash?: false | number[];
  25. borderDashOffset?: number;
  26. font?: string;
  27. textFont?: string;
  28. fontStyle?: FontStyle;
  29. fontWeight?: FontWeight;
  30. fontFamily?: string;
  31. fontSize?: number | string;
  32. align?: TextAlign;
  33. verticalAlign?: TextVerticalAlign;
  34. lineHeight?: number;
  35. width?: number | string;
  36. height?: number;
  37. tag?: string;
  38. textShadowColor?: string;
  39. textShadowBlur?: number;
  40. textShadowOffsetX?: number;
  41. textShadowOffsetY?: number;
  42. backgroundColor?: string | {
  43. image: ImageLike | string;
  44. };
  45. padding?: number | number[];
  46. margin?: number;
  47. borderColor?: string;
  48. borderWidth?: number;
  49. borderRadius?: number | number[];
  50. shadowColor?: string;
  51. shadowBlur?: number;
  52. shadowOffsetX?: number;
  53. shadowOffsetY?: number;
  54. }
  55. export interface TextStyleProps extends TextStylePropsPart {
  56. text?: string;
  57. x?: number;
  58. y?: number;
  59. width?: number;
  60. rich?: Dictionary<TextStylePropsPart>;
  61. overflow?: 'break' | 'breakAll' | 'truncate' | 'none';
  62. lineOverflow?: 'truncate';
  63. ellipsis?: string;
  64. placeholder?: string;
  65. truncateMinChar?: number;
  66. }
  67. export interface TextProps extends DisplayableProps {
  68. style?: TextStyleProps;
  69. zlevel?: number;
  70. z?: number;
  71. z2?: number;
  72. culling?: boolean;
  73. cursor?: string;
  74. }
  75. export declare type TextState = Pick<TextProps, DisplayableStatePropNames> & ElementCommonState;
  76. export declare type DefaultTextStyle = Pick<TextStyleProps, 'fill' | 'stroke' | 'align' | 'verticalAlign'> & {
  77. autoStroke?: boolean;
  78. };
  79. export declare const DEFAULT_TEXT_ANIMATION_PROPS: MapToType<TextProps, boolean>;
  80. interface ZRText {
  81. animate(key?: '', loop?: boolean): Animator<this>;
  82. animate(key: 'style', loop?: boolean): Animator<this['style']>;
  83. getState(stateName: string): TextState;
  84. ensureState(stateName: string): TextState;
  85. states: Dictionary<TextState>;
  86. stateProxy: (stateName: string) => TextState;
  87. }
  88. declare class ZRText extends Displayable<TextProps> implements GroupLike {
  89. type: string;
  90. style: TextStyleProps;
  91. overlap: 'hidden' | 'show' | 'blur';
  92. innerTransformable: Transformable;
  93. private _children;
  94. private _childCursor;
  95. private _defaultStyle;
  96. constructor(opts?: TextProps);
  97. childrenRef(): (ZRImage | Rect | TSpan)[];
  98. update(): void;
  99. updateTransform(): void;
  100. getLocalTransform(m?: MatrixArray): MatrixArray;
  101. getComputedTransform(): MatrixArray;
  102. private _updateSubTexts;
  103. addSelfToZr(zr: ZRenderType): void;
  104. removeSelfFromZr(zr: ZRenderType): void;
  105. getBoundingRect(): BoundingRect;
  106. setDefaultTextStyle(defaultTextStyle: DefaultTextStyle): void;
  107. setTextContent(textContent: never): void;
  108. protected _mergeStyle(targetStyle: TextStyleProps, sourceStyle: TextStyleProps): TextStyleProps;
  109. private _mergeRich;
  110. getAnimationStyleProps(): MapToType<TextProps, boolean>;
  111. private _getOrCreateChild;
  112. private _updatePlainTexts;
  113. private _updateRichTexts;
  114. private _placeToken;
  115. private _renderBackground;
  116. static makeFont(style: TextStylePropsPart): string;
  117. }
  118. export declare function parseFontSize(fontSize: number | string): string;
  119. export declare function hasSeparateFont(style: Pick<TextStylePropsPart, 'fontSize' | 'fontFamily' | 'fontWeight'>): string | number | true;
  120. export declare function normalizeTextStyle(style: TextStyleProps): TextStyleProps;
  121. export default ZRText;