little optimize

This commit is contained in:
Anton Lavrenov 2023-06-05 10:25:36 -05:00
parent d410ceee24
commit 72cbc8d289
3 changed files with 13 additions and 8 deletions

View File

@ -362,8 +362,8 @@ export class Context {
* @method * @method
* @name Konva.Context#clip * @name Konva.Context#clip
*/ */
clip(fillRule?: CanvasFillRule): void clip(fillRule?: CanvasFillRule): void;
clip(path: Path2D, fillRule?: CanvasFillRule): void clip(path: Path2D, fillRule?: CanvasFillRule): void;
clip(...args: any[]) { clip(...args: any[]) {
this._context.clip.apply(this._context, args); this._context.clip.apply(this._context, args);
} }
@ -484,9 +484,10 @@ export class Context {
* @method * @method
* @name Konva.Context#fill * @name Konva.Context#fill
*/ */
fill(fillRule?: CanvasFillRule): void fill(fillRule?: CanvasFillRule): void;
fill(path: Path2D, fillRule?: CanvasFillRule): void fill(path: Path2D, fillRule?: CanvasFillRule): void;
fill(...args: any[]) { fill(...args: any[]) {
// this._context.fill();
this._context.fill.apply(this._context, args); this._context.fill.apply(this._context, args);
} }
/** /**
@ -749,7 +750,7 @@ export class Context {
// supported context properties // supported context properties
type CanvasContextProps = Pick< type CanvasContextProps = Pick<
CanvasRenderingContext2D, CanvasRenderingContext2D,
typeof CONTEXT_PROPERTIES[number] (typeof CONTEXT_PROPERTIES)[number]
>; >;
export interface Context extends CanvasContextProps {} export interface Context extends CanvasContextProps {}

View File

@ -56,7 +56,7 @@ export interface ShapeConfig extends NodeConfig {
fillRadialGradientColorStops?: Array<number | string>; fillRadialGradientColorStops?: Array<number | string>;
fillEnabled?: boolean; fillEnabled?: boolean;
fillPriority?: string; fillPriority?: string;
fillRule?: CanvasFillRule fillRule?: CanvasFillRule;
stroke?: string | CanvasGradient; stroke?: string | CanvasGradient;
strokeWidth?: number; strokeWidth?: number;
fillAfterStrokeEnabled?: boolean; fillAfterStrokeEnabled?: boolean;
@ -89,7 +89,10 @@ export interface ShapeGetClientRectConfig {
relativeTo?: Node; relativeTo?: Node;
} }
export type FillFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule] export type FillFuncOutput =
| void
| [Path2D | CanvasFillRule]
| [Path2D, CanvasFillRule];
var HAS_SHADOW = 'hasShadow'; var HAS_SHADOW = 'hasShadow';
var SHADOW_RGBA = 'shadowRGBA'; var SHADOW_RGBA = 'shadowRGBA';
@ -115,7 +118,7 @@ export const shapes: { [key: string]: Shape } = {};
// what color to use for hit test? // what color to use for hit test?
function _fillFunc(context) { function _fillFunc(context) {
const fillRule = this.fillRule() const fillRule = this.attrs.fillRule;
if (fillRule) { if (fillRule) {
context.fill(fillRule); context.fill(fillRule);
} else { } else {

View File

@ -96,6 +96,7 @@
perfectDrawEnabled: false, perfectDrawEnabled: false,
width: wabbitTexture.width, width: wabbitTexture.width,
height: wabbitTexture.height, height: wabbitTexture.height,
fill: 'yellow',
}); });
bunny.speedX = Math.random() * 10; bunny.speedX = Math.random() * 10;