Element.d.ts 8.7 KB

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