konva 9.3.14 → 9.3.16
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/konva.js +754 -737
- package/konva.min.js +3 -3
- package/lib/Animation.js +1 -1
- package/lib/BezierFunctions.js +1 -2
- package/lib/Canvas.js +9 -9
- package/lib/Container.d.ts +1 -1
- package/lib/Container.js +29 -29
- package/lib/Context.d.ts +2 -2
- package/lib/Context.js +26 -26
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/DragAndDrop.js +6 -4
- package/lib/Factory.js +16 -16
- package/lib/Global.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Layer.js +17 -17
- package/lib/Node.d.ts +4 -4
- package/lib/Node.js +87 -87
- package/lib/PointerEvents.js +5 -6
- package/lib/Shape.js +31 -31
- package/lib/Stage.d.ts +3 -3
- package/lib/Stage.js +28 -28
- package/lib/Tween.js +21 -21
- package/lib/Util.d.ts +4 -4
- package/lib/Util.js +62 -62
- package/lib/Validators.js +16 -17
- package/lib/_CoreInternals.d.ts +8 -8
- package/lib/_FullInternals.d.ts +8 -8
- package/lib/filters/Blur.js +6 -6
- package/lib/filters/Brighten.js +1 -1
- package/lib/filters/Contrast.js +2 -2
- package/lib/filters/Emboss.js +19 -19
- package/lib/filters/Enhance.js +4 -4
- package/lib/filters/Grayscale.js +1 -1
- package/lib/filters/HSL.js +6 -6
- package/lib/filters/HSV.js +7 -7
- package/lib/filters/Invert.js +1 -1
- package/lib/filters/Kaleidoscope.js +20 -20
- package/lib/filters/Mask.js +57 -57
- package/lib/filters/Noise.js +2 -2
- package/lib/filters/Pixelate.js +1 -1
- package/lib/filters/Posterize.js +1 -1
- package/lib/filters/RGB.js +1 -1
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Sepia.js +1 -1
- package/lib/filters/Solarize.js +8 -7
- package/lib/filters/Threshold.js +2 -2
- package/lib/shapes/Arc.js +1 -1
- package/lib/shapes/Arrow.js +10 -10
- package/lib/shapes/Ellipse.js +1 -1
- package/lib/shapes/Image.js +3 -3
- package/lib/shapes/Label.d.ts +1 -1
- package/lib/shapes/Label.js +6 -6
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +14 -14
- package/lib/shapes/Path.d.ts +8 -8
- package/lib/shapes/Path.js +68 -68
- package/lib/shapes/Rect.js +1 -1
- package/lib/shapes/RegularPolygon.js +6 -6
- package/lib/shapes/Ring.js +1 -1
- package/lib/shapes/Sprite.js +9 -9
- package/lib/shapes/Star.js +5 -5
- package/lib/shapes/Text.d.ts +13 -13
- package/lib/shapes/Text.js +52 -38
- package/lib/shapes/TextPath.d.ts +2 -2
- package/lib/shapes/TextPath.js +23 -23
- package/lib/shapes/Transformer.d.ts +1 -1
- package/lib/shapes/Transformer.js +63 -63
- package/package.json +2 -5
package/lib/filters/Emboss.js
CHANGED
|
@@ -6,7 +6,7 @@ const Node_1 = require("../Node");
|
|
|
6
6
|
const Util_1 = require("../Util");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
8
|
const Emboss = function (imageData) {
|
|
9
|
-
|
|
9
|
+
let strength = this.embossStrength() * 10, greyLevel = this.embossWhiteLevel() * 255, direction = this.embossDirection(), blend = this.embossBlend(), dirY = 0, dirX = 0, data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4, y = h;
|
|
10
10
|
switch (direction) {
|
|
11
11
|
case 'top-left':
|
|
12
12
|
dirY = -1;
|
|
@@ -44,33 +44,33 @@ const Emboss = function (imageData) {
|
|
|
44
44
|
Util_1.Util.error('Unknown emboss direction: ' + direction);
|
|
45
45
|
}
|
|
46
46
|
do {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const offsetY = (y - 1) * w4;
|
|
48
|
+
let otherY = dirY;
|
|
49
49
|
if (y + otherY < 1) {
|
|
50
50
|
otherY = 0;
|
|
51
51
|
}
|
|
52
52
|
if (y + otherY > h) {
|
|
53
53
|
otherY = 0;
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const offsetYOther = (y - 1 + otherY) * w * 4;
|
|
56
|
+
let x = w;
|
|
57
57
|
do {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const offset = offsetY + (x - 1) * 4;
|
|
59
|
+
let otherX = dirX;
|
|
60
60
|
if (x + otherX < 1) {
|
|
61
61
|
otherX = 0;
|
|
62
62
|
}
|
|
63
63
|
if (x + otherX > w) {
|
|
64
64
|
otherX = 0;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const offsetOther = offsetYOther + (x - 1 + otherX) * 4;
|
|
67
|
+
const dR = data[offset] - data[offsetOther];
|
|
68
|
+
const dG = data[offset + 1] - data[offsetOther + 1];
|
|
69
|
+
const dB = data[offset + 2] - data[offsetOther + 2];
|
|
70
|
+
let dif = dR;
|
|
71
|
+
const absDif = dif > 0 ? dif : -dif;
|
|
72
|
+
const absG = dG > 0 ? dG : -dG;
|
|
73
|
+
const absB = dB > 0 ? dB : -dB;
|
|
74
74
|
if (absG > absDif) {
|
|
75
75
|
dif = dG;
|
|
76
76
|
}
|
|
@@ -79,15 +79,15 @@ const Emboss = function (imageData) {
|
|
|
79
79
|
}
|
|
80
80
|
dif *= strength;
|
|
81
81
|
if (blend) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const r = data[offset] + dif;
|
|
83
|
+
const g = data[offset + 1] + dif;
|
|
84
|
+
const b = data[offset + 2] + dif;
|
|
85
85
|
data[offset] = r > 255 ? 255 : r < 0 ? 0 : r;
|
|
86
86
|
data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
|
|
87
87
|
data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
|
|
90
|
+
let grey = greyLevel - dif;
|
|
91
91
|
if (grey < 0) {
|
|
92
92
|
grey = 0;
|
|
93
93
|
}
|
package/lib/filters/Enhance.js
CHANGED
|
@@ -5,7 +5,7 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
8
|
-
|
|
8
|
+
let fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;
|
|
9
9
|
if (fromRange === 0) {
|
|
10
10
|
return toMin + toRange / 2;
|
|
11
11
|
}
|
|
@@ -17,8 +17,8 @@ function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
|
17
17
|
return toValue;
|
|
18
18
|
}
|
|
19
19
|
const Enhance = function (imageData) {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let data = imageData.data, nSubPixels = data.length, rMin = data[0], rMax = rMin, r, gMin = data[1], gMax = gMin, g, bMin = data[2], bMax = bMin, b, i;
|
|
21
|
+
const enhanceAmount = this.enhance();
|
|
22
22
|
if (enhanceAmount === 0) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
@@ -57,7 +57,7 @@ const Enhance = function (imageData) {
|
|
|
57
57
|
bMax = 255;
|
|
58
58
|
bMin = 0;
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
|
|
61
61
|
if (enhanceAmount > 0) {
|
|
62
62
|
rGoalMax = rMax + enhanceAmount * (255 - rMax);
|
|
63
63
|
rGoalMin = rMin - enhanceAmount * (rMin - 0);
|
package/lib/filters/Grayscale.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Grayscale = void 0;
|
|
4
4
|
const Grayscale = function (imageData) {
|
|
5
|
-
|
|
5
|
+
let data = imageData.data, len = data.length, i, brightness;
|
|
6
6
|
for (i = 0; i < len; i += 4) {
|
|
7
7
|
brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
|
8
8
|
data[i] = brightness;
|
package/lib/filters/HSL.js
CHANGED
|
@@ -8,12 +8,12 @@ Factory_1.Factory.addGetterSetter(Node_1.Node, 'hue', 0, (0, Validators_1.getNum
|
|
|
8
8
|
Factory_1.Factory.addGetterSetter(Node_1.Node, 'saturation', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
9
9
|
Factory_1.Factory.addGetterSetter(Node_1.Node, 'luminance', 0, (0, Validators_1.getNumberValidator)(), Factory_1.Factory.afterSetFilter);
|
|
10
10
|
const HSL = function (imageData) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let data = imageData.data, nPixels = data.length, v = 1, s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360, l = this.luminance() * 127, i;
|
|
12
|
+
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
13
|
+
const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
|
14
|
+
const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
|
15
|
+
const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
|
16
|
+
let r, g, b, a;
|
|
17
17
|
for (i = 0; i < nPixels; i += 4) {
|
|
18
18
|
r = data[i + 0];
|
|
19
19
|
g = data[i + 1];
|
package/lib/filters/HSV.js
CHANGED
|
@@ -5,13 +5,13 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const HSV = function (imageData) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
8
|
+
const data = imageData.data, nPixels = data.length, v = Math.pow(2, this.value()), s = Math.pow(2, this.saturation()), h = Math.abs(this.hue() + 360) % 360;
|
|
9
|
+
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
10
|
+
const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
|
11
|
+
const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
|
12
|
+
const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
|
13
|
+
let r, g, b, a;
|
|
14
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
15
15
|
r = data[i + 0];
|
|
16
16
|
g = data[i + 1];
|
|
17
17
|
b = data[i + 2];
|
package/lib/filters/Invert.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Invert = void 0;
|
|
4
4
|
const Invert = function (imageData) {
|
|
5
|
-
|
|
5
|
+
let data = imageData.data, len = data.length, i;
|
|
6
6
|
for (i = 0; i < len; i += 4) {
|
|
7
7
|
data[i] = 255 - data[i];
|
|
8
8
|
data[i + 1] = 255 - data[i + 1];
|
|
@@ -5,15 +5,15 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Util_1 = require("../Util");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const ToPolar = function (src, dst, opt) {
|
|
9
|
+
let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, r = 0, g = 0, b = 0, a = 0;
|
|
10
|
+
let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
11
11
|
x = xSize - xMid;
|
|
12
12
|
y = ySize - yMid;
|
|
13
13
|
rad = Math.sqrt(x * x + y * y);
|
|
14
14
|
rMax = rad > rMax ? rad : rMax;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
let rSize = ySize, tSize = xSize, radius, theta;
|
|
16
|
+
let conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
|
|
17
17
|
for (theta = 0; theta < tSize; theta += 1) {
|
|
18
18
|
sin = Math.sin(theta * conversion);
|
|
19
19
|
cos = Math.cos(theta * conversion);
|
|
@@ -33,15 +33,15 @@ var ToPolar = function (src, dst, opt) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
const FromPolar = function (src, dst, opt) {
|
|
37
|
+
let srcPixels = src.data, dstPixels = dst.data, xSize = src.width, ySize = src.height, xMid = opt.polarCenterX || xSize / 2, yMid = opt.polarCenterY || ySize / 2, i, x, y, dx, dy, r = 0, g = 0, b = 0, a = 0;
|
|
38
|
+
let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
39
39
|
x = xSize - xMid;
|
|
40
40
|
y = ySize - yMid;
|
|
41
41
|
rad = Math.sqrt(x * x + y * y);
|
|
42
42
|
rMax = rad > rMax ? rad : rMax;
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
let rSize = ySize, tSize = xSize, radius, theta, phaseShift = opt.polarRotation || 0;
|
|
44
|
+
let x1, y1;
|
|
45
45
|
for (x = 0; x < xSize; x += 1) {
|
|
46
46
|
for (y = 0; y < ySize; y += 1) {
|
|
47
47
|
dx = x - xMid;
|
|
@@ -65,18 +65,18 @@ var FromPolar = function (src, dst, opt) {
|
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
const Kaleidoscope = function (imageData) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const xSize = imageData.width, ySize = imageData.height;
|
|
69
|
+
let x, y, xoff, i, r, g, b, a, srcPos, dstPos;
|
|
70
|
+
let power = Math.round(this.kaleidoscopePower());
|
|
71
|
+
const angle = Math.round(this.kaleidoscopeAngle());
|
|
72
|
+
const offset = Math.floor((xSize * (angle % 360)) / 360);
|
|
73
73
|
if (power < 1) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
const tempCanvas = Util_1.Util.createCanvasElement();
|
|
77
77
|
tempCanvas.width = xSize;
|
|
78
78
|
tempCanvas.height = ySize;
|
|
79
|
-
|
|
79
|
+
const scratchData = tempCanvas
|
|
80
80
|
.getContext('2d')
|
|
81
81
|
.getImageData(0, 0, xSize, ySize);
|
|
82
82
|
Util_1.Util.releaseCanvas(tempCanvas);
|
|
@@ -84,14 +84,14 @@ const Kaleidoscope = function (imageData) {
|
|
|
84
84
|
polarCenterX: xSize / 2,
|
|
85
85
|
polarCenterY: ySize / 2,
|
|
86
86
|
});
|
|
87
|
-
|
|
87
|
+
let minSectionSize = xSize / Math.pow(2, power);
|
|
88
88
|
while (minSectionSize <= 8) {
|
|
89
89
|
minSectionSize = minSectionSize * 2;
|
|
90
90
|
power -= 1;
|
|
91
91
|
}
|
|
92
92
|
minSectionSize = Math.ceil(minSectionSize);
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
let sectionSize = minSectionSize;
|
|
94
|
+
let xStart = 0, xEnd = sectionSize, xDelta = 1;
|
|
95
95
|
if (offset + minSectionSize > xSize) {
|
|
96
96
|
xStart = sectionSize;
|
|
97
97
|
xEnd = 0;
|
package/lib/filters/Mask.js
CHANGED
|
@@ -5,8 +5,8 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
function pixelAt(idata, x, y) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let idx = (y * idata.width + x) * 4;
|
|
9
|
+
const d = [];
|
|
10
10
|
d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]);
|
|
11
11
|
return d;
|
|
12
12
|
}
|
|
@@ -16,8 +16,8 @@ function rgbDistance(p1, p2) {
|
|
|
16
16
|
Math.pow(p1[2] - p2[2], 2));
|
|
17
17
|
}
|
|
18
18
|
function rgbMean(pTab) {
|
|
19
|
-
|
|
20
|
-
for (
|
|
19
|
+
const m = [0, 0, 0];
|
|
20
|
+
for (let i = 0; i < pTab.length; i++) {
|
|
21
21
|
m[0] += pTab[i][0];
|
|
22
22
|
m[1] += pTab[i][1];
|
|
23
23
|
m[2] += pTab[i][2];
|
|
@@ -28,19 +28,19 @@ function rgbMean(pTab) {
|
|
|
28
28
|
return m;
|
|
29
29
|
}
|
|
30
30
|
function backgroundMask(idata, threshold) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const rgbv_no = pixelAt(idata, 0, 0);
|
|
32
|
+
const rgbv_ne = pixelAt(idata, idata.width - 1, 0);
|
|
33
|
+
const rgbv_so = pixelAt(idata, 0, idata.height - 1);
|
|
34
|
+
const rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
|
|
35
|
+
const thres = threshold || 10;
|
|
36
36
|
if (rgbDistance(rgbv_no, rgbv_ne) < thres &&
|
|
37
37
|
rgbDistance(rgbv_ne, rgbv_se) < thres &&
|
|
38
38
|
rgbDistance(rgbv_se, rgbv_so) < thres &&
|
|
39
39
|
rgbDistance(rgbv_so, rgbv_no) < thres) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (
|
|
43
|
-
|
|
40
|
+
const mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
|
|
41
|
+
const mask = [];
|
|
42
|
+
for (let i = 0; i < idata.width * idata.height; i++) {
|
|
43
|
+
const d = rgbDistance(mean, [
|
|
44
44
|
idata.data[i * 4],
|
|
45
45
|
idata.data[i * 4 + 1],
|
|
46
46
|
idata.data[i * 4 + 2],
|
|
@@ -51,26 +51,26 @@ function backgroundMask(idata, threshold) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function applyMask(idata, mask) {
|
|
54
|
-
for (
|
|
54
|
+
for (let i = 0; i < idata.width * idata.height; i++) {
|
|
55
55
|
idata.data[4 * i + 3] = mask[i];
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
function erodeMask(mask, sw, sh) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
for (
|
|
64
|
-
for (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (
|
|
68
|
-
for (
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
const weights = [1, 1, 1, 1, 0, 1, 1, 1, 1];
|
|
60
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
61
|
+
const halfSide = Math.floor(side / 2);
|
|
62
|
+
const maskResult = [];
|
|
63
|
+
for (let y = 0; y < sh; y++) {
|
|
64
|
+
for (let x = 0; x < sw; x++) {
|
|
65
|
+
const so = y * sw + x;
|
|
66
|
+
let a = 0;
|
|
67
|
+
for (let cy = 0; cy < side; cy++) {
|
|
68
|
+
for (let cx = 0; cx < side; cx++) {
|
|
69
|
+
const scy = y + cy - halfSide;
|
|
70
|
+
const scx = x + cx - halfSide;
|
|
71
71
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const srcOff = scy * sw + scx;
|
|
73
|
+
const wt = weights[cy * side + cx];
|
|
74
74
|
a += mask[srcOff] * wt;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -81,21 +81,21 @@ function erodeMask(mask, sw, sh) {
|
|
|
81
81
|
return maskResult;
|
|
82
82
|
}
|
|
83
83
|
function dilateMask(mask, sw, sh) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
for (
|
|
89
|
-
for (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (
|
|
93
|
-
for (
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
const weights = [1, 1, 1, 1, 1, 1, 1, 1, 1];
|
|
85
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
86
|
+
const halfSide = Math.floor(side / 2);
|
|
87
|
+
const maskResult = [];
|
|
88
|
+
for (let y = 0; y < sh; y++) {
|
|
89
|
+
for (let x = 0; x < sw; x++) {
|
|
90
|
+
const so = y * sw + x;
|
|
91
|
+
let a = 0;
|
|
92
|
+
for (let cy = 0; cy < side; cy++) {
|
|
93
|
+
for (let cx = 0; cx < side; cx++) {
|
|
94
|
+
const scy = y + cy - halfSide;
|
|
95
|
+
const scx = x + cx - halfSide;
|
|
96
96
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
const srcOff = scy * sw + scx;
|
|
98
|
+
const wt = weights[cy * side + cx];
|
|
99
99
|
a += mask[srcOff] * wt;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -106,21 +106,21 @@ function dilateMask(mask, sw, sh) {
|
|
|
106
106
|
return maskResult;
|
|
107
107
|
}
|
|
108
108
|
function smoothEdgeMask(mask, sw, sh) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
for (
|
|
114
|
-
for (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
for (
|
|
118
|
-
for (
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
|
|
110
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
111
|
+
const halfSide = Math.floor(side / 2);
|
|
112
|
+
const maskResult = [];
|
|
113
|
+
for (let y = 0; y < sh; y++) {
|
|
114
|
+
for (let x = 0; x < sw; x++) {
|
|
115
|
+
const so = y * sw + x;
|
|
116
|
+
let a = 0;
|
|
117
|
+
for (let cy = 0; cy < side; cy++) {
|
|
118
|
+
for (let cx = 0; cx < side; cx++) {
|
|
119
|
+
const scy = y + cy - halfSide;
|
|
120
|
+
const scx = x + cx - halfSide;
|
|
121
121
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const srcOff = scy * sw + scx;
|
|
123
|
+
const wt = weights[cy * side + cx];
|
|
124
124
|
a += mask[srcOff] * wt;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -131,7 +131,7 @@ function smoothEdgeMask(mask, sw, sh) {
|
|
|
131
131
|
return maskResult;
|
|
132
132
|
}
|
|
133
133
|
const Mask = function (imageData) {
|
|
134
|
-
|
|
134
|
+
let threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
|
|
135
135
|
if (mask) {
|
|
136
136
|
mask = erodeMask(mask, imageData.width, imageData.height);
|
|
137
137
|
mask = dilateMask(mask, imageData.width, imageData.height);
|
package/lib/filters/Noise.js
CHANGED
|
@@ -5,8 +5,8 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const Noise = function (imageData) {
|
|
8
|
-
|
|
9
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
8
|
+
const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2;
|
|
9
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
10
10
|
data[i + 0] += half - 2 * half * Math.random();
|
|
11
11
|
data[i + 1] += half - 2 * half * Math.random();
|
|
12
12
|
data[i + 2] += half - 2 * half * Math.random();
|
package/lib/filters/Pixelate.js
CHANGED
|
@@ -6,7 +6,7 @@ const Util_1 = require("../Util");
|
|
|
6
6
|
const Node_1 = require("../Node");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
8
|
const Pixelate = function (imageData) {
|
|
9
|
-
|
|
9
|
+
let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i, red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;
|
|
10
10
|
if (pixelSize <= 0) {
|
|
11
11
|
Util_1.Util.error('pixelSize value can not be <= 0');
|
|
12
12
|
return;
|
package/lib/filters/Posterize.js
CHANGED
|
@@ -5,7 +5,7 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const Posterize = function (imageData) {
|
|
8
|
-
|
|
8
|
+
let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
|
|
9
9
|
for (i = 0; i < len; i += 1) {
|
|
10
10
|
data[i] = Math.floor(data[i] / scale) * scale;
|
|
11
11
|
}
|
package/lib/filters/RGB.js
CHANGED
|
@@ -5,7 +5,7 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const RGB = function (imageData) {
|
|
8
|
-
|
|
8
|
+
let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
|
|
9
9
|
for (i = 0; i < nPixels; i += 4) {
|
|
10
10
|
brightness =
|
|
11
11
|
(0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
package/lib/filters/RGBA.js
CHANGED
|
@@ -5,9 +5,9 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const RGBA = function (imageData) {
|
|
8
|
-
|
|
9
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
10
|
-
ia = 1 - alpha;
|
|
8
|
+
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha();
|
|
9
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
10
|
+
const ia = 1 - alpha;
|
|
11
11
|
data[i] = red * alpha + data[i] * ia;
|
|
12
12
|
data[i + 1] = green * alpha + data[i + 1] * ia;
|
|
13
13
|
data[i + 2] = blue * alpha + data[i + 2] * ia;
|
package/lib/filters/Sepia.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Sepia = void 0;
|
|
4
4
|
const Sepia = function (imageData) {
|
|
5
|
-
|
|
5
|
+
let data = imageData.data, nPixels = data.length, i, r, g, b;
|
|
6
6
|
for (i = 0; i < nPixels; i += 4) {
|
|
7
7
|
r = data[i + 0];
|
|
8
8
|
g = data[i + 1];
|
package/lib/filters/Solarize.js
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Solarize = void 0;
|
|
4
4
|
const Solarize = function (imageData) {
|
|
5
|
-
|
|
5
|
+
const data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
|
|
6
|
+
let y = h;
|
|
6
7
|
do {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const offsetY = (y - 1) * w4;
|
|
9
|
+
let x = w;
|
|
9
10
|
do {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const offset = offsetY + (x - 1) * 4;
|
|
12
|
+
let r = data[offset];
|
|
13
|
+
let g = data[offset + 1];
|
|
14
|
+
let b = data[offset + 2];
|
|
14
15
|
if (r > 127) {
|
|
15
16
|
r = 255 - r;
|
|
16
17
|
}
|
package/lib/filters/Threshold.js
CHANGED
|
@@ -5,8 +5,8 @@ const Factory_1 = require("../Factory");
|
|
|
5
5
|
const Node_1 = require("../Node");
|
|
6
6
|
const Validators_1 = require("../Validators");
|
|
7
7
|
const Threshold = function (imageData) {
|
|
8
|
-
|
|
9
|
-
for (i = 0; i < len; i += 1) {
|
|
8
|
+
const level = this.threshold() * 255, data = imageData.data, len = data.length;
|
|
9
|
+
for (let i = 0; i < len; i += 1) {
|
|
10
10
|
data[i] = data[i] < level ? 0 : 255;
|
|
11
11
|
}
|
|
12
12
|
};
|
package/lib/shapes/Arc.js
CHANGED
|
@@ -8,7 +8,7 @@ const Validators_1 = require("../Validators");
|
|
|
8
8
|
const Global_2 = require("../Global");
|
|
9
9
|
class Arc extends Shape_1.Shape {
|
|
10
10
|
_sceneFunc(context) {
|
|
11
|
-
|
|
11
|
+
const angle = Global_1.Konva.getAngle(this.angle()), clockwise = this.clockwise();
|
|
12
12
|
context.beginPath();
|
|
13
13
|
context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
|
14
14
|
context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
package/lib/shapes/Arrow.js
CHANGED
|
@@ -9,16 +9,16 @@ const Path_1 = require("./Path");
|
|
|
9
9
|
class Arrow extends Line_1.Line {
|
|
10
10
|
_sceneFunc(ctx) {
|
|
11
11
|
super._sceneFunc(ctx);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const PI2 = Math.PI * 2;
|
|
13
|
+
const points = this.points();
|
|
14
|
+
let tp = points;
|
|
15
|
+
const fromTension = this.tension() !== 0 && points.length > 4;
|
|
16
16
|
if (fromTension) {
|
|
17
17
|
tp = this.getTensionPoints();
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const length = this.pointerLength();
|
|
20
|
+
const n = points.length;
|
|
21
|
+
let dx, dy;
|
|
22
22
|
if (fromTension) {
|
|
23
23
|
const lp = [
|
|
24
24
|
tp[tp.length - 4],
|
|
@@ -37,8 +37,8 @@ class Arrow extends Line_1.Line {
|
|
|
37
37
|
dx = points[n - 2] - points[n - 4];
|
|
38
38
|
dy = points[n - 1] - points[n - 3];
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
const radians = (Math.atan2(dy, dx) + PI2) % PI2;
|
|
41
|
+
const width = this.pointerWidth();
|
|
42
42
|
if (this.pointerAtEnding()) {
|
|
43
43
|
ctx.save();
|
|
44
44
|
ctx.beginPath();
|
|
@@ -73,7 +73,7 @@ class Arrow extends Line_1.Line {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
__fillStroke(ctx) {
|
|
76
|
-
|
|
76
|
+
const isDashEnabled = this.dashEnabled();
|
|
77
77
|
if (isDashEnabled) {
|
|
78
78
|
this.attrs.dashEnabled = false;
|
|
79
79
|
ctx.setLineDash([]);
|
package/lib/shapes/Ellipse.js
CHANGED
|
@@ -7,7 +7,7 @@ const Validators_1 = require("../Validators");
|
|
|
7
7
|
const Global_1 = require("../Global");
|
|
8
8
|
class Ellipse extends Shape_1.Shape {
|
|
9
9
|
_sceneFunc(context) {
|
|
10
|
-
|
|
10
|
+
const rx = this.radiusX(), ry = this.radiusY();
|
|
11
11
|
context.beginPath();
|
|
12
12
|
context.save();
|
|
13
13
|
if (rx !== ry) {
|
package/lib/shapes/Image.js
CHANGED
|
@@ -78,7 +78,7 @@ class Image extends Shape_1.Shape {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
_hitFunc(context) {
|
|
81
|
-
|
|
81
|
+
const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
82
82
|
context.beginPath();
|
|
83
83
|
if (!cornerRadius) {
|
|
84
84
|
context.rect(0, 0, width, height);
|
|
@@ -98,9 +98,9 @@ class Image extends Shape_1.Shape {
|
|
|
98
98
|
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
99
99
|
}
|
|
100
100
|
static fromURL(url, callback, onError = null) {
|
|
101
|
-
|
|
101
|
+
const img = Util_1.Util.createImageElement();
|
|
102
102
|
img.onload = function () {
|
|
103
|
-
|
|
103
|
+
const image = new Image({
|
|
104
104
|
image: img,
|
|
105
105
|
});
|
|
106
106
|
callback(image);
|
package/lib/shapes/Label.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare class Tag extends Shape<TagConfig> {
|
|
|
29
29
|
width: number;
|
|
30
30
|
height: number;
|
|
31
31
|
};
|
|
32
|
-
pointerDirection: GetSet<'left' | 'top' | 'right' | 'bottom', this>;
|
|
32
|
+
pointerDirection: GetSet<'left' | 'top' | 'right' | 'bottom' | 'up' | 'down', this>;
|
|
33
33
|
pointerWidth: GetSet<number, this>;
|
|
34
34
|
pointerHeight: GetSet<number, this>;
|
|
35
35
|
cornerRadius: GetSet<number, this>;
|