konva 8.3.14 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmj/Context.d.ts +29 -28
- package/cmj/Context.js +5 -2
- package/cmj/Global.js +1 -1
- package/cmj/Node.d.ts +5 -5
- package/cmj/PointerEvents.d.ts +1 -1
- package/cmj/Shape.d.ts +3 -3
- package/cmj/Util.d.ts +4 -0
- package/cmj/Util.js +46 -0
- package/cmj/_CoreInternals.d.ts +3 -0
- package/cmj/_FullInternals.d.ts +3 -0
- package/cmj/shapes/Image.d.ts +2 -0
- package/cmj/shapes/Image.js +17 -5
- package/cmj/shapes/Rect.d.ts +2 -1
- package/cmj/shapes/Rect.js +2 -22
- package/cmj/shapes/Transformer.d.ts +1 -0
- package/cmj/shapes/Transformer.js +4 -0
- package/cmj/types.d.ts +1 -1
- package/konva.js +111 -46
- package/konva.min.js +3 -3
- package/lib/Context.d.ts +29 -28
- package/lib/Context.js +5 -2
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +5 -5
- package/lib/PointerEvents.d.ts +1 -1
- package/lib/Shape.d.ts +3 -3
- package/lib/Util.d.ts +4 -0
- package/lib/Util.js +46 -0
- package/lib/_CoreInternals.d.ts +3 -0
- package/lib/_FullInternals.d.ts +3 -0
- package/lib/shapes/Image.d.ts +2 -0
- package/lib/shapes/Image.js +17 -5
- package/lib/shapes/Rect.d.ts +2 -1
- package/lib/shapes/Rect.js +2 -22
- package/lib/shapes/Transformer.d.ts +1 -0
- package/lib/shapes/Transformer.js +4 -0
- package/lib/types.d.ts +1 -1
- package/package.json +13 -13
package/cmj/Context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Canvas } from './Canvas';
|
|
2
2
|
import { Shape } from './Shape';
|
|
3
|
+
import { IRect } from './types';
|
|
3
4
|
declare var CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
|
|
4
5
|
export declare class Context {
|
|
5
6
|
canvas: Canvas;
|
|
@@ -7,7 +8,7 @@ export declare class Context {
|
|
|
7
8
|
traceArr: Array<String>;
|
|
8
9
|
constructor(canvas: Canvas);
|
|
9
10
|
fillShape(shape: Shape): void;
|
|
10
|
-
_fill(shape:
|
|
11
|
+
_fill(shape: Shape): void;
|
|
11
12
|
strokeShape(shape: Shape): void;
|
|
12
13
|
_stroke(shape: any): void;
|
|
13
14
|
fillStrokeShape(shape: Shape): void;
|
|
@@ -16,51 +17,51 @@ export declare class Context {
|
|
|
16
17
|
_trace(str: any): void;
|
|
17
18
|
reset(): void;
|
|
18
19
|
getCanvas(): Canvas;
|
|
19
|
-
clear(bounds?:
|
|
20
|
+
clear(bounds?: IRect): void;
|
|
20
21
|
_applyLineCap(shape: any): void;
|
|
21
22
|
_applyOpacity(shape: any): void;
|
|
22
23
|
_applyLineJoin(shape: Shape): void;
|
|
23
|
-
setAttr(attr:
|
|
24
|
-
arc(a0:
|
|
25
|
-
arcTo(a0:
|
|
24
|
+
setAttr(attr: string, val: any): void;
|
|
25
|
+
arc(a0: number, a1: number, a2: number, a3: number, a4: number, a5?: boolean): void;
|
|
26
|
+
arcTo(a0: number, a1: number, a2: number, a3: number, a4: number): void;
|
|
26
27
|
beginPath(): void;
|
|
27
|
-
bezierCurveTo(a0:
|
|
28
|
-
clearRect(a0:
|
|
28
|
+
bezierCurveTo(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
|
|
29
|
+
clearRect(a0: number, a1: number, a2: number, a3: number): void;
|
|
29
30
|
clip(): void;
|
|
30
31
|
closePath(): void;
|
|
31
32
|
createImageData(a0: any, a1: any): ImageData;
|
|
32
|
-
createLinearGradient(a0:
|
|
33
|
-
createPattern(a0:
|
|
34
|
-
createRadialGradient(a0:
|
|
33
|
+
createLinearGradient(a0: number, a1: number, a2: number, a3: number): CanvasGradient;
|
|
34
|
+
createPattern(a0: CanvasImageSource, a1: string | null): CanvasPattern;
|
|
35
|
+
createRadialGradient(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): CanvasGradient;
|
|
35
36
|
drawImage(a0: CanvasImageSource, a1: number, a2: number, a3?: number, a4?: number, a5?: number, a6?: number, a7?: number, a8?: number): void;
|
|
36
37
|
ellipse(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7?: boolean): void;
|
|
37
|
-
isPointInPath(x:
|
|
38
|
+
isPointInPath(x: number, y: number, path?: Path2D, fillRule?: CanvasFillRule): boolean;
|
|
38
39
|
fill(path2d?: Path2D): void;
|
|
39
|
-
fillRect(x:
|
|
40
|
-
strokeRect(x:
|
|
40
|
+
fillRect(x: number, y: number, width: number, height: number): void;
|
|
41
|
+
strokeRect(x: number, y: number, width: number, height: number): void;
|
|
41
42
|
fillText(text: string, x: number, y: number, maxWidth?: number): void;
|
|
42
|
-
measureText(text:
|
|
43
|
-
getImageData(a0:
|
|
44
|
-
lineTo(a0:
|
|
45
|
-
moveTo(a0:
|
|
46
|
-
rect(a0:
|
|
47
|
-
putImageData(a0:
|
|
48
|
-
quadraticCurveTo(a0:
|
|
43
|
+
measureText(text: string): TextMetrics;
|
|
44
|
+
getImageData(a0: number, a1: number, a2: number, a3: number): ImageData;
|
|
45
|
+
lineTo(a0: number, a1: number): void;
|
|
46
|
+
moveTo(a0: number, a1: number): void;
|
|
47
|
+
rect(a0: number, a1: number, a2: number, a3: number): void;
|
|
48
|
+
putImageData(a0: ImageData, a1: number, a2: number): void;
|
|
49
|
+
quadraticCurveTo(a0: number, a1: number, a2: number, a3: number): void;
|
|
49
50
|
restore(): void;
|
|
50
|
-
rotate(a0:
|
|
51
|
+
rotate(a0: number): void;
|
|
51
52
|
save(): void;
|
|
52
|
-
scale(a0:
|
|
53
|
-
setLineDash(a0:
|
|
53
|
+
scale(a0: number, a1: number): void;
|
|
54
|
+
setLineDash(a0: number[]): void;
|
|
54
55
|
getLineDash(): number[];
|
|
55
|
-
setTransform(a0:
|
|
56
|
+
setTransform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
|
|
56
57
|
stroke(path2d?: Path2D): void;
|
|
57
|
-
strokeText(a0:
|
|
58
|
-
transform(a0:
|
|
59
|
-
translate(a0:
|
|
58
|
+
strokeText(a0: string, a1: number, a2: number, a3: number): void;
|
|
59
|
+
transform(a0: number, a1: number, a2: number, a3: number, a4: number, a5: number): void;
|
|
60
|
+
translate(a0: number, a1: number): void;
|
|
60
61
|
_enableTrace(): void;
|
|
61
62
|
_applyGlobalCompositeOperation(node: any): void;
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
type CanvasContextProps = Pick<CanvasRenderingContext2D, typeof CONTEXT_PROPERTIES[number]>;
|
|
64
65
|
export interface Context extends CanvasContextProps {
|
|
65
66
|
}
|
|
66
67
|
export declare class SceneContext extends Context {
|
package/cmj/Context.js
CHANGED
|
@@ -237,8 +237,11 @@ class Context {
|
|
|
237
237
|
ellipse(a0, a1, a2, a3, a4, a5, a6, a7) {
|
|
238
238
|
this._context.ellipse(a0, a1, a2, a3, a4, a5, a6, a7);
|
|
239
239
|
}
|
|
240
|
-
isPointInPath(x, y) {
|
|
241
|
-
|
|
240
|
+
isPointInPath(x, y, path, fillRule) {
|
|
241
|
+
if (path) {
|
|
242
|
+
return this._context.isPointInPath(path, x, y, fillRule);
|
|
243
|
+
}
|
|
244
|
+
return this._context.isPointInPath(x, y, fillRule);
|
|
242
245
|
}
|
|
243
246
|
fill(path2d) {
|
|
244
247
|
if (path2d) {
|
package/cmj/Global.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
|
|
|
16
16
|
: {};
|
|
17
17
|
exports.Konva = {
|
|
18
18
|
_global: exports.glob,
|
|
19
|
-
version: '8.
|
|
19
|
+
version: '8.4.0',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/cmj/Node.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { Stage } from './Stage';
|
|
|
6
6
|
import { Context } from './Context';
|
|
7
7
|
import { Shape } from './Shape';
|
|
8
8
|
import { Layer } from './Layer';
|
|
9
|
-
export
|
|
10
|
-
|
|
9
|
+
export type Filter = (this: Node, imageData: ImageData) => void;
|
|
10
|
+
type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
|
11
11
|
export interface NodeConfig {
|
|
12
12
|
[index: string]: any;
|
|
13
13
|
x?: number;
|
|
@@ -34,7 +34,7 @@ export interface NodeConfig {
|
|
|
34
34
|
globalCompositeOperation?: globalCompositeOperationType;
|
|
35
35
|
filters?: Array<Filter>;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
type NodeEventMap = GlobalEventHandlersEventMap & {
|
|
38
38
|
[index: string]: any;
|
|
39
39
|
};
|
|
40
40
|
export interface KonvaEventObject<EventType> {
|
|
@@ -45,7 +45,7 @@ export interface KonvaEventObject<EventType> {
|
|
|
45
45
|
cancelBubble: boolean;
|
|
46
46
|
child?: Node;
|
|
47
47
|
}
|
|
48
|
-
export
|
|
48
|
+
export type KonvaEventListener<This, EventType> = (this: This, ev: KonvaEventObject<EventType>) => void;
|
|
49
49
|
export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
50
50
|
_id: number;
|
|
51
51
|
eventListeners: {
|
|
@@ -179,7 +179,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
179
179
|
getParent(): Container<Node<NodeConfig>>;
|
|
180
180
|
findAncestors(selector: string, includeSelf?: boolean, stopNode?: Node): Node<NodeConfig>[];
|
|
181
181
|
isAncestorOf(node: Node): boolean;
|
|
182
|
-
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container):
|
|
182
|
+
findAncestor(selector?: string, includeSelf?: boolean, stopNode?: Container): any;
|
|
183
183
|
_isMatch(selector: string | Function): any;
|
|
184
184
|
getLayer(): Layer | null;
|
|
185
185
|
getStage(): Stage | null;
|
package/cmj/PointerEvents.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Stage } from './Stage';
|
|
|
4
4
|
export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
|
|
5
5
|
pointerId: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function getCapturedShape(pointerId: number):
|
|
7
|
+
export declare function getCapturedShape(pointerId: number): Shape<import("./Shape").ShapeConfig> | Stage;
|
|
8
8
|
export declare function createEvent(evt: PointerEvent): KonvaPointerEvent;
|
|
9
9
|
export declare function hasPointerCapture(pointerId: number, shape: Shape | Stage): boolean;
|
|
10
10
|
export declare function setPointerCapture(pointerId: number, shape: Shape | Stage): void;
|
package/cmj/Shape.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Node, NodeConfig } from './Node';
|
|
|
2
2
|
import { Context } from './Context';
|
|
3
3
|
import { GetSet, Vector2d } from './types';
|
|
4
4
|
import { HitCanvas, SceneCanvas } from './Canvas';
|
|
5
|
-
export
|
|
5
|
+
export type ShapeConfigHandler<TTarget> = {
|
|
6
6
|
bivarianceHack(ctx: Context, shape: TTarget): void;
|
|
7
7
|
}['bivarianceHack'];
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type LineJoin = 'round' | 'bevel' | 'miter';
|
|
9
|
+
export type LineCap = 'butt' | 'round' | 'square';
|
|
10
10
|
export interface ShapeConfig extends NodeConfig {
|
|
11
11
|
fill?: string;
|
|
12
12
|
fillPatternImage?: HTMLImageElement;
|
package/cmj/Util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Context } from './Context';
|
|
1
2
|
import { IRect, RGB, RGBA, Vector2d } from './types';
|
|
2
3
|
export declare class Transform {
|
|
3
4
|
m: Array<number>;
|
|
@@ -60,7 +61,9 @@ export declare const Util: {
|
|
|
60
61
|
};
|
|
61
62
|
_rgbColorToRGBA(str: string): RGBA;
|
|
62
63
|
_rgbaColorToRGBA(str: string): RGBA;
|
|
64
|
+
_hex8ColorToRGBA(str: string): RGBA;
|
|
63
65
|
_hex6ColorToRGBA(str: string): RGBA;
|
|
66
|
+
_hex4ColorToRGBA(str: string): RGBA;
|
|
64
67
|
_hex3ColorToRGBA(str: string): RGBA;
|
|
65
68
|
_hslColorToRGBA(str: string): RGBA;
|
|
66
69
|
haveIntersection(r1: IRect, r2: IRect): boolean;
|
|
@@ -84,4 +87,5 @@ export declare const Util: {
|
|
|
84
87
|
_assign<T, U>(target: T, source: U): T & U;
|
|
85
88
|
_getFirstPointerId(evt: any): any;
|
|
86
89
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
90
|
+
drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
87
91
|
};
|
package/cmj/Util.js
CHANGED
|
@@ -442,7 +442,9 @@ exports.Util = {
|
|
|
442
442
|
str = str || 'black';
|
|
443
443
|
return (exports.Util._namedColorToRBA(str) ||
|
|
444
444
|
exports.Util._hex3ColorToRGBA(str) ||
|
|
445
|
+
exports.Util._hex4ColorToRGBA(str) ||
|
|
445
446
|
exports.Util._hex6ColorToRGBA(str) ||
|
|
447
|
+
exports.Util._hex8ColorToRGBA(str) ||
|
|
446
448
|
exports.Util._rgbColorToRGBA(str) ||
|
|
447
449
|
exports.Util._rgbaColorToRGBA(str) ||
|
|
448
450
|
exports.Util._hslColorToRGBA(str));
|
|
@@ -488,6 +490,16 @@ exports.Util = {
|
|
|
488
490
|
};
|
|
489
491
|
}
|
|
490
492
|
},
|
|
493
|
+
_hex8ColorToRGBA(str) {
|
|
494
|
+
if (str[0] === '#' && str.length === 9) {
|
|
495
|
+
return {
|
|
496
|
+
r: parseInt(str.slice(1, 3), 16),
|
|
497
|
+
g: parseInt(str.slice(3, 5), 16),
|
|
498
|
+
b: parseInt(str.slice(5, 7), 16),
|
|
499
|
+
a: parseInt(str.slice(7, 9), 16) / 0xff,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
},
|
|
491
503
|
_hex6ColorToRGBA(str) {
|
|
492
504
|
if (str[0] === '#' && str.length === 7) {
|
|
493
505
|
return {
|
|
@@ -498,6 +510,16 @@ exports.Util = {
|
|
|
498
510
|
};
|
|
499
511
|
}
|
|
500
512
|
},
|
|
513
|
+
_hex4ColorToRGBA(str) {
|
|
514
|
+
if (str[0] === '#' && str.length === 5) {
|
|
515
|
+
return {
|
|
516
|
+
r: parseInt(str[1] + str[1], 16),
|
|
517
|
+
g: parseInt(str[2] + str[2], 16),
|
|
518
|
+
b: parseInt(str[3] + str[3], 16),
|
|
519
|
+
a: parseInt(str[4] + str[4], 16) / 0xff,
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
},
|
|
501
523
|
_hex3ColorToRGBA(str) {
|
|
502
524
|
if (str[0] === '#' && str.length === 4) {
|
|
503
525
|
return {
|
|
@@ -751,5 +773,29 @@ exports.Util = {
|
|
|
751
773
|
c.width = 0;
|
|
752
774
|
c.height = 0;
|
|
753
775
|
});
|
|
776
|
+
},
|
|
777
|
+
drawRoundedRectPath(context, width, height, cornerRadius) {
|
|
778
|
+
let topLeft = 0;
|
|
779
|
+
let topRight = 0;
|
|
780
|
+
let bottomLeft = 0;
|
|
781
|
+
let bottomRight = 0;
|
|
782
|
+
if (typeof cornerRadius === 'number') {
|
|
783
|
+
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
787
|
+
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
788
|
+
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
789
|
+
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
790
|
+
}
|
|
791
|
+
context.moveTo(topLeft, 0);
|
|
792
|
+
context.lineTo(width - topRight, 0);
|
|
793
|
+
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
794
|
+
context.lineTo(width, height - bottomRight);
|
|
795
|
+
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
796
|
+
context.lineTo(bottomLeft, height);
|
|
797
|
+
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
798
|
+
context.lineTo(0, topLeft);
|
|
799
|
+
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
754
800
|
}
|
|
755
801
|
};
|
package/cmj/_CoreInternals.d.ts
CHANGED
|
@@ -71,7 +71,9 @@ export declare const Konva: {
|
|
|
71
71
|
};
|
|
72
72
|
_rgbColorToRGBA(str: string): import("./types").RGBA;
|
|
73
73
|
_rgbaColorToRGBA(str: string): import("./types").RGBA;
|
|
74
|
+
_hex8ColorToRGBA(str: string): import("./types").RGBA;
|
|
74
75
|
_hex6ColorToRGBA(str: string): import("./types").RGBA;
|
|
76
|
+
_hex4ColorToRGBA(str: string): import("./types").RGBA;
|
|
75
77
|
_hex3ColorToRGBA(str: string): import("./types").RGBA;
|
|
76
78
|
_hslColorToRGBA(str: string): import("./types").RGBA;
|
|
77
79
|
haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
|
|
@@ -95,6 +97,7 @@ export declare const Konva: {
|
|
|
95
97
|
_assign<T, U>(target: T, source: U): T & U;
|
|
96
98
|
_getFirstPointerId(evt: any): any;
|
|
97
99
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
100
|
+
drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
98
101
|
};
|
|
99
102
|
Transform: typeof Transform;
|
|
100
103
|
Node: typeof Node;
|
package/cmj/_FullInternals.d.ts
CHANGED
|
@@ -76,7 +76,9 @@ export declare const Konva: {
|
|
|
76
76
|
};
|
|
77
77
|
_rgbColorToRGBA(str: string): import("./types").RGBA;
|
|
78
78
|
_rgbaColorToRGBA(str: string): import("./types").RGBA;
|
|
79
|
+
_hex8ColorToRGBA(str: string): import("./types").RGBA;
|
|
79
80
|
_hex6ColorToRGBA(str: string): import("./types").RGBA;
|
|
81
|
+
_hex4ColorToRGBA(str: string): import("./types").RGBA;
|
|
80
82
|
_hex3ColorToRGBA(str: string): import("./types").RGBA;
|
|
81
83
|
_hslColorToRGBA(str: string): import("./types").RGBA;
|
|
82
84
|
haveIntersection(r1: import("./types").IRect, r2: import("./types").IRect): boolean;
|
|
@@ -100,6 +102,7 @@ export declare const Konva: {
|
|
|
100
102
|
_assign<T, U>(target: T, source: U): T & U;
|
|
101
103
|
_getFirstPointerId(evt: any): any;
|
|
102
104
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
105
|
+
drawRoundedRectPath(context: import("./Context").Context, width: number, height: number, cornerRadius: number | number[]): void;
|
|
103
106
|
};
|
|
104
107
|
Transform: typeof import("./Util").Transform;
|
|
105
108
|
Node: typeof import("./Node").Node;
|
package/cmj/shapes/Image.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Context } from '../Context';
|
|
|
4
4
|
export interface ImageConfig extends ShapeConfig {
|
|
5
5
|
image: CanvasImageSource | undefined;
|
|
6
6
|
crop?: IRect;
|
|
7
|
+
cornerRadius?: number | number[];
|
|
7
8
|
}
|
|
8
9
|
export declare class Image extends Shape<ImageConfig> {
|
|
9
10
|
constructor(attrs: ImageConfig);
|
|
@@ -20,4 +21,5 @@ export declare class Image extends Shape<ImageConfig> {
|
|
|
20
21
|
cropY: GetSet<number, this>;
|
|
21
22
|
cropWidth: GetSet<number, this>;
|
|
22
23
|
cropHeight: GetSet<number, this>;
|
|
24
|
+
cornerRadius: GetSet<number | number[], this>;
|
|
23
25
|
}
|
package/cmj/shapes/Image.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.Image = void 0;
|
|
|
4
4
|
const Util_1 = require("../Util");
|
|
5
5
|
const Factory_1 = require("../Factory");
|
|
6
6
|
const Shape_1 = require("../Shape");
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
8
7
|
const Global_1 = require("../Global");
|
|
8
|
+
const Validators_1 = require("../Validators");
|
|
9
9
|
class Image extends Shape_1.Shape {
|
|
10
10
|
constructor(attrs) {
|
|
11
11
|
super(attrs);
|
|
@@ -34,6 +34,7 @@ class Image extends Shape_1.Shape {
|
|
|
34
34
|
_sceneFunc(context) {
|
|
35
35
|
const width = this.getWidth();
|
|
36
36
|
const height = this.getHeight();
|
|
37
|
+
const cornerRadius = this.cornerRadius();
|
|
37
38
|
const image = this.attrs.image;
|
|
38
39
|
let params;
|
|
39
40
|
if (image) {
|
|
@@ -56,20 +57,30 @@ class Image extends Shape_1.Shape {
|
|
|
56
57
|
params = [image, 0, 0, width, height];
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
if (this.hasFill() || this.hasStroke()) {
|
|
60
|
+
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
60
61
|
context.beginPath();
|
|
61
|
-
|
|
62
|
+
cornerRadius
|
|
63
|
+
? Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
64
|
+
: context.rect(0, 0, width, height);
|
|
62
65
|
context.closePath();
|
|
63
66
|
context.fillStrokeShape(this);
|
|
64
67
|
}
|
|
65
68
|
if (image) {
|
|
69
|
+
if (cornerRadius) {
|
|
70
|
+
context.clip();
|
|
71
|
+
}
|
|
66
72
|
context.drawImage.apply(context, params);
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
_hitFunc(context) {
|
|
70
|
-
var width = this.width(), height = this.height();
|
|
76
|
+
var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
71
77
|
context.beginPath();
|
|
72
|
-
|
|
78
|
+
if (!cornerRadius) {
|
|
79
|
+
context.rect(0, 0, width, height);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
83
|
+
}
|
|
73
84
|
context.closePath();
|
|
74
85
|
context.fillStrokeShape(this);
|
|
75
86
|
}
|
|
@@ -97,6 +108,7 @@ class Image extends Shape_1.Shape {
|
|
|
97
108
|
exports.Image = Image;
|
|
98
109
|
Image.prototype.className = 'Image';
|
|
99
110
|
(0, Global_1._registerNode)(Image);
|
|
111
|
+
Factory_1.Factory.addGetterSetter(Image, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
|
|
100
112
|
Factory_1.Factory.addGetterSetter(Image, 'image');
|
|
101
113
|
Factory_1.Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
102
114
|
Factory_1.Factory.addGetterSetter(Image, 'cropX', 0, (0, Validators_1.getNumberValidator)());
|
package/cmj/shapes/Rect.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Shape, ShapeConfig } from '../Shape';
|
|
2
2
|
import { GetSet } from '../types';
|
|
3
|
+
import { Context } from '../Context';
|
|
3
4
|
export interface RectConfig extends ShapeConfig {
|
|
4
5
|
cornerRadius?: number | number[];
|
|
5
6
|
}
|
|
6
7
|
export declare class Rect extends Shape<RectConfig> {
|
|
7
|
-
_sceneFunc(context:
|
|
8
|
+
_sceneFunc(context: Context): void;
|
|
8
9
|
cornerRadius: GetSet<number | number[], this>;
|
|
9
10
|
}
|
package/cmj/shapes/Rect.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.Rect = void 0;
|
|
|
4
4
|
const Factory_1 = require("../Factory");
|
|
5
5
|
const Shape_1 = require("../Shape");
|
|
6
6
|
const Global_1 = require("../Global");
|
|
7
|
+
const Util_1 = require("../Util");
|
|
7
8
|
const Validators_1 = require("../Validators");
|
|
8
9
|
class Rect extends Shape_1.Shape {
|
|
9
10
|
_sceneFunc(context) {
|
|
@@ -13,28 +14,7 @@ class Rect extends Shape_1.Shape {
|
|
|
13
14
|
context.rect(0, 0, width, height);
|
|
14
15
|
}
|
|
15
16
|
else {
|
|
16
|
-
|
|
17
|
-
let topRight = 0;
|
|
18
|
-
let bottomLeft = 0;
|
|
19
|
-
let bottomRight = 0;
|
|
20
|
-
if (typeof cornerRadius === 'number') {
|
|
21
|
-
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
25
|
-
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
26
|
-
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
27
|
-
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
28
|
-
}
|
|
29
|
-
context.moveTo(topLeft, 0);
|
|
30
|
-
context.lineTo(width - topRight, 0);
|
|
31
|
-
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
32
|
-
context.lineTo(width, height - bottomRight);
|
|
33
|
-
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
34
|
-
context.lineTo(bottomLeft, height);
|
|
35
|
-
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
36
|
-
context.lineTo(0, topLeft);
|
|
37
|
-
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
17
|
+
Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
38
18
|
}
|
|
39
19
|
context.closePath();
|
|
40
20
|
context.fillStrokeShape(this);
|
|
@@ -899,6 +899,10 @@ class Transformer extends Group_1.Group {
|
|
|
899
899
|
toObject() {
|
|
900
900
|
return Node_1.Node.prototype.toObject.call(this);
|
|
901
901
|
}
|
|
902
|
+
clone(obj) {
|
|
903
|
+
var node = Node_1.Node.prototype.clone.call(this, obj);
|
|
904
|
+
return node;
|
|
905
|
+
}
|
|
902
906
|
getClientRect() {
|
|
903
907
|
if (this.nodes().length > 0) {
|
|
904
908
|
return super.getClientRect();
|
package/cmj/types.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface IFrame {
|
|
|
18
18
|
lastTime: number;
|
|
19
19
|
frameRate: number;
|
|
20
20
|
}
|
|
21
|
-
export
|
|
21
|
+
export type AnimationFn = (frame?: IFrame) => boolean | void;
|
|
22
22
|
export declare enum KonvaNodeEvent {
|
|
23
23
|
mouseover = "mouseover",
|
|
24
24
|
mouseout = "mouseout",
|