UNPKG

4.41 kBTypeScriptView Raw
1import { TextAlign, TextVerticalAlign, ImageLike, Dictionary, MapToType, FontWeight, FontStyle } from '../core/types';
2import TSpan from './TSpan';
3import ZRImage from './Image';
4import Rect from './shape/Rect';
5import BoundingRect from '../core/BoundingRect';
6import { MatrixArray } from '../core/matrix';
7import Displayable, { DisplayableStatePropNames, DisplayableProps } from './Displayable';
8import { ZRenderType } from '../zrender';
9import Animator from '../animation/Animator';
10import Transformable from '../core/Transformable';
11import { ElementCommonState } from '../Element';
12import { GroupLike } from './Group';
13export 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}
55export 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}
67export interface TextProps extends DisplayableProps {
68 style?: TextStyleProps;
69 zlevel?: number;
70 z?: number;
71 z2?: number;
72 culling?: boolean;
73 cursor?: string;
74}
75export declare type TextState = Pick<TextProps, DisplayableStatePropNames> & ElementCommonState;
76export declare type DefaultTextStyle = Pick<TextStyleProps, 'fill' | 'stroke' | 'align' | 'verticalAlign'> & {
77 autoStroke?: boolean;
78};
79export declare const DEFAULT_TEXT_ANIMATION_PROPS: MapToType<TextProps, boolean>;
80interface 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}
88declare class ZRText extends Displayable<TextProps> implements GroupLike {
89 type: string;
90 style: TextStyleProps;
91 overlap: 'hidden' | 'show' | 'blur';
92 innerTransformable: Transformable;
93 isTruncated: boolean;
94 private _children;
95 private _childCursor;
96 private _defaultStyle;
97 constructor(opts?: TextProps);
98 childrenRef(): (ZRImage | Rect | TSpan)[];
99 update(): void;
100 updateTransform(): void;
101 getLocalTransform(m?: MatrixArray): MatrixArray;
102 getComputedTransform(): MatrixArray;
103 private _updateSubTexts;
104 addSelfToZr(zr: ZRenderType): void;
105 removeSelfFromZr(zr: ZRenderType): void;
106 getBoundingRect(): BoundingRect;
107 setDefaultTextStyle(defaultTextStyle: DefaultTextStyle): void;
108 setTextContent(textContent: never): void;
109 protected _mergeStyle(targetStyle: TextStyleProps, sourceStyle: TextStyleProps): TextStyleProps;
110 private _mergeRich;
111 getAnimationStyleProps(): MapToType<TextProps, boolean>;
112 private _getOrCreateChild;
113 private _updatePlainTexts;
114 private _updateRichTexts;
115 private _placeToken;
116 private _renderBackground;
117 static makeFont(style: TextStylePropsPart): string;
118}
119export declare function parseFontSize(fontSize: number | string): string;
120export declare function hasSeparateFont(style: Pick<TextStylePropsPart, 'fontSize' | 'fontFamily' | 'fontWeight'>): string | number | true;
121export declare function normalizeTextStyle(style: TextStyleProps): TextStyleProps;
122export default ZRText;