UNPKG

4.38 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 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}
118export declare function parseFontSize(fontSize: number | string): string;
119export declare function hasSeparateFont(style: Pick<TextStylePropsPart, 'fontSize' | 'fontFamily' | 'fontWeight'>): string | number | true;
120export declare function normalizeTextStyle(style: TextStyleProps): TextStyleProps;
121export default ZRText;