1 | import Transformable, { TransformProp } from './core/Transformable';
|
2 | import { AnimationEasing } from './animation/easing';
|
3 | import Animator from './animation/Animator';
|
4 | import { ZRenderType } from './zrender';
|
5 | import { Dictionary, ElementEventName, ZRRawEvent, BuiltinTextPosition, MapToType } from './core/types';
|
6 | import Path from './graphic/Path';
|
7 | import BoundingRect, { RectLike } from './core/BoundingRect';
|
8 | import Eventful from './core/Eventful';
|
9 | import ZRText from './graphic/Text';
|
10 | import { TextPositionCalculationResult } from './contain/text';
|
11 | import Polyline from './graphic/shape/Polyline';
|
12 | import Group from './graphic/Group';
|
13 | import Point from './core/Point';
|
14 | export interface ElementAnimateConfig {
|
15 | duration?: number;
|
16 | delay?: number;
|
17 | easing?: AnimationEasing;
|
18 | during?: (percent: number) => void;
|
19 | done?: Function;
|
20 | aborted?: Function;
|
21 | scope?: string;
|
22 | force?: boolean;
|
23 | additive?: boolean;
|
24 | setToFinal?: boolean;
|
25 | }
|
26 | export interface ElementTextConfig {
|
27 | position?: BuiltinTextPosition | (number | string)[];
|
28 | rotation?: number;
|
29 | layoutRect?: RectLike;
|
30 | offset?: number[];
|
31 | origin?: (number | string)[] | 'center';
|
32 | distance?: number;
|
33 | local?: boolean;
|
34 | insideFill?: string;
|
35 | insideStroke?: string;
|
36 | outsideFill?: string;
|
37 | outsideStroke?: string;
|
38 | inside?: boolean;
|
39 | }
|
40 | export interface ElementTextGuideLineConfig {
|
41 | anchor?: Point;
|
42 | showAbove?: boolean;
|
43 | candidates?: ('left' | 'top' | 'right' | 'bottom')[];
|
44 | }
|
45 | export interface ElementEvent {
|
46 | type: ElementEventName;
|
47 | event: ZRRawEvent;
|
48 | target: Element;
|
49 | topTarget: Element;
|
50 | cancelBubble: boolean;
|
51 | offsetX: number;
|
52 | offsetY: number;
|
53 | gestureEvent: string;
|
54 | pinchX: number;
|
55 | pinchY: number;
|
56 | pinchScale: number;
|
57 | wheelDelta: number;
|
58 | zrByTouch: boolean;
|
59 | which: number;
|
60 | stop: (this: ElementEvent) => void;
|
61 | }
|
62 | export declare type ElementEventCallback<Ctx, Impl> = (this: CbThis<Ctx, Impl>, e: ElementEvent) => boolean | void;
|
63 | declare type CbThis<Ctx, Impl> = unknown extends Ctx ? Impl : Ctx;
|
64 | interface ElementEventHandlerProps {
|
65 | onclick: ElementEventCallback<unknown, unknown>;
|
66 | ondblclick: ElementEventCallback<unknown, unknown>;
|
67 | onmouseover: ElementEventCallback<unknown, unknown>;
|
68 | onmouseout: ElementEventCallback<unknown, unknown>;
|
69 | onmousemove: ElementEventCallback<unknown, unknown>;
|
70 | onmousewheel: ElementEventCallback<unknown, unknown>;
|
71 | onmousedown: ElementEventCallback<unknown, unknown>;
|
72 | onmouseup: ElementEventCallback<unknown, unknown>;
|
73 | oncontextmenu: ElementEventCallback<unknown, unknown>;
|
74 | ondrag: ElementEventCallback<unknown, unknown>;
|
75 | ondragstart: ElementEventCallback<unknown, unknown>;
|
76 | ondragend: ElementEventCallback<unknown, unknown>;
|
77 | ondragenter: ElementEventCallback<unknown, unknown>;
|
78 | ondragleave: ElementEventCallback<unknown, unknown>;
|
79 | ondragover: ElementEventCallback<unknown, unknown>;
|
80 | ondrop: ElementEventCallback<unknown, unknown>;
|
81 | }
|
82 | export interface ElementProps extends Partial<ElementEventHandlerProps>, Partial<Pick<Transformable, TransformProp>> {
|
83 | name?: string;
|
84 | ignore?: boolean;
|
85 | isGroup?: boolean;
|
86 | draggable?: boolean | 'horizontal' | 'vertical';
|
87 | silent?: boolean;
|
88 | ignoreClip?: boolean;
|
89 | globalScaleRatio?: number;
|
90 | textConfig?: ElementTextConfig;
|
91 | textContent?: ZRText;
|
92 | clipPath?: Path;
|
93 | drift?: Element['drift'];
|
94 | extra?: Dictionary<unknown>;
|
95 | anid?: string;
|
96 | }
|
97 | export declare const PRESERVED_NORMAL_STATE = "__zr_normal__";
|
98 | declare const PRIMARY_STATES_KEYS: ["x" | "y" | "originX" | "originY" | "anchorX" | "anchorY" | "rotation" | "scaleX" | "scaleY" | "skewX" | "skewY", "ignore"];
|
99 | export declare type ElementStatePropNames = (typeof PRIMARY_STATES_KEYS)[number] | 'textConfig';
|
100 | export declare type ElementState = Pick<ElementProps, ElementStatePropNames> & ElementCommonState;
|
101 | export declare type ElementCommonState = {
|
102 | hoverLayer?: boolean;
|
103 | };
|
104 | export declare type ElementCalculateTextPosition = (out: TextPositionCalculationResult, style: ElementTextConfig, rect: RectLike) => TextPositionCalculationResult;
|
105 | interface Element<Props extends ElementProps = ElementProps> extends Transformable, Eventful<{
|
106 | [key in ElementEventName]: (e: ElementEvent) => void | boolean;
|
107 | } & {
|
108 | [key in string]: (...args: any) => void | boolean;
|
109 | }>, ElementEventHandlerProps {
|
110 | }
|
111 | declare class Element<Props extends ElementProps = ElementProps> {
|
112 | id: number;
|
113 | type: string;
|
114 | name: string;
|
115 | ignore: boolean;
|
116 | silent: boolean;
|
117 | isGroup: boolean;
|
118 | draggable: boolean | 'horizontal' | 'vertical';
|
119 | dragging: boolean;
|
120 | parent: Group;
|
121 | animators: Animator<any>[];
|
122 | ignoreClip: boolean;
|
123 | __hostTarget: Element;
|
124 | __zr: ZRenderType;
|
125 | __dirty: number;
|
126 | __isRendered: boolean;
|
127 | __inHover: boolean;
|
128 | private _clipPath?;
|
129 | private _textContent?;
|
130 | private _textGuide?;
|
131 | textConfig?: ElementTextConfig;
|
132 | textGuideLineConfig?: ElementTextGuideLineConfig;
|
133 | anid: string;
|
134 | extra: Dictionary<unknown>;
|
135 | currentStates?: string[];
|
136 | prevStates?: string[];
|
137 | states: Dictionary<ElementState>;
|
138 | stateTransition: ElementAnimateConfig;
|
139 | stateProxy?: (stateName: string, targetStates?: string[]) => ElementState;
|
140 | protected _normalState: ElementState;
|
141 | private _innerTextDefaultStyle;
|
142 | constructor(props?: Props);
|
143 | protected _init(props?: Props): void;
|
144 | drift(dx: number, dy: number, e?: ElementEvent): void;
|
145 | beforeUpdate(): void;
|
146 | afterUpdate(): void;
|
147 | update(): void;
|
148 | updateInnerText(forceUpdate?: boolean): void;
|
149 | protected canBeInsideText(): boolean;
|
150 | protected getInsideTextFill(): string | undefined;
|
151 | protected getInsideTextStroke(textFill: string): string | undefined;
|
152 | protected getOutsideFill(): string | undefined;
|
153 | protected getOutsideStroke(textFill: string): string;
|
154 | traverse<Context>(cb: (this: Context, el: Element<Props>) => void, context?: Context): void;
|
155 | protected attrKV(key: string, value: unknown): void;
|
156 | hide(): void;
|
157 | show(): void;
|
158 | attr(keyOrObj: Props): this;
|
159 | attr<T extends keyof Props>(keyOrObj: T, value: Props[T]): this;
|
160 | saveCurrentToNormalState(toState: ElementState): void;
|
161 | protected _innerSaveToNormal(toState: ElementState): void;
|
162 | protected _savePrimaryToNormal(toState: Dictionary<any>, normalState: Dictionary<any>, primaryKeys: readonly string[]): void;
|
163 | hasState(): boolean;
|
164 | getState(name: string): ElementState;
|
165 | ensureState(name: string): ElementState;
|
166 | clearStates(noAnimation?: boolean): void;
|
167 | useState(stateName: string, keepCurrentStates?: boolean, noAnimation?: boolean, forceUseHoverLayer?: boolean): ElementState;
|
168 | useStates(states: string[], noAnimation?: boolean, forceUseHoverLayer?: boolean): void;
|
169 | isSilent(): boolean;
|
170 | private _updateAnimationTargets;
|
171 | removeState(state: string): void;
|
172 | replaceState(oldState: string, newState: string, forceAdd: boolean): void;
|
173 | toggleState(state: string, enable: boolean): void;
|
174 | protected _mergeStates(states: ElementState[]): ElementState;
|
175 | protected _applyStateObj(stateName: string, state: ElementState, normalState: ElementState, keepCurrentStates: boolean, transition: boolean, animationCfg: ElementAnimateConfig): void;
|
176 | private _attachComponent;
|
177 | private _detachComponent;
|
178 | getClipPath(): Path<import("./graphic/Path").PathProps>;
|
179 | setClipPath(clipPath: Path): void;
|
180 | removeClipPath(): void;
|
181 | getTextContent(): ZRText;
|
182 | setTextContent(textEl: ZRText): void;
|
183 | setTextConfig(cfg: ElementTextConfig): void;
|
184 | removeTextConfig(): void;
|
185 | removeTextContent(): void;
|
186 | getTextGuideLine(): Polyline;
|
187 | setTextGuideLine(guideLine: Polyline): void;
|
188 | removeTextGuideLine(): void;
|
189 | markRedraw(): void;
|
190 | dirty(): void;
|
191 | private _toggleHoverLayerFlag;
|
192 | addSelfToZr(zr: ZRenderType): void;
|
193 | removeSelfFromZr(zr: ZRenderType): void;
|
194 | animate(key?: string, loop?: boolean, allowDiscreteAnimation?: boolean): Animator<any>;
|
195 | addAnimator(animator: Animator<any>, key: string): void;
|
196 | updateDuringAnimation(key: string): void;
|
197 | stopAnimation(scope?: string, forwardToLast?: boolean): this;
|
198 | animateTo(target: Props, cfg?: ElementAnimateConfig, animationProps?: MapToType<Props, boolean>): void;
|
199 | animateFrom(target: Props, cfg: ElementAnimateConfig, animationProps?: MapToType<Props, boolean>): void;
|
200 | protected _transitionState(stateName: string, target: Props, cfg?: ElementAnimateConfig, animationProps?: MapToType<Props, boolean>): void;
|
201 | getBoundingRect(): BoundingRect;
|
202 | getPaintRect(): BoundingRect;
|
203 | calculateTextPosition: ElementCalculateTextPosition;
|
204 | protected static initDefaultProps: void;
|
205 | }
|
206 | export default Element;
|