Path.d.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import Displayable, { DisplayableProps, CommonStyleProps, DisplayableStatePropNames } from './Displayable';
  2. import Element, { ElementAnimateConfig } from '../Element';
  3. import PathProxy from '../core/PathProxy';
  4. import { PatternObject } from './Pattern';
  5. import { Dictionary, PropType, MapToType } from '../core/types';
  6. import BoundingRect from '../core/BoundingRect';
  7. import { LinearGradientObject } from './LinearGradient';
  8. import { RadialGradientObject } from './RadialGradient';
  9. import Animator from '../animation/Animator';
  10. export interface PathStyleProps extends CommonStyleProps {
  11. fill?: string | PatternObject | LinearGradientObject | RadialGradientObject;
  12. stroke?: string | PatternObject | LinearGradientObject | RadialGradientObject;
  13. decal?: PatternObject;
  14. strokePercent?: number;
  15. strokeNoScale?: boolean;
  16. fillOpacity?: number;
  17. strokeOpacity?: number;
  18. lineDash?: false | number[] | 'solid' | 'dashed' | 'dotted';
  19. lineDashOffset?: number;
  20. lineWidth?: number;
  21. lineCap?: CanvasLineCap;
  22. lineJoin?: CanvasLineJoin;
  23. miterLimit?: number;
  24. strokeFirst?: boolean;
  25. }
  26. export declare const DEFAULT_PATH_STYLE: PathStyleProps;
  27. export declare const DEFAULT_PATH_ANIMATION_PROPS: MapToType<PathProps, boolean>;
  28. export interface PathProps extends DisplayableProps {
  29. strokeContainThreshold?: number;
  30. segmentIgnoreThreshold?: number;
  31. subPixelOptimize?: boolean;
  32. style?: PathStyleProps;
  33. shape?: Dictionary<any>;
  34. autoBatch?: boolean;
  35. __value?: (string | number)[] | (string | number);
  36. buildPath?: (ctx: PathProxy | CanvasRenderingContext2D, shapeCfg: Dictionary<any>, inBatch?: boolean) => void;
  37. }
  38. declare type PathKey = keyof PathProps;
  39. declare type PathPropertyType = PropType<PathProps, PathKey>;
  40. interface Path<Props extends PathProps = PathProps> {
  41. animate(key?: '', loop?: boolean): Animator<this>;
  42. animate(key: 'style', loop?: boolean): Animator<this['style']>;
  43. animate(key: 'shape', loop?: boolean): Animator<this['shape']>;
  44. getState(stateName: string): PathState;
  45. ensureState(stateName: string): PathState;
  46. states: Dictionary<PathState>;
  47. stateProxy: (stateName: string) => PathState;
  48. }
  49. export declare type PathStatePropNames = DisplayableStatePropNames | 'shape';
  50. export declare type PathState = Pick<PathProps, PathStatePropNames> & {
  51. hoverLayer?: boolean;
  52. };
  53. declare class Path<Props extends PathProps = PathProps> extends Displayable<Props> {
  54. path: PathProxy;
  55. strokeContainThreshold: number;
  56. segmentIgnoreThreshold: number;
  57. subPixelOptimize: boolean;
  58. style: PathStyleProps;
  59. autoBatch: boolean;
  60. private _rectStroke;
  61. protected _normalState: PathState;
  62. protected _decalEl: Path;
  63. shape: Dictionary<any>;
  64. constructor(opts?: Props);
  65. update(): void;
  66. getDecalElement(): Path<PathProps>;
  67. protected _init(props?: Props): void;
  68. protected getDefaultStyle(): Props['style'];
  69. protected getDefaultShape(): {};
  70. protected canBeInsideText(): boolean;
  71. protected getInsideTextFill(): "#333" | "#ccc" | "#eee";
  72. protected getInsideTextStroke(textFill?: string): string;
  73. buildPath(ctx: PathProxy | CanvasRenderingContext2D, shapeCfg: Dictionary<any>, inBatch?: boolean): void;
  74. pathUpdated(): void;
  75. getUpdatedPathProxy(inBatch?: boolean): PathProxy;
  76. createPathProxy(): void;
  77. hasStroke(): boolean;
  78. hasFill(): boolean;
  79. getBoundingRect(): BoundingRect;
  80. contain(x: number, y: number): boolean;
  81. dirtyShape(): void;
  82. dirty(): void;
  83. animateShape(loop: boolean): Animator<this["shape"]>;
  84. updateDuringAnimation(targetKey: string): void;
  85. attrKV(key: PathKey, value: PathPropertyType): void;
  86. setShape(obj: Props['shape']): this;
  87. setShape<T extends keyof Props['shape']>(obj: T, value: Props['shape'][T]): this;
  88. shapeChanged(): boolean;
  89. createStyle(obj?: Props['style']): Props["style"];
  90. protected _innerSaveToNormal(toState: PathState): void;
  91. protected _applyStateObj(stateName: string, state: PathState, normalState: PathState, keepCurrentStates: boolean, transition: boolean, animationCfg: ElementAnimateConfig): void;
  92. protected _mergeStates(states: PathState[]): PathState;
  93. getAnimationStyleProps(): MapToType<PathProps, boolean>;
  94. isZeroArea(): boolean;
  95. static extend<Shape extends Dictionary<any>>(defaultProps: {
  96. type?: string;
  97. shape?: Shape;
  98. style?: PathStyleProps;
  99. beforeBrush?: Displayable['beforeBrush'];
  100. afterBrush?: Displayable['afterBrush'];
  101. getBoundingRect?: Displayable['getBoundingRect'];
  102. calculateTextPosition?: Element['calculateTextPosition'];
  103. buildPath(this: Path, ctx: CanvasRenderingContext2D | PathProxy, shape: Shape, inBatch?: boolean): void;
  104. init?(this: Path, opts: PathProps): void;
  105. }): {
  106. new (opts?: PathProps & {
  107. shape: Shape;
  108. }): Path;
  109. };
  110. protected static initDefaultProps: void;
  111. }
  112. export default Path;