Displayable.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Element, { ElementProps, ElementStatePropNames, ElementAnimateConfig, ElementCommonState } from '../Element';
  2. import BoundingRect from '../core/BoundingRect';
  3. import { PropType, Dictionary, MapToType, IncrementalIdCompat } from '../core/types';
  4. import Path from './Path';
  5. import Animator from '../animation/Animator';
  6. export interface CommonStyleProps {
  7. shadowBlur?: number;
  8. shadowOffsetX?: number;
  9. shadowOffsetY?: number;
  10. shadowColor?: string;
  11. opacity?: number;
  12. blend?: string;
  13. }
  14. export declare const DEFAULT_COMMON_STYLE: CommonStyleProps;
  15. export declare const DEFAULT_COMMON_ANIMATION_PROPS: MapToType<DisplayableProps, boolean>;
  16. export interface DisplayableProps extends ElementProps {
  17. style?: Dictionary<any>;
  18. zlevel?: number;
  19. z?: number;
  20. z2?: number;
  21. culling?: boolean;
  22. cursor?: string;
  23. rectHover?: boolean;
  24. progressive?: boolean;
  25. incremental?: Displayable['incremental'];
  26. ignoreCoarsePointer?: boolean;
  27. batch?: boolean;
  28. invisible?: boolean;
  29. }
  30. declare type DisplayableKey = keyof DisplayableProps;
  31. declare type DisplayablePropertyType = PropType<DisplayableProps, DisplayableKey>;
  32. export declare type DisplayableStatePropNames = ElementStatePropNames | 'style' | 'z' | 'z2' | 'invisible';
  33. export declare type DisplayableState = Pick<DisplayableProps, DisplayableStatePropNames> & ElementCommonState;
  34. export interface BeforeBrushParam {
  35. contentRetained?: boolean;
  36. }
  37. interface Displayable<Props extends DisplayableProps = DisplayableProps> {
  38. animate(key?: '', loop?: boolean): Animator<this>;
  39. animate(key: 'style', loop?: boolean): Animator<this['style']>;
  40. getState(stateName: string): DisplayableState;
  41. ensureState(stateName: string): DisplayableState;
  42. states: Dictionary<DisplayableState>;
  43. stateProxy: (stateName: string) => DisplayableState;
  44. }
  45. declare class Displayable<Props extends DisplayableProps = DisplayableProps> extends Element<Props> {
  46. invisible: boolean;
  47. z: number;
  48. z2: number;
  49. zlevel: number;
  50. culling: boolean;
  51. cursor: string;
  52. rectHover: boolean;
  53. incremental: IncrementalIdCompat;
  54. notClear?: boolean;
  55. __layerCleared?: boolean;
  56. ignoreCoarsePointer?: boolean;
  57. style: Dictionary<any>;
  58. protected _normalState: DisplayableState;
  59. protected _rect: BoundingRect;
  60. protected _paintRect: BoundingRect;
  61. protected _prevPaintRect: BoundingRect;
  62. dirtyRectTolerance: number;
  63. useHoverLayer?: boolean;
  64. __hoverStyle?: CommonStyleProps;
  65. __clipPaths?: Path[];
  66. __canvasFillGradient: CanvasGradient;
  67. __canvasStrokeGradient: CanvasGradient;
  68. __canvasFillPattern: CanvasPattern;
  69. __canvasStrokePattern: CanvasPattern;
  70. __svgEl: SVGElement;
  71. constructor(props?: Props);
  72. protected _init(props?: Props): void;
  73. beforeBrush(param: BeforeBrushParam): void;
  74. afterBrush(): void;
  75. innerBeforeBrush(): void;
  76. innerAfterBrush(): void;
  77. shouldBePainted(viewWidth: number, viewHeight: number, considerClipPath: boolean, considerAncestors: boolean): boolean;
  78. contain(x: number, y: number): boolean;
  79. traverse<Context>(cb: (this: Context, el: this) => void, context?: Context): void;
  80. rectContain(x: number, y: number): boolean;
  81. getPaintRect(): BoundingRect;
  82. setPrevPaintRect(paintRect: BoundingRect): void;
  83. getPrevPaintRect(): BoundingRect;
  84. animateStyle(loop: boolean): Animator<this["style"]>;
  85. updateDuringAnimation(targetKey: string): void;
  86. attrKV(key: DisplayableKey, value: DisplayablePropertyType): void;
  87. setStyle(obj: Props['style']): this;
  88. setStyle<T extends keyof Props['style']>(obj: T, value: Props['style'][T]): this;
  89. dirtyStyle(notRedraw?: boolean): void;
  90. dirty(): void;
  91. styleChanged(): boolean;
  92. styleUpdated(): void;
  93. createStyle(obj?: Props['style']): Props["style"];
  94. useStyle(obj: Props['style']): void;
  95. protected _useHoverStyle(obj: Props['style']): void;
  96. isStyleObject(obj: Props['style']): any;
  97. protected _innerSaveToNormal(toState: DisplayableState): void;
  98. protected _applyStateObj(stateName: string, state: DisplayableState, normalState: DisplayableState, keepCurrentStates: boolean, transition: boolean, animationCfg: ElementAnimateConfig): void;
  99. protected _mergeStates(states: DisplayableState[]): DisplayableState;
  100. protected _mergeStyle(targetStyle: CommonStyleProps, sourceStyle: CommonStyleProps): CommonStyleProps;
  101. getAnimationStyleProps(): MapToType<DisplayableProps, boolean>;
  102. protected static initDefaultProps: void;
  103. }
  104. export default Displayable;