konva 9.3.21 → 10.0.0-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/README.md +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/filters/RGBA.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const RGBA = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { RGBComponent } from "../Validators.js";
|
|
4
|
+
export const RGBA = function (imageData) {
|
|
8
5
|
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha();
|
|
9
6
|
for (let i = 0; i < nPixels; i += 4) {
|
|
10
7
|
const ia = 1 - alpha;
|
|
@@ -13,8 +10,7 @@ const RGBA = function (imageData) {
|
|
|
13
10
|
data[i + 2] = blue * alpha + data[i + 2] * ia;
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
|
13
|
+
Factory.addGetterSetter(Node, 'red', 0, function (val) {
|
|
18
14
|
this._filterUpToDate = false;
|
|
19
15
|
if (val > 255) {
|
|
20
16
|
return 255;
|
|
@@ -26,7 +22,7 @@ Factory_1.Factory.addGetterSetter(Node_1.Node, 'red', 0, function (val) {
|
|
|
26
22
|
return Math.round(val);
|
|
27
23
|
}
|
|
28
24
|
});
|
|
29
|
-
|
|
25
|
+
Factory.addGetterSetter(Node, 'green', 0, function (val) {
|
|
30
26
|
this._filterUpToDate = false;
|
|
31
27
|
if (val > 255) {
|
|
32
28
|
return 255;
|
|
@@ -38,8 +34,8 @@ Factory_1.Factory.addGetterSetter(Node_1.Node, 'green', 0, function (val) {
|
|
|
38
34
|
return Math.round(val);
|
|
39
35
|
}
|
|
40
36
|
});
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
Factory.addGetterSetter(Node, 'blue', 0, RGBComponent, Factory.afterSetFilter);
|
|
38
|
+
Factory.addGetterSetter(Node, 'alpha', 1, function (val) {
|
|
43
39
|
this._filterUpToDate = false;
|
|
44
40
|
if (val > 1) {
|
|
45
41
|
return 1;
|
package/lib/filters/Sepia.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Sepia: Filter;
|
package/lib/filters/Sepia.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Sepia = void 0;
|
|
4
|
-
const Sepia = function (imageData) {
|
|
1
|
+
export const Sepia = function (imageData) {
|
|
5
2
|
const data = imageData.data, nPixels = data.length;
|
|
6
3
|
for (let i = 0; i < nPixels; i += 4) {
|
|
7
4
|
const r = data[i + 0];
|
|
@@ -12,4 +9,3 @@ const Sepia = function (imageData) {
|
|
|
12
9
|
data[i + 2] = Math.min(255, r * 0.272 + g * 0.534 + b * 0.131);
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
exports.Sepia = Sepia;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Solarize: Filter;
|
package/lib/filters/Solarize.js
CHANGED
|
@@ -1,30 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let b = data[offset + 2];
|
|
15
|
-
if (r > 127) {
|
|
16
|
-
r = 255 - r;
|
|
17
|
-
}
|
|
18
|
-
if (g > 127) {
|
|
19
|
-
g = 255 - g;
|
|
20
|
-
}
|
|
21
|
-
if (b > 127) {
|
|
22
|
-
b = 255 - b;
|
|
23
|
-
}
|
|
24
|
-
data[offset] = r;
|
|
25
|
-
data[offset + 1] = g;
|
|
26
|
-
data[offset + 2] = b;
|
|
27
|
-
} while (--x);
|
|
28
|
-
} while (--y);
|
|
1
|
+
export const Solarize = function (imageData) {
|
|
2
|
+
const threshold = 128;
|
|
3
|
+
const d = imageData.data;
|
|
4
|
+
for (let i = 0; i < d.length; i += 4) {
|
|
5
|
+
const r = d[i], g = d[i + 1], b = d[i + 2];
|
|
6
|
+
const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
7
|
+
if (L >= threshold) {
|
|
8
|
+
d[i] = 255 - r;
|
|
9
|
+
d[i + 1] = 255 - g;
|
|
10
|
+
d[i + 2] = 255 - b;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return imageData;
|
|
29
14
|
};
|
|
30
|
-
exports.Solarize = Solarize;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Filter } from '../Node.
|
|
1
|
+
import type { Filter } from '../Node.ts';
|
|
2
2
|
export declare const Threshold: Filter;
|
package/lib/filters/Threshold.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const Node_1 = require("../Node");
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const Threshold = function (imageData) {
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Node } from "../Node.js";
|
|
3
|
+
import { getNumberValidator } from "../Validators.js";
|
|
4
|
+
export const Threshold = function (imageData) {
|
|
8
5
|
const level = this.threshold() * 255, data = imageData.data, len = data.length;
|
|
9
6
|
for (let i = 0; i < len; i += 1) {
|
|
10
7
|
data[i] = data[i] < level ? 0 : 255;
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
Factory_1.Factory.addGetterSetter(Node_1.Node, 'threshold', 0.5, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
10
|
+
Factory.addGetterSetter(Node, 'threshold', 0.5, getNumberValidator(), Factory.afterSetFilter);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Konva } from './_FullInternals.
|
|
1
|
+
import { Konva } from './_FullInternals.ts';
|
|
2
2
|
export default Konva;
|
package/lib/index.js
CHANGED
package/lib/shapes/Arc.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
4
5
|
export interface ArcConfig extends ShapeConfig {
|
|
5
6
|
angle: number;
|
|
6
7
|
innerRadius: number;
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
8
|
-
const Global_2 = require("../Global");
|
|
9
|
-
class Arc extends Shape_1.Shape {
|
|
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 {
|
|
10
7
|
_sceneFunc(context) {
|
|
11
|
-
const angle =
|
|
8
|
+
const angle = Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
|
12
9
|
context.beginPath();
|
|
13
10
|
context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
|
14
11
|
context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
|
@@ -31,7 +28,7 @@ class Arc extends Shape_1.Shape {
|
|
|
31
28
|
const innerRadius = this.innerRadius();
|
|
32
29
|
const outerRadius = this.outerRadius();
|
|
33
30
|
const clockwise = this.clockwise();
|
|
34
|
-
const angle =
|
|
31
|
+
const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
35
32
|
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
36
33
|
const boundRightRatio = 1;
|
|
37
34
|
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
|
|
@@ -48,7 +45,6 @@ class Arc extends Shape_1.Shape {
|
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.Arc = Arc;
|
|
52
48
|
Arc.prototype._centroid = true;
|
|
53
49
|
Arc.prototype.className = 'Arc';
|
|
54
50
|
Arc.prototype._attrsAffectingSize = [
|
|
@@ -57,8 +53,8 @@ Arc.prototype._attrsAffectingSize = [
|
|
|
57
53
|
'angle',
|
|
58
54
|
'clockwise',
|
|
59
55
|
];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
_registerNode(Arc);
|
|
57
|
+
Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator());
|
|
58
|
+
Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator());
|
|
59
|
+
Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator());
|
|
60
|
+
Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator());
|
package/lib/shapes/Arrow.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { LineConfig } from './Line.ts';
|
|
2
|
+
import { Line } from './Line.ts';
|
|
3
|
+
import type { GetSet } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
4
5
|
export interface ArrowConfig extends LineConfig {
|
|
5
6
|
points: number[];
|
|
6
7
|
tension?: number;
|
package/lib/shapes/Arrow.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Global_1 = require("../Global");
|
|
8
|
-
const Path_1 = require("./Path");
|
|
9
|
-
class Arrow extends Line_1.Line {
|
|
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 {
|
|
10
7
|
_sceneFunc(ctx) {
|
|
11
8
|
super._sceneFunc(ctx);
|
|
12
9
|
const PI2 = Math.PI * 2;
|
|
@@ -28,8 +25,8 @@ class Arrow extends Line_1.Line {
|
|
|
28
25
|
points[n - 2],
|
|
29
26
|
points[n - 1],
|
|
30
27
|
];
|
|
31
|
-
const lastLength =
|
|
32
|
-
const previous =
|
|
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]);
|
|
33
30
|
dx = points[n - 2] - previous.x;
|
|
34
31
|
dy = points[n - 1] - previous.y;
|
|
35
32
|
}
|
|
@@ -94,10 +91,9 @@ class Arrow extends Line_1.Line {
|
|
|
94
91
|
};
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
|
-
exports.Arrow = Arrow;
|
|
98
94
|
Arrow.prototype.className = 'Arrow';
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
95
|
+
_registerNode(Arrow);
|
|
96
|
+
Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator());
|
|
97
|
+
Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator());
|
|
98
|
+
Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
|
|
99
|
+
Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
|
package/lib/shapes/Circle.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
4
5
|
export interface CircleConfig extends ShapeConfig {
|
|
5
6
|
radius?: number;
|
|
6
7
|
}
|
package/lib/shapes/Circle.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const Global_1 = require("../Global");
|
|
8
|
-
class Circle extends Shape_1.Shape {
|
|
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 {
|
|
9
6
|
_sceneFunc(context) {
|
|
10
7
|
context.beginPath();
|
|
11
8
|
context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
|
|
@@ -29,9 +26,8 @@ class Circle extends Shape_1.Shape {
|
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
|
-
exports.Circle = Circle;
|
|
33
29
|
Circle.prototype._centroid = true;
|
|
34
30
|
Circle.prototype.className = 'Circle';
|
|
35
31
|
Circle.prototype._attrsAffectingSize = ['radius'];
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
_registerNode(Circle);
|
|
33
|
+
Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator());
|
package/lib/shapes/Ellipse.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { Context } from '../Context.ts';
|
|
4
|
+
import type { GetSet, Vector2d } from '../types.ts';
|
|
4
5
|
export interface EllipseConfig extends ShapeConfig {
|
|
5
6
|
radiusX: number;
|
|
6
7
|
radiusY: number;
|
package/lib/shapes/Ellipse.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Validators_1 = require("../Validators");
|
|
7
|
-
const Global_1 = require("../Global");
|
|
8
|
-
class Ellipse extends Shape_1.Shape {
|
|
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 {
|
|
9
6
|
_sceneFunc(context) {
|
|
10
7
|
const rx = this.radiusX(), ry = this.radiusY();
|
|
11
8
|
context.beginPath();
|
|
@@ -31,11 +28,10 @@ class Ellipse extends Shape_1.Shape {
|
|
|
31
28
|
this.radiusY(height / 2);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
exports.Ellipse = Ellipse;
|
|
35
31
|
Ellipse.prototype.className = 'Ellipse';
|
|
36
32
|
Ellipse.prototype._centroid = true;
|
|
37
33
|
Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
_registerNode(Ellipse);
|
|
35
|
+
Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
|
|
36
|
+
Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator());
|
|
37
|
+
Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator());
|
package/lib/shapes/Image.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet, IRect } from '../types.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
4
5
|
export interface ImageConfig extends ShapeConfig {
|
|
5
6
|
image: CanvasImageSource | undefined;
|
|
6
7
|
crop?: IRect;
|
package/lib/shapes/Image.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Global_1 = require("../Global");
|
|
8
|
-
const Validators_1 = require("../Validators");
|
|
9
|
-
class Image extends Shape_1.Shape {
|
|
1
|
+
import { Util } from "../Util.js";
|
|
2
|
+
import { Factory } from "../Factory.js";
|
|
3
|
+
import { Shape } from "../Shape.js";
|
|
4
|
+
import { _registerNode } from "../Global.js";
|
|
5
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
6
|
+
export class Image extends Shape {
|
|
10
7
|
constructor(attrs) {
|
|
11
8
|
super(attrs);
|
|
12
9
|
this._loadListener = () => {
|
|
@@ -77,7 +74,7 @@ class Image extends Shape_1.Shape {
|
|
|
77
74
|
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
78
75
|
context.beginPath();
|
|
79
76
|
cornerRadius
|
|
80
|
-
?
|
|
77
|
+
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
81
78
|
: context.rect(0, 0, width, height);
|
|
82
79
|
context.closePath();
|
|
83
80
|
context.fillStrokeShape(this);
|
|
@@ -96,7 +93,7 @@ class Image extends Shape_1.Shape {
|
|
|
96
93
|
context.rect(0, 0, width, height);
|
|
97
94
|
}
|
|
98
95
|
else {
|
|
99
|
-
|
|
96
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
100
97
|
}
|
|
101
98
|
context.closePath();
|
|
102
99
|
context.fillStrokeShape(this);
|
|
@@ -110,7 +107,7 @@ class Image extends Shape_1.Shape {
|
|
|
110
107
|
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
111
108
|
}
|
|
112
109
|
static fromURL(url, callback, onError = null) {
|
|
113
|
-
const img =
|
|
110
|
+
const img = Util.createImageElement();
|
|
114
111
|
img.onload = function () {
|
|
115
112
|
const image = new Image({
|
|
116
113
|
image: img,
|
|
@@ -122,13 +119,12 @@ class Image extends Shape_1.Shape {
|
|
|
122
119
|
img.src = url;
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
|
-
exports.Image = Image;
|
|
126
122
|
Image.prototype.className = 'Image';
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
_registerNode(Image);
|
|
124
|
+
Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
125
|
+
Factory.addGetterSetter(Image, 'image');
|
|
126
|
+
Factory.addComponentsGetterSetter(Image, 'crop', ['x', 'y', 'width', 'height']);
|
|
127
|
+
Factory.addGetterSetter(Image, 'cropX', 0, getNumberValidator());
|
|
128
|
+
Factory.addGetterSetter(Image, 'cropY', 0, getNumberValidator());
|
|
129
|
+
Factory.addGetterSetter(Image, 'cropWidth', 0, getNumberValidator());
|
|
130
|
+
Factory.addGetterSetter(Image, 'cropHeight', 0, getNumberValidator());
|
package/lib/shapes/Label.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import { Group } from '../Group.ts';
|
|
4
|
+
import type { Context } from '../Context.ts';
|
|
5
|
+
import type { ContainerConfig } from '../Container.ts';
|
|
6
|
+
import type { GetSet } from '../types.ts';
|
|
7
|
+
import type { Text } from './Text.ts';
|
|
7
8
|
export interface LabelConfig extends ContainerConfig {
|
|
8
9
|
}
|
|
9
10
|
declare const NONE = "none";
|
package/lib/shapes/Label.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const Group_1 = require("../Group");
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
8
|
-
const Global_1 = require("../Global");
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { Shape } from "../Shape.js";
|
|
3
|
+
import { Group } from "../Group.js";
|
|
4
|
+
import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from "../Validators.js";
|
|
5
|
+
import { _registerNode } from "../Global.js";
|
|
9
6
|
const ATTR_CHANGE_LIST = [
|
|
10
7
|
'fontFamily',
|
|
11
8
|
'fontSize',
|
|
@@ -19,7 +16,7 @@ const ATTR_CHANGE_LIST = [
|
|
|
19
16
|
'pointerWidth',
|
|
20
17
|
'pointerHeight',
|
|
21
18
|
], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
|
|
22
|
-
class Label extends
|
|
19
|
+
export class Label extends Group {
|
|
23
20
|
constructor(config) {
|
|
24
21
|
super(config);
|
|
25
22
|
this.on('add.konva', function (evt) {
|
|
@@ -89,10 +86,9 @@ class Label extends Group_1.Group {
|
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
exports.Label = Label;
|
|
93
89
|
Label.prototype.className = 'Label';
|
|
94
|
-
|
|
95
|
-
class Tag extends
|
|
90
|
+
_registerNode(Label);
|
|
91
|
+
export class Tag extends Shape {
|
|
96
92
|
_sceneFunc(context) {
|
|
97
93
|
const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
|
98
94
|
let topLeft = 0;
|
|
@@ -169,10 +165,9 @@ class Tag extends Shape_1.Shape {
|
|
|
169
165
|
};
|
|
170
166
|
}
|
|
171
167
|
}
|
|
172
|
-
exports.Tag = Tag;
|
|
173
168
|
Tag.prototype.className = 'Tag';
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
_registerNode(Tag);
|
|
170
|
+
Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
|
|
171
|
+
Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator());
|
|
172
|
+
Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
|
|
173
|
+
Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { Context } from '../Context.ts';
|
|
4
|
+
import type { GetSet } from '../types.ts';
|
|
4
5
|
export interface LineConfig extends ShapeConfig {
|
|
5
6
|
points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
6
7
|
tension?: number;
|
package/lib/shapes/Line.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Global_1 = require("../Global");
|
|
6
|
-
const Shape_1 = require("../Shape");
|
|
7
|
-
const Validators_1 = require("../Validators");
|
|
1
|
+
import { Factory } from "../Factory.js";
|
|
2
|
+
import { _registerNode } from "../Global.js";
|
|
3
|
+
import { Shape } from "../Shape.js";
|
|
4
|
+
import { getNumberArrayValidator, getNumberValidator } from "../Validators.js";
|
|
8
5
|
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
9
6
|
const d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
|
|
10
7
|
return [p1x, p1y, p2x, p2y];
|
|
@@ -25,7 +22,7 @@ function expandPoints(p, tension) {
|
|
|
25
22
|
}
|
|
26
23
|
return allPoints;
|
|
27
24
|
}
|
|
28
|
-
class Line extends
|
|
25
|
+
export class Line extends Shape {
|
|
29
26
|
constructor(config) {
|
|
30
27
|
super(config);
|
|
31
28
|
this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
|
|
@@ -150,11 +147,10 @@ class Line extends Shape_1.Shape {
|
|
|
150
147
|
};
|
|
151
148
|
}
|
|
152
149
|
}
|
|
153
|
-
exports.Line = Line;
|
|
154
150
|
Line.prototype.className = 'Line';
|
|
155
151
|
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
152
|
+
_registerNode(Line);
|
|
153
|
+
Factory.addGetterSetter(Line, 'closed', false);
|
|
154
|
+
Factory.addGetterSetter(Line, 'bezier', false);
|
|
155
|
+
Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator());
|
|
156
|
+
Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator());
|
package/lib/shapes/Path.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
2
|
+
import { Shape } from '../Shape.ts';
|
|
3
|
+
import type { GetSet, PathSegment } from '../types.ts';
|
|
3
4
|
export interface PathConfig extends ShapeConfig {
|
|
4
5
|
data?: string;
|
|
5
6
|
}
|