Text.d.ts 4.1 KB

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