konva 8.1.4
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/CHANGELOG.md +1140 -0
- package/LICENSE +22 -0
- package/README.md +189 -0
- package/konva.js +18090 -0
- package/konva.min.js +12 -0
- package/lib/Animation.d.ts +24 -0
- package/lib/Animation.js +141 -0
- package/lib/Canvas.d.ts +32 -0
- package/lib/Canvas.js +107 -0
- package/lib/Container.d.ts +47 -0
- package/lib/Container.js +318 -0
- package/lib/Context.d.ts +76 -0
- package/lib/Context.js +520 -0
- package/lib/Core.d.ts +3 -0
- package/lib/Core.js +3 -0
- package/lib/DragAndDrop.d.ts +17 -0
- package/lib/DragAndDrop.js +104 -0
- package/lib/Factory.d.ts +11 -0
- package/lib/Factory.js +117 -0
- package/lib/FastLayer.d.ts +4 -0
- package/lib/FastLayer.js +12 -0
- package/lib/Global.d.ts +30 -0
- package/lib/Global.js +53 -0
- package/lib/Group.d.ts +6 -0
- package/lib/Group.js +13 -0
- package/lib/Layer.d.ts +60 -0
- package/lib/Layer.js +301 -0
- package/lib/Node.d.ts +318 -0
- package/lib/Node.js +1381 -0
- package/lib/PointerEvents.d.ts +11 -0
- package/lib/PointerEvents.js +37 -0
- package/lib/Shape.d.ts +184 -0
- package/lib/Shape.js +515 -0
- package/lib/Stage.d.ts +85 -0
- package/lib/Stage.js +687 -0
- package/lib/Tween.d.ts +86 -0
- package/lib/Tween.js +516 -0
- package/lib/Util.d.ts +87 -0
- package/lib/Util.js +742 -0
- package/lib/Validators.d.ts +11 -0
- package/lib/Validators.js +171 -0
- package/lib/_CoreInternals.d.ts +144 -0
- package/lib/_CoreInternals.js +34 -0
- package/lib/_FullInternals.d.ts +188 -0
- package/lib/_FullInternals.js +78 -0
- package/lib/filters/Blur.d.ts +2 -0
- package/lib/filters/Blur.js +697 -0
- package/lib/filters/Brighten.d.ts +2 -0
- package/lib/filters/Brighten.js +12 -0
- package/lib/filters/Contrast.d.ts +2 -0
- package/lib/filters/Contrast.js +34 -0
- package/lib/filters/Emboss.d.ts +2 -0
- package/lib/filters/Emboss.js +102 -0
- package/lib/filters/Enhance.d.ts +2 -0
- package/lib/filters/Enhance.js +83 -0
- package/lib/filters/Grayscale.d.ts +2 -0
- package/lib/filters/Grayscale.js +9 -0
- package/lib/filters/HSL.d.ts +2 -0
- package/lib/filters/HSL.js +24 -0
- package/lib/filters/HSV.d.ts +2 -0
- package/lib/filters/HSV.js +24 -0
- package/lib/filters/Invert.d.ts +2 -0
- package/lib/filters/Invert.js +8 -0
- package/lib/filters/Kaleidoscope.d.ts +2 -0
- package/lib/filters/Kaleidoscope.js +132 -0
- package/lib/filters/Mask.d.ts +2 -0
- package/lib/filters/Mask.js +140 -0
- package/lib/filters/Noise.d.ts +2 -0
- package/lib/filters/Noise.js +12 -0
- package/lib/filters/Pixelate.d.ts +2 -0
- package/lib/filters/Pixelate.js +60 -0
- package/lib/filters/Posterize.d.ts +2 -0
- package/lib/filters/Posterize.js +10 -0
- package/lib/filters/RGB.d.ts +2 -0
- package/lib/filters/RGB.js +39 -0
- package/lib/filters/RGBA.d.ts +2 -0
- package/lib/filters/RGBA.js +49 -0
- package/lib/filters/Sepia.d.ts +2 -0
- package/lib/filters/Sepia.js +11 -0
- package/lib/filters/Solarize.d.ts +2 -0
- package/lib/filters/Solarize.js +25 -0
- package/lib/filters/Threshold.d.ts +2 -0
- package/lib/filters/Threshold.js +10 -0
- package/lib/index-node.d.ts +2 -0
- package/lib/index-node.js +18 -0
- package/lib/index-types.d.ts +179 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/shapes/Arc.d.ts +19 -0
- package/lib/shapes/Arc.js +35 -0
- package/lib/shapes/Arrow.d.ts +24 -0
- package/lib/shapes/Arrow.js +94 -0
- package/lib/shapes/Circle.d.ts +13 -0
- package/lib/shapes/Circle.js +33 -0
- package/lib/shapes/Ellipse.d.ts +16 -0
- package/lib/shapes/Ellipse.js +37 -0
- package/lib/shapes/Image.d.ts +23 -0
- package/lib/shapes/Image.js +100 -0
- package/lib/shapes/Label.d.ts +35 -0
- package/lib/shapes/Label.js +166 -0
- package/lib/shapes/Line.d.ts +28 -0
- package/lib/shapes/Line.js +155 -0
- package/lib/shapes/Path.d.ts +37 -0
- package/lib/shapes/Path.js +627 -0
- package/lib/shapes/Rect.d.ts +9 -0
- package/lib/shapes/Rect.js +42 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +65 -0
- package/lib/shapes/Ring.d.ts +16 -0
- package/lib/shapes/Ring.js +33 -0
- package/lib/shapes/Sprite.d.ts +30 -0
- package/lib/shapes/Sprite.js +108 -0
- package/lib/shapes/Star.d.ts +17 -0
- package/lib/shapes/Star.js +38 -0
- package/lib/shapes/Text.d.ts +59 -0
- package/lib/shapes/Text.js +347 -0
- package/lib/shapes/TextPath.d.ts +54 -0
- package/lib/shapes/TextPath.js +343 -0
- package/lib/shapes/Transformer.d.ts +112 -0
- package/lib/shapes/Transformer.js +944 -0
- package/lib/shapes/Wedge.d.ts +17 -0
- package/lib/shapes/Wedge.js +38 -0
- package/lib/types.d.ts +50 -0
- package/lib/types.js +22 -0
- package/package.json +111 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface ArcConfig extends ShapeConfig {
|
|
4
|
+
angle: number;
|
|
5
|
+
innerRadius: number;
|
|
6
|
+
outerRadius: number;
|
|
7
|
+
clockwise?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class Arc extends Shape<ArcConfig> {
|
|
10
|
+
_sceneFunc(context: any): void;
|
|
11
|
+
getWidth(): number;
|
|
12
|
+
getHeight(): number;
|
|
13
|
+
setWidth(width: any): void;
|
|
14
|
+
setHeight(height: any): void;
|
|
15
|
+
innerRadius: GetSet<number, this>;
|
|
16
|
+
outerRadius: GetSet<number, this>;
|
|
17
|
+
angle: GetSet<number, this>;
|
|
18
|
+
clockwise: GetSet<boolean, this>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { Konva } from '../Global.js';
|
|
4
|
+
import { getNumberValidator, getBooleanValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
|
+
export class Arc extends Shape {
|
|
7
|
+
_sceneFunc(context) {
|
|
8
|
+
var angle = Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
|
9
|
+
context.beginPath();
|
|
10
|
+
context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
|
11
|
+
context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
|
12
|
+
context.closePath();
|
|
13
|
+
context.fillStrokeShape(this);
|
|
14
|
+
}
|
|
15
|
+
getWidth() {
|
|
16
|
+
return this.outerRadius() * 2;
|
|
17
|
+
}
|
|
18
|
+
getHeight() {
|
|
19
|
+
return this.outerRadius() * 2;
|
|
20
|
+
}
|
|
21
|
+
setWidth(width) {
|
|
22
|
+
this.outerRadius(width / 2);
|
|
23
|
+
}
|
|
24
|
+
setHeight(height) {
|
|
25
|
+
this.outerRadius(height / 2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
Arc.prototype._centroid = true;
|
|
29
|
+
Arc.prototype.className = 'Arc';
|
|
30
|
+
Arc.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
|
|
31
|
+
_registerNode(Arc);
|
|
32
|
+
Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator());
|
|
33
|
+
Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator());
|
|
34
|
+
Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator());
|
|
35
|
+
Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator());
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Line, LineConfig } from './Line';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface ArrowConfig extends LineConfig {
|
|
4
|
+
points: number[];
|
|
5
|
+
tension?: number;
|
|
6
|
+
closed?: boolean;
|
|
7
|
+
pointerLength?: number;
|
|
8
|
+
pointerWidth?: number;
|
|
9
|
+
pointerAtBeginning?: boolean;
|
|
10
|
+
pointerAtEnding?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class Arrow extends Line<ArrowConfig> {
|
|
13
|
+
_sceneFunc(ctx: any): void;
|
|
14
|
+
getSelfRect(): {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
pointerLength: GetSet<number, this>;
|
|
21
|
+
pointerWidth: GetSet<number, this>;
|
|
22
|
+
pointerAtEnding: GetSet<boolean, this>;
|
|
23
|
+
pointerAtBeginning: GetSet<boolean, this>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Line } from './Line.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
import { Path } from './Path.js';
|
|
6
|
+
export class Arrow extends Line {
|
|
7
|
+
_sceneFunc(ctx) {
|
|
8
|
+
super._sceneFunc(ctx);
|
|
9
|
+
var PI2 = Math.PI * 2;
|
|
10
|
+
var points = this.points();
|
|
11
|
+
var tp = points;
|
|
12
|
+
var fromTension = this.tension() !== 0 && points.length > 4;
|
|
13
|
+
if (fromTension) {
|
|
14
|
+
tp = this.getTensionPoints();
|
|
15
|
+
}
|
|
16
|
+
var length = this.pointerLength();
|
|
17
|
+
var n = points.length;
|
|
18
|
+
var dx, dy;
|
|
19
|
+
if (fromTension) {
|
|
20
|
+
const lp = [
|
|
21
|
+
tp[tp.length - 4],
|
|
22
|
+
tp[tp.length - 3],
|
|
23
|
+
tp[tp.length - 2],
|
|
24
|
+
tp[tp.length - 1],
|
|
25
|
+
points[n - 2],
|
|
26
|
+
points[n - 1],
|
|
27
|
+
];
|
|
28
|
+
const lastLength = Path.calcLength(tp[tp.length - 4], tp[tp.length - 3], 'C', lp);
|
|
29
|
+
const previous = Path.getPointOnQuadraticBezier(Math.min(1, 1 - length / lastLength), lp[0], lp[1], lp[2], lp[3], lp[4], lp[5]);
|
|
30
|
+
dx = points[n - 2] - previous.x;
|
|
31
|
+
dy = points[n - 1] - previous.y;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
dx = points[n - 2] - points[n - 4];
|
|
35
|
+
dy = points[n - 1] - points[n - 3];
|
|
36
|
+
}
|
|
37
|
+
var radians = (Math.atan2(dy, dx) + PI2) % PI2;
|
|
38
|
+
var width = this.pointerWidth();
|
|
39
|
+
if (this.pointerAtEnding()) {
|
|
40
|
+
ctx.save();
|
|
41
|
+
ctx.beginPath();
|
|
42
|
+
ctx.translate(points[n - 2], points[n - 1]);
|
|
43
|
+
ctx.rotate(radians);
|
|
44
|
+
ctx.moveTo(0, 0);
|
|
45
|
+
ctx.lineTo(-length, width / 2);
|
|
46
|
+
ctx.lineTo(-length, -width / 2);
|
|
47
|
+
ctx.closePath();
|
|
48
|
+
ctx.restore();
|
|
49
|
+
}
|
|
50
|
+
if (this.pointerAtBeginning()) {
|
|
51
|
+
ctx.save();
|
|
52
|
+
ctx.translate(points[0], points[1]);
|
|
53
|
+
if (fromTension) {
|
|
54
|
+
dx = (tp[0] + tp[2]) / 2 - points[0];
|
|
55
|
+
dy = (tp[1] + tp[3]) / 2 - points[1];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
dx = points[2] - points[0];
|
|
59
|
+
dy = points[3] - points[1];
|
|
60
|
+
}
|
|
61
|
+
ctx.rotate((Math.atan2(-dy, -dx) + PI2) % PI2);
|
|
62
|
+
ctx.moveTo(0, 0);
|
|
63
|
+
ctx.lineTo(-length, width / 2);
|
|
64
|
+
ctx.lineTo(-length, -width / 2);
|
|
65
|
+
ctx.closePath();
|
|
66
|
+
ctx.restore();
|
|
67
|
+
}
|
|
68
|
+
var isDashEnabled = this.dashEnabled();
|
|
69
|
+
if (isDashEnabled) {
|
|
70
|
+
this.attrs.dashEnabled = false;
|
|
71
|
+
ctx.setLineDash([]);
|
|
72
|
+
}
|
|
73
|
+
ctx.fillStrokeShape(this);
|
|
74
|
+
if (isDashEnabled) {
|
|
75
|
+
this.attrs.dashEnabled = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
getSelfRect() {
|
|
79
|
+
const lineRect = super.getSelfRect();
|
|
80
|
+
const offset = this.pointerWidth() / 2;
|
|
81
|
+
return {
|
|
82
|
+
x: lineRect.x - offset,
|
|
83
|
+
y: lineRect.y - offset,
|
|
84
|
+
width: lineRect.width + offset * 2,
|
|
85
|
+
height: lineRect.height + offset * 2,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
Arrow.prototype.className = 'Arrow';
|
|
90
|
+
_registerNode(Arrow);
|
|
91
|
+
Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator());
|
|
92
|
+
Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator());
|
|
93
|
+
Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
|
|
94
|
+
Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet } from '../types';
|
|
3
|
+
export interface CircleConfig extends ShapeConfig {
|
|
4
|
+
radius?: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class Circle extends Shape<CircleConfig> {
|
|
7
|
+
_sceneFunc(context: any): void;
|
|
8
|
+
getWidth(): number;
|
|
9
|
+
getHeight(): number;
|
|
10
|
+
setWidth(width: any): void;
|
|
11
|
+
setHeight(height: any): void;
|
|
12
|
+
radius: GetSet<number, this>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
export class Circle extends Shape {
|
|
6
|
+
_sceneFunc(context) {
|
|
7
|
+
context.beginPath();
|
|
8
|
+
context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
|
|
9
|
+
context.closePath();
|
|
10
|
+
context.fillStrokeShape(this);
|
|
11
|
+
}
|
|
12
|
+
getWidth() {
|
|
13
|
+
return this.radius() * 2;
|
|
14
|
+
}
|
|
15
|
+
getHeight() {
|
|
16
|
+
return this.radius() * 2;
|
|
17
|
+
}
|
|
18
|
+
setWidth(width) {
|
|
19
|
+
if (this.radius() !== width / 2) {
|
|
20
|
+
this.radius(width / 2);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
setHeight(height) {
|
|
24
|
+
if (this.radius() !== height / 2) {
|
|
25
|
+
this.radius(height / 2);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
Circle.prototype._centroid = true;
|
|
30
|
+
Circle.prototype.className = 'Circle';
|
|
31
|
+
Circle.prototype._attrsAffectingSize = ['radius'];
|
|
32
|
+
_registerNode(Circle);
|
|
33
|
+
Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator());
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet, Vector2d } from '../types';
|
|
3
|
+
export interface EllipseConfig extends ShapeConfig {
|
|
4
|
+
radiusX: number;
|
|
5
|
+
radiusY: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class Ellipse extends Shape<EllipseConfig> {
|
|
8
|
+
_sceneFunc(context: any): void;
|
|
9
|
+
getWidth(): number;
|
|
10
|
+
getHeight(): number;
|
|
11
|
+
setWidth(width: any): void;
|
|
12
|
+
setHeight(height: any): void;
|
|
13
|
+
radius: GetSet<Vector2d, this>;
|
|
14
|
+
radiusX: GetSet<number, this>;
|
|
15
|
+
radiusY: GetSet<number, this>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Factory } from '../Factory.js';
|
|
2
|
+
import { Shape } from '../Shape.js';
|
|
3
|
+
import { getNumberValidator } from '../Validators.js';
|
|
4
|
+
import { _registerNode } from '../Global.js';
|
|
5
|
+
export class Ellipse extends Shape {
|
|
6
|
+
_sceneFunc(context) {
|
|
7
|
+
var rx = this.radiusX(), ry = this.radiusY();
|
|
8
|
+
context.beginPath();
|
|
9
|
+
context.save();
|
|
10
|
+
if (rx !== ry) {
|
|
11
|
+
context.scale(1, ry / rx);
|
|
12
|
+
}
|
|
13
|
+
context.arc(0, 0, rx, 0, Math.PI * 2, false);
|
|
14
|
+
context.restore();
|
|
15
|
+
context.closePath();
|
|
16
|
+
context.fillStrokeShape(this);
|
|
17
|
+
}
|
|
18
|
+
getWidth() {
|
|
19
|
+
return this.radiusX() * 2;
|
|
20
|
+
}
|
|
21
|
+
getHeight() {
|
|
22
|
+
return this.radiusY() * 2;
|
|
23
|
+
}
|
|
24
|
+
setWidth(width) {
|
|
25
|
+
this.radiusX(width / 2);
|
|
26
|
+
}
|
|
27
|
+
setHeight(height) {
|
|
28
|
+
this.radiusY(height / 2);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
Ellipse.prototype.className = 'Ellipse';
|
|
32
|
+
Ellipse.prototype._centroid = true;
|
|
33
|
+
Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
|
|
34
|
+
_registerNode(Ellipse);
|
|
35
|
+
Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
|
|
36
|
+
Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator());
|
|
37
|
+
Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator());
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { GetSet, IRect } from '../types';
|
|
3
|
+
import { Context } from '../Context';
|
|
4
|
+
export interface ImageConfig extends ShapeConfig {
|
|
5
|
+
image: CanvasImageSource | undefined;
|
|
6
|
+
crop?: IRect;
|
|
7
|
+
}
|
|
8
|
+
export declare class Image extends Shape<ImageConfig> {
|
|
9
|
+
constructor(attrs: ImageConfig);
|
|
10
|
+
_setImageLoad(): void;
|
|
11
|
+
_useBufferCanvas(): boolean;
|
|
12
|
+
_sceneFunc(context: Context): void;
|
|
13
|
+
_hitFunc(context: any): void;
|
|
14
|
+
getWidth(): any;
|
|
15
|
+
getHeight(): any;
|
|
16
|
+
static fromURL(url: any, callback: any): void;
|
|
17
|
+
image: GetSet<CanvasImageSource | undefined, this>;
|
|
18
|
+
crop: GetSet<IRect, this>;
|
|
19
|
+
cropX: GetSet<number, this>;
|
|
20
|
+
cropY: GetSet<number, this>;
|
|
21
|
+
cropWidth: GetSet<number, this>;
|
|
22
|
+
cropHeight: GetSet<number, this>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Util } from '../Util.js';
|
|
2
|
+
import { Factory } from '../Factory.js';
|
|
3
|
+
import { Shape } from '../Shape.js';
|
|
4
|
+
import { getNumberValidator } from '../Validators.js';
|
|
5
|
+
import { _registerNode } from '../Global.js';
|
|
6
|
+
export class Image extends Shape {
|
|
7
|
+
constructor(attrs) {
|
|
8
|
+
super(attrs);
|
|
9
|
+
this.on('imageChange.konva', () => {
|
|
10
|
+
this._setImageLoad();
|
|
11
|
+
});
|
|
12
|
+
this._setImageLoad();
|
|
13
|
+
}
|
|
14
|
+
_setImageLoad() {
|
|
15
|
+
const image = this.image();
|
|
16
|
+
if (image && image.complete) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (image && image.readyState === 4) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (image && image['addEventListener']) {
|
|
23
|
+
image['addEventListener']('load', () => {
|
|
24
|
+
this._requestDraw();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
_useBufferCanvas() {
|
|
29
|
+
return super._useBufferCanvas(true);
|
|
30
|
+
}
|
|
31
|
+
_sceneFunc(context) {
|
|
32
|
+
const width = this.getWidth();
|
|
33
|
+
const height = this.getHeight();
|
|
34
|
+
const image = this.attrs.image;
|
|
35
|
+
let params;
|
|
36
|
+
if (image) {
|
|
37
|
+
const cropWidth = this.attrs.cropWidth;
|
|
38
|
+
const cropHeight = this.attrs.cropHeight;
|
|
39
|
+
if (cropWidth && cropHeight) {
|
|
40
|
+
params = [
|
|
41
|
+
image,
|
|
42
|
+
this.cropX(),
|
|
43
|
+
this.cropY(),
|
|
44
|
+
cropWidth,
|
|
45
|
+
cropHeight,
|
|
46
|
+
0,
|
|
47
|
+
0,
|
|
48
|
+
width,
|
|
49
|
+
height,
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
params = [image, 0, 0, width, height];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (this.hasFill() || this.hasStroke()) {
|
|
57
|
+
context.beginPath();
|
|
58
|
+
context.rect(0, 0, width, height);
|
|
59
|
+
context.closePath();
|
|
60
|
+
context.fillStrokeShape(this);
|
|
61
|
+
}
|
|
62
|
+
if (image) {
|
|
63
|
+
context.drawImage.apply(context, params);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
_hitFunc(context) {
|
|
67
|
+
var width = this.width(), height = this.height();
|
|
68
|
+
context.beginPath();
|
|
69
|
+
context.rect(0, 0, width, height);
|
|
70
|
+
context.closePath();
|
|
71
|
+
context.fillStrokeShape(this);
|
|
72
|
+
}
|
|
73
|
+
getWidth() {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
return (_a = this.attrs.width) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.width;
|
|
76
|
+
}
|
|
77
|
+
getHeight() {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
80
|
+
}
|
|
81
|
+
static fromURL(url, callback) {
|
|
82
|
+
var img = Util.createImageElement();
|
|
83
|
+
img.onload = function () {
|
|
84
|
+
var image = new Image({
|
|
85
|
+
image: img,
|
|
86
|
+
});
|
|
87
|
+
callback(image);
|
|
88
|
+
};
|
|
89
|
+
img.crossOrigin = 'Anonymous';
|
|
90
|
+
img.src = url;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Image.prototype.className = 'Image';
|
|
94
|
+
_registerNode(Image);
|
|
95
|
+
Factory.addGetterSetter(Image, 'image');
|
|
96
|
+
Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
97
|
+
Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
|
|
98
|
+
Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
|
|
99
|
+
Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
|
|
100
|
+
Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Shape, ShapeConfig } from '../Shape';
|
|
2
|
+
import { Group } from '../Group';
|
|
3
|
+
import { ContainerConfig } from '../Container';
|
|
4
|
+
import { GetSet } from '../types';
|
|
5
|
+
import { Text } from './Text';
|
|
6
|
+
export interface LabelConfig extends ContainerConfig {
|
|
7
|
+
}
|
|
8
|
+
export declare class Label extends Group {
|
|
9
|
+
constructor(config?: any);
|
|
10
|
+
getText(): Text;
|
|
11
|
+
getTag(): Tag;
|
|
12
|
+
_addListeners(text: any): void;
|
|
13
|
+
getWidth(): number;
|
|
14
|
+
getHeight(): number;
|
|
15
|
+
_sync(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface TagConfig extends ShapeConfig {
|
|
18
|
+
pointerDirection?: string;
|
|
19
|
+
pointerWidth?: number;
|
|
20
|
+
pointerHeight?: number;
|
|
21
|
+
cornerRadius?: number | Array<number>;
|
|
22
|
+
}
|
|
23
|
+
export declare class Tag extends Shape<TagConfig> {
|
|
24
|
+
_sceneFunc(context: any): void;
|
|
25
|
+
getSelfRect(): {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
width: number;
|
|
29
|
+
height: number;
|
|
30
|
+
};
|
|
31
|
+
pointerDirection: GetSet<'left' | 'top' | 'right' | 'bottom', this>;
|
|
32
|
+
pointerWidth: GetSet<number, this>;
|
|
33
|
+
pointerHeight: GetSet<number, this>;
|
|
34
|
+
cornerRadius: GetSet<number, this>;
|
|
35
|
+
}
|