Displayable.d.ts 4.2 KB

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