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/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v9.3.
|
|
8
|
+
* Konva JavaScript Framework v9.3.16
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Mon Oct 21 2024
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '9.3.
|
|
38
|
+
version: '9.3.16',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -249,7 +249,7 @@
|
|
|
249
249
|
* @returns {Object} 2D point(x, y)
|
|
250
250
|
*/
|
|
251
251
|
point(point) {
|
|
252
|
-
|
|
252
|
+
const m = this.m;
|
|
253
253
|
return {
|
|
254
254
|
x: m[0] * point.x + m[2] * point.y + m[4],
|
|
255
255
|
y: m[1] * point.x + m[3] * point.y + m[5],
|
|
@@ -291,12 +291,12 @@
|
|
|
291
291
|
* @returns {Konva.Transform}
|
|
292
292
|
*/
|
|
293
293
|
rotate(rad) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
294
|
+
const c = Math.cos(rad);
|
|
295
|
+
const s = Math.sin(rad);
|
|
296
|
+
const m11 = this.m[0] * c + this.m[2] * s;
|
|
297
|
+
const m12 = this.m[1] * c + this.m[3] * s;
|
|
298
|
+
const m21 = this.m[0] * -s + this.m[2] * c;
|
|
299
|
+
const m22 = this.m[1] * -s + this.m[3] * c;
|
|
300
300
|
this.m[0] = m11;
|
|
301
301
|
this.m[1] = m12;
|
|
302
302
|
this.m[2] = m21;
|
|
@@ -324,10 +324,10 @@
|
|
|
324
324
|
* @returns {Konva.Transform}
|
|
325
325
|
*/
|
|
326
326
|
skew(sx, sy) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
327
|
+
const m11 = this.m[0] + this.m[2] * sy;
|
|
328
|
+
const m12 = this.m[1] + this.m[3] * sy;
|
|
329
|
+
const m21 = this.m[2] + this.m[0] * sx;
|
|
330
|
+
const m22 = this.m[3] + this.m[1] * sx;
|
|
331
331
|
this.m[0] = m11;
|
|
332
332
|
this.m[1] = m12;
|
|
333
333
|
this.m[2] = m21;
|
|
@@ -342,12 +342,12 @@
|
|
|
342
342
|
* @returns {Konva.Transform}
|
|
343
343
|
*/
|
|
344
344
|
multiply(matrix) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
345
|
+
const m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
|
|
346
|
+
const m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
|
|
347
|
+
const m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
|
|
348
|
+
const m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
|
|
349
|
+
const dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
|
|
350
|
+
const dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
|
|
351
351
|
this.m[0] = m11;
|
|
352
352
|
this.m[1] = m12;
|
|
353
353
|
this.m[2] = m21;
|
|
@@ -363,13 +363,13 @@
|
|
|
363
363
|
* @returns {Konva.Transform}
|
|
364
364
|
*/
|
|
365
365
|
invert() {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
366
|
+
const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
|
|
367
|
+
const m0 = this.m[3] * d;
|
|
368
|
+
const m1 = -this.m[1] * d;
|
|
369
|
+
const m2 = -this.m[2] * d;
|
|
370
|
+
const m3 = this.m[0] * d;
|
|
371
|
+
const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
|
|
372
|
+
const m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
|
|
373
373
|
this.m[0] = m0;
|
|
374
374
|
this.m[1] = m1;
|
|
375
375
|
this.m[2] = m2;
|
|
@@ -393,14 +393,14 @@
|
|
|
393
393
|
* @returns {Konva.Transform}
|
|
394
394
|
*/
|
|
395
395
|
decompose() {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
396
|
+
const a = this.m[0];
|
|
397
|
+
const b = this.m[1];
|
|
398
|
+
const c = this.m[2];
|
|
399
|
+
const d = this.m[3];
|
|
400
|
+
const e = this.m[4];
|
|
401
|
+
const f = this.m[5];
|
|
402
|
+
const delta = a * d - b * c;
|
|
403
|
+
const result = {
|
|
404
404
|
x: e,
|
|
405
405
|
y: f,
|
|
406
406
|
rotation: 0,
|
|
@@ -411,7 +411,7 @@
|
|
|
411
411
|
};
|
|
412
412
|
// Apply the QR-like decomposition.
|
|
413
413
|
if (a != 0 || b != 0) {
|
|
414
|
-
|
|
414
|
+
const r = Math.sqrt(a * a + b * b);
|
|
415
415
|
result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
|
|
416
416
|
result.scaleX = r;
|
|
417
417
|
result.scaleY = delta / r;
|
|
@@ -419,7 +419,7 @@
|
|
|
419
419
|
result.skewY = 0;
|
|
420
420
|
}
|
|
421
421
|
else if (c != 0 || d != 0) {
|
|
422
|
-
|
|
422
|
+
const s = Math.sqrt(c * c + d * d);
|
|
423
423
|
result.rotation =
|
|
424
424
|
Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
|
|
425
425
|
result.scaleX = delta / s;
|
|
@@ -433,7 +433,7 @@
|
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
// CONSTANTS
|
|
436
|
-
|
|
436
|
+
let OBJECT_ARRAY = '[object Array]', OBJECT_NUMBER = '[object Number]', OBJECT_STRING = '[object String]', OBJECT_BOOLEAN = '[object Boolean]', PI_OVER_DEG180 = Math.PI / 180, DEG180_OVER_PI = 180 / Math.PI, HASH$1 = '#', EMPTY_STRING$1 = '', ZERO = '0', KONVA_WARNING = 'Konva warning: ', KONVA_ERROR = 'Konva error: ', RGB_PAREN = 'rgb(', COLORS = {
|
|
437
437
|
aliceblue: [240, 248, 255],
|
|
438
438
|
antiquewhite: [250, 235, 215],
|
|
439
439
|
aqua: [0, 255, 255],
|
|
@@ -627,7 +627,7 @@
|
|
|
627
627
|
if (typeof selector !== 'string') {
|
|
628
628
|
return false;
|
|
629
629
|
}
|
|
630
|
-
|
|
630
|
+
const firstChar = selector[0];
|
|
631
631
|
return (firstChar === '#' ||
|
|
632
632
|
firstChar === '.' ||
|
|
633
633
|
firstChar === firstChar.toUpperCase());
|
|
@@ -658,7 +658,7 @@
|
|
|
658
658
|
}
|
|
659
659
|
},
|
|
660
660
|
createCanvasElement() {
|
|
661
|
-
|
|
661
|
+
const canvas = document.createElement('canvas');
|
|
662
662
|
// on some environments canvas.style is readonly
|
|
663
663
|
try {
|
|
664
664
|
canvas.style = canvas.style || {};
|
|
@@ -682,7 +682,7 @@
|
|
|
682
682
|
*/
|
|
683
683
|
_urlToImage(url, callback) {
|
|
684
684
|
// if arg is a string, then it's a data url
|
|
685
|
-
|
|
685
|
+
const imageObj = Util.createImageElement();
|
|
686
686
|
imageObj.onload = function () {
|
|
687
687
|
callback(imageObj);
|
|
688
688
|
};
|
|
@@ -693,7 +693,7 @@
|
|
|
693
693
|
},
|
|
694
694
|
_hexToRgb(hex) {
|
|
695
695
|
hex = hex.replace(HASH$1, EMPTY_STRING$1);
|
|
696
|
-
|
|
696
|
+
const bigint = parseInt(hex, 16);
|
|
697
697
|
return {
|
|
698
698
|
r: (bigint >> 16) & 255,
|
|
699
699
|
g: (bigint >> 8) & 255,
|
|
@@ -708,7 +708,7 @@
|
|
|
708
708
|
* shape.fill(Konva.Util.getRandomColor());
|
|
709
709
|
*/
|
|
710
710
|
getRandomColor() {
|
|
711
|
-
|
|
711
|
+
let randColor = ((Math.random() * 0xffffff) << 0).toString(16);
|
|
712
712
|
while (randColor.length < 6) {
|
|
713
713
|
randColor = ZERO + randColor;
|
|
714
714
|
}
|
|
@@ -726,7 +726,7 @@
|
|
|
726
726
|
* var rgb = Konva.Util.getRGB('rgb(0,0,255)');
|
|
727
727
|
*/
|
|
728
728
|
getRGB(color) {
|
|
729
|
-
|
|
729
|
+
let rgb;
|
|
730
730
|
// color string
|
|
731
731
|
if (color in COLORS) {
|
|
732
732
|
rgb = COLORS[color];
|
|
@@ -773,7 +773,7 @@
|
|
|
773
773
|
},
|
|
774
774
|
// Parse named css color. Like "green"
|
|
775
775
|
_namedColorToRBA(str) {
|
|
776
|
-
|
|
776
|
+
const c = COLORS[str.toLowerCase()];
|
|
777
777
|
if (!c) {
|
|
778
778
|
return null;
|
|
779
779
|
}
|
|
@@ -788,7 +788,7 @@
|
|
|
788
788
|
_rgbColorToRGBA(str) {
|
|
789
789
|
if (str.indexOf('rgb(') === 0) {
|
|
790
790
|
str = str.match(/rgb\(([^)]+)\)/)[1];
|
|
791
|
-
|
|
791
|
+
const parts = str.split(/ *, */).map(Number);
|
|
792
792
|
return {
|
|
793
793
|
r: parts[0],
|
|
794
794
|
g: parts[1],
|
|
@@ -801,7 +801,7 @@
|
|
|
801
801
|
_rgbaColorToRGBA(str) {
|
|
802
802
|
if (str.indexOf('rgba(') === 0) {
|
|
803
803
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
804
|
-
|
|
804
|
+
const parts = str.split(/ *, */).map((n, index) => {
|
|
805
805
|
if (n.slice(-1) === '%') {
|
|
806
806
|
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
807
807
|
}
|
|
@@ -934,8 +934,8 @@
|
|
|
934
934
|
r2.y + r2.height < r1.y);
|
|
935
935
|
},
|
|
936
936
|
cloneObject(obj) {
|
|
937
|
-
|
|
938
|
-
for (
|
|
937
|
+
const retObj = {};
|
|
938
|
+
for (const key in obj) {
|
|
939
939
|
if (this._isPlainObject(obj[key])) {
|
|
940
940
|
retObj[key] = this.cloneObject(obj[key]);
|
|
941
941
|
}
|
|
@@ -984,7 +984,7 @@
|
|
|
984
984
|
console.warn(KONVA_WARNING + str);
|
|
985
985
|
},
|
|
986
986
|
each(obj, func) {
|
|
987
|
-
for (
|
|
987
|
+
for (const key in obj) {
|
|
988
988
|
func(key, obj[key]);
|
|
989
989
|
}
|
|
990
990
|
},
|
|
@@ -992,15 +992,15 @@
|
|
|
992
992
|
return left <= val && val < right;
|
|
993
993
|
},
|
|
994
994
|
_getProjectionToSegment(x1, y1, x2, y2, x3, y3) {
|
|
995
|
-
|
|
996
|
-
|
|
995
|
+
let x, y, dist;
|
|
996
|
+
const pd2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
|
997
997
|
if (pd2 == 0) {
|
|
998
998
|
x = x1;
|
|
999
999
|
y = y1;
|
|
1000
1000
|
dist = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
|
|
1001
1001
|
}
|
|
1002
1002
|
else {
|
|
1003
|
-
|
|
1003
|
+
const u = ((x3 - x1) * (x2 - x1) + (y3 - y1) * (y2 - y1)) / pd2;
|
|
1004
1004
|
if (u < 0) {
|
|
1005
1005
|
x = x1;
|
|
1006
1006
|
y = y1;
|
|
@@ -1022,15 +1022,15 @@
|
|
|
1022
1022
|
// line as array of points.
|
|
1023
1023
|
// line might be closed
|
|
1024
1024
|
_getProjectionToLine(pt, line, isClosed) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1025
|
+
const pc = Util.cloneObject(pt);
|
|
1026
|
+
let dist = Number.MAX_VALUE;
|
|
1027
1027
|
line.forEach(function (p1, i) {
|
|
1028
1028
|
if (!isClosed && i === line.length - 1) {
|
|
1029
1029
|
return;
|
|
1030
1030
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1031
|
+
const p2 = line[(i + 1) % line.length];
|
|
1032
|
+
const proj = Util._getProjectionToSegment(p1.x, p1.y, p2.x, p2.y, pt.x, pt.y);
|
|
1033
|
+
const px = proj[0], py = proj[1], pdist = proj[2];
|
|
1034
1034
|
if (pdist < dist) {
|
|
1035
1035
|
pc.x = px;
|
|
1036
1036
|
pc.y = py;
|
|
@@ -1040,9 +1040,9 @@
|
|
|
1040
1040
|
return pc;
|
|
1041
1041
|
},
|
|
1042
1042
|
_prepareArrayForTween(startArray, endArray, isClosed) {
|
|
1043
|
-
|
|
1043
|
+
let n, start = [], end = [];
|
|
1044
1044
|
if (startArray.length > endArray.length) {
|
|
1045
|
-
|
|
1045
|
+
const temp = endArray;
|
|
1046
1046
|
endArray = startArray;
|
|
1047
1047
|
startArray = temp;
|
|
1048
1048
|
}
|
|
@@ -1058,18 +1058,18 @@
|
|
|
1058
1058
|
y: endArray[n + 1],
|
|
1059
1059
|
});
|
|
1060
1060
|
}
|
|
1061
|
-
|
|
1061
|
+
const newStart = [];
|
|
1062
1062
|
end.forEach(function (point) {
|
|
1063
|
-
|
|
1063
|
+
const pr = Util._getProjectionToLine(point, start, isClosed);
|
|
1064
1064
|
newStart.push(pr.x);
|
|
1065
1065
|
newStart.push(pr.y);
|
|
1066
1066
|
});
|
|
1067
1067
|
return newStart;
|
|
1068
1068
|
},
|
|
1069
1069
|
_prepareToStringify(obj) {
|
|
1070
|
-
|
|
1070
|
+
let desc;
|
|
1071
1071
|
obj.visitedByCircularReferenceRemoval = true;
|
|
1072
|
-
for (
|
|
1072
|
+
for (const key in obj) {
|
|
1073
1073
|
if (!(obj.hasOwnProperty(key) && obj[key] && typeof obj[key] == 'object')) {
|
|
1074
1074
|
continue;
|
|
1075
1075
|
}
|
|
@@ -1097,7 +1097,7 @@
|
|
|
1097
1097
|
},
|
|
1098
1098
|
// very simplified version of Object.assign
|
|
1099
1099
|
_assign(target, source) {
|
|
1100
|
-
for (
|
|
1100
|
+
for (const key in source) {
|
|
1101
1101
|
target[key] = source[key];
|
|
1102
1102
|
}
|
|
1103
1103
|
return target;
|
|
@@ -1186,8 +1186,8 @@
|
|
|
1186
1186
|
function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
1187
1187
|
if (Konva$2.isUnminified) {
|
|
1188
1188
|
return function (val, attr) {
|
|
1189
|
-
|
|
1190
|
-
|
|
1189
|
+
const isNumber = Util._isNumber(val);
|
|
1190
|
+
const isValidArray = Util._isArray(val) && val.length == noOfElements;
|
|
1191
1191
|
if (!isNumber && !isValidArray) {
|
|
1192
1192
|
Util.warn(_formatValue(val) +
|
|
1193
1193
|
' is a not valid value for "' +
|
|
@@ -1203,8 +1203,8 @@
|
|
|
1203
1203
|
function getNumberOrAutoValidator() {
|
|
1204
1204
|
if (Konva$2.isUnminified) {
|
|
1205
1205
|
return function (val, attr) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1206
|
+
const isNumber = Util._isNumber(val);
|
|
1207
|
+
const isAuto = val === 'auto';
|
|
1208
1208
|
if (!(isNumber || isAuto)) {
|
|
1209
1209
|
Util.warn(_formatValue(val) +
|
|
1210
1210
|
' is a not valid value for "' +
|
|
@@ -1277,7 +1277,7 @@
|
|
|
1277
1277
|
function getBooleanValidator() {
|
|
1278
1278
|
if (Konva$2.isUnminified) {
|
|
1279
1279
|
return function (val, attr) {
|
|
1280
|
-
|
|
1280
|
+
const isBool = val === true || val === false;
|
|
1281
1281
|
if (!isBool) {
|
|
1282
1282
|
Util.warn(_formatValue(val) +
|
|
1283
1283
|
' is a not valid value for "' +
|
|
@@ -1307,7 +1307,7 @@
|
|
|
1307
1307
|
}
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
|
-
|
|
1310
|
+
const GET = 'get', SET$1 = 'set';
|
|
1311
1311
|
const Factory = {
|
|
1312
1312
|
addGetterSetter(constructor, attr, def, validator, after) {
|
|
1313
1313
|
Factory.addGetter(constructor, attr, def);
|
|
@@ -1315,22 +1315,22 @@
|
|
|
1315
1315
|
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
1316
1316
|
},
|
|
1317
1317
|
addGetter(constructor, attr, def) {
|
|
1318
|
-
|
|
1318
|
+
const method = GET + Util._capitalize(attr);
|
|
1319
1319
|
constructor.prototype[method] =
|
|
1320
1320
|
constructor.prototype[method] ||
|
|
1321
1321
|
function () {
|
|
1322
|
-
|
|
1322
|
+
const val = this.attrs[attr];
|
|
1323
1323
|
return val === undefined ? def : val;
|
|
1324
1324
|
};
|
|
1325
1325
|
},
|
|
1326
1326
|
addSetter(constructor, attr, validator, after) {
|
|
1327
|
-
|
|
1327
|
+
const method = SET$1 + Util._capitalize(attr);
|
|
1328
1328
|
if (!constructor.prototype[method]) {
|
|
1329
1329
|
Factory.overWriteSetter(constructor, attr, validator, after);
|
|
1330
1330
|
}
|
|
1331
1331
|
},
|
|
1332
1332
|
overWriteSetter(constructor, attr, validator, after) {
|
|
1333
|
-
|
|
1333
|
+
const method = SET$1 + Util._capitalize(attr);
|
|
1334
1334
|
constructor.prototype[method] = function (val) {
|
|
1335
1335
|
if (validator && val !== undefined && val !== null) {
|
|
1336
1336
|
val = validator.call(this, val, attr);
|
|
@@ -1343,20 +1343,20 @@
|
|
|
1343
1343
|
};
|
|
1344
1344
|
},
|
|
1345
1345
|
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
|
1346
|
-
|
|
1346
|
+
let len = components.length, capitalize = Util._capitalize, getter = GET + capitalize(attr), setter = SET$1 + capitalize(attr), n, component;
|
|
1347
1347
|
// getter
|
|
1348
1348
|
constructor.prototype[getter] = function () {
|
|
1349
|
-
|
|
1349
|
+
const ret = {};
|
|
1350
1350
|
for (n = 0; n < len; n++) {
|
|
1351
1351
|
component = components[n];
|
|
1352
1352
|
ret[component] = this.getAttr(attr + capitalize(component));
|
|
1353
1353
|
}
|
|
1354
1354
|
return ret;
|
|
1355
1355
|
};
|
|
1356
|
-
|
|
1356
|
+
const basicValidator = getComponentValidator(components);
|
|
1357
1357
|
// setter
|
|
1358
1358
|
constructor.prototype[setter] = function (val) {
|
|
1359
|
-
|
|
1359
|
+
let oldVal = this.attrs[attr], key;
|
|
1360
1360
|
if (validator) {
|
|
1361
1361
|
val = validator.call(this, val);
|
|
1362
1362
|
}
|
|
@@ -1383,7 +1383,7 @@
|
|
|
1383
1383
|
Factory.addOverloadedGetterSetter(constructor, attr);
|
|
1384
1384
|
},
|
|
1385
1385
|
addOverloadedGetterSetter(constructor, attr) {
|
|
1386
|
-
|
|
1386
|
+
const capitalizedAttr = Util._capitalize(attr), setter = SET$1 + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
1387
1387
|
constructor.prototype[attr] = function () {
|
|
1388
1388
|
// setting
|
|
1389
1389
|
if (arguments.length) {
|
|
@@ -1396,12 +1396,12 @@
|
|
|
1396
1396
|
},
|
|
1397
1397
|
addDeprecatedGetterSetter(constructor, attr, def, validator) {
|
|
1398
1398
|
Util.error('Adding deprecated ' + attr);
|
|
1399
|
-
|
|
1400
|
-
|
|
1399
|
+
const method = GET + Util._capitalize(attr);
|
|
1400
|
+
const message = attr +
|
|
1401
1401
|
' property is deprecated and will be removed soon. Look at Konva change log for more information.';
|
|
1402
1402
|
constructor.prototype[method] = function () {
|
|
1403
1403
|
Util.error(message);
|
|
1404
|
-
|
|
1404
|
+
const val = this.attrs[attr];
|
|
1405
1405
|
return val === undefined ? def : val;
|
|
1406
1406
|
};
|
|
1407
1407
|
Factory.addSetter(constructor, attr, validator, function () {
|
|
@@ -1411,9 +1411,9 @@
|
|
|
1411
1411
|
},
|
|
1412
1412
|
backCompat(constructor, methods) {
|
|
1413
1413
|
Util.each(methods, function (oldMethodName, newMethodName) {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1414
|
+
const method = constructor.prototype[newMethodName];
|
|
1415
|
+
const oldGetter = GET + Util._capitalize(oldMethodName);
|
|
1416
|
+
const oldSetter = SET$1 + Util._capitalize(oldMethodName);
|
|
1417
1417
|
function deprecated() {
|
|
1418
1418
|
method.apply(this, arguments);
|
|
1419
1419
|
Util.error('"' +
|
|
@@ -1433,7 +1433,7 @@
|
|
|
1433
1433
|
};
|
|
1434
1434
|
|
|
1435
1435
|
function simplifyArray(arr) {
|
|
1436
|
-
|
|
1436
|
+
let retArr = [], len = arr.length, util = Util, n, val;
|
|
1437
1437
|
for (n = 0; n < len; n++) {
|
|
1438
1438
|
val = arr[n];
|
|
1439
1439
|
if (util._isNumber(val)) {
|
|
@@ -1446,7 +1446,7 @@
|
|
|
1446
1446
|
}
|
|
1447
1447
|
return retArr;
|
|
1448
1448
|
}
|
|
1449
|
-
|
|
1449
|
+
const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()',
|
|
1450
1450
|
// EMPTY_STRING = '',
|
|
1451
1451
|
EQUALS = '=',
|
|
1452
1452
|
// SET = 'set',
|
|
@@ -1484,7 +1484,7 @@
|
|
|
1484
1484
|
'transform',
|
|
1485
1485
|
'translate',
|
|
1486
1486
|
];
|
|
1487
|
-
|
|
1487
|
+
const CONTEXT_PROPERTIES = [
|
|
1488
1488
|
'fillStyle',
|
|
1489
1489
|
'strokeStyle',
|
|
1490
1490
|
'shadowColor',
|
|
@@ -1581,7 +1581,7 @@
|
|
|
1581
1581
|
}
|
|
1582
1582
|
}
|
|
1583
1583
|
getTrace(relaxed, rounded) {
|
|
1584
|
-
|
|
1584
|
+
let traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
|
|
1585
1585
|
for (n = 0; n < len; n++) {
|
|
1586
1586
|
trace = traceArr[n];
|
|
1587
1587
|
method = trace.method;
|
|
@@ -1619,7 +1619,7 @@
|
|
|
1619
1619
|
this.traceArr = [];
|
|
1620
1620
|
}
|
|
1621
1621
|
_trace(str) {
|
|
1622
|
-
|
|
1622
|
+
let traceArr = this.traceArr, len;
|
|
1623
1623
|
traceArr.push(str);
|
|
1624
1624
|
len = traceArr.length;
|
|
1625
1625
|
if (len >= traceArrMax) {
|
|
@@ -1632,7 +1632,7 @@
|
|
|
1632
1632
|
* @name Konva.Context#reset
|
|
1633
1633
|
*/
|
|
1634
1634
|
reset() {
|
|
1635
|
-
|
|
1635
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
1636
1636
|
this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
|
1637
1637
|
}
|
|
1638
1638
|
/**
|
|
@@ -1655,7 +1655,7 @@
|
|
|
1655
1655
|
* @param {Number} [bounds.height]
|
|
1656
1656
|
*/
|
|
1657
1657
|
clear(bounds) {
|
|
1658
|
-
|
|
1658
|
+
const canvas = this.getCanvas();
|
|
1659
1659
|
if (bounds) {
|
|
1660
1660
|
this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
|
1661
1661
|
}
|
|
@@ -1670,7 +1670,7 @@
|
|
|
1670
1670
|
}
|
|
1671
1671
|
}
|
|
1672
1672
|
_applyOpacity(shape) {
|
|
1673
|
-
|
|
1673
|
+
const absOpacity = shape.getAbsoluteOpacity();
|
|
1674
1674
|
if (absOpacity !== 1) {
|
|
1675
1675
|
this.setAttr('globalAlpha', absOpacity);
|
|
1676
1676
|
}
|
|
@@ -1742,7 +1742,7 @@
|
|
|
1742
1742
|
* @name Konva.Context#createImageData
|
|
1743
1743
|
*/
|
|
1744
1744
|
createImageData(width, height) {
|
|
1745
|
-
|
|
1745
|
+
const a = arguments;
|
|
1746
1746
|
if (a.length === 2) {
|
|
1747
1747
|
return this._context.createImageData(width, height);
|
|
1748
1748
|
}
|
|
@@ -1781,7 +1781,7 @@
|
|
|
1781
1781
|
*/
|
|
1782
1782
|
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
|
1783
1783
|
// this._context.drawImage(...arguments);
|
|
1784
|
-
|
|
1784
|
+
const a = arguments, _context = this._context;
|
|
1785
1785
|
if (a.length === 3) {
|
|
1786
1786
|
_context.drawImage(image, sx, sy);
|
|
1787
1787
|
}
|
|
@@ -2014,10 +2014,10 @@
|
|
|
2014
2014
|
this._context.translate(x, y);
|
|
2015
2015
|
}
|
|
2016
2016
|
_enableTrace() {
|
|
2017
|
-
|
|
2017
|
+
let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
|
2018
2018
|
// to prevent creating scope function at each loop
|
|
2019
|
-
|
|
2020
|
-
|
|
2019
|
+
const func = function (methodName) {
|
|
2020
|
+
let origMethod = that[methodName], ret;
|
|
2021
2021
|
that[methodName] = function () {
|
|
2022
2022
|
args = simplifyArray(Array.prototype.slice.call(arguments, 0));
|
|
2023
2023
|
ret = origMethod.apply(that, arguments);
|
|
@@ -2035,8 +2035,8 @@
|
|
|
2035
2035
|
// attrs
|
|
2036
2036
|
that.setAttr = function () {
|
|
2037
2037
|
origSetter.apply(that, arguments);
|
|
2038
|
-
|
|
2039
|
-
|
|
2038
|
+
const prop = arguments[0];
|
|
2039
|
+
let val = arguments[1];
|
|
2040
2040
|
if (prop === 'shadowOffsetX' ||
|
|
2041
2041
|
prop === 'shadowOffsetY' ||
|
|
2042
2042
|
prop === 'shadowBlur') {
|
|
@@ -2050,7 +2050,7 @@
|
|
|
2050
2050
|
}
|
|
2051
2051
|
_applyGlobalCompositeOperation(node) {
|
|
2052
2052
|
const op = node.attrs.globalCompositeOperation;
|
|
2053
|
-
|
|
2053
|
+
const def = !op || op === 'source-over';
|
|
2054
2054
|
if (!def) {
|
|
2055
2055
|
this.setAttr('globalCompositeOperation', op);
|
|
2056
2056
|
}
|
|
@@ -2074,7 +2074,7 @@
|
|
|
2074
2074
|
});
|
|
2075
2075
|
}
|
|
2076
2076
|
_fillColor(shape) {
|
|
2077
|
-
|
|
2077
|
+
const fill = shape.fill();
|
|
2078
2078
|
this.setAttr('fillStyle', fill);
|
|
2079
2079
|
shape._fillFunc(this);
|
|
2080
2080
|
}
|
|
@@ -2083,7 +2083,7 @@
|
|
|
2083
2083
|
shape._fillFunc(this);
|
|
2084
2084
|
}
|
|
2085
2085
|
_fillLinearGradient(shape) {
|
|
2086
|
-
|
|
2086
|
+
const grd = shape._getLinearGradient();
|
|
2087
2087
|
if (grd) {
|
|
2088
2088
|
this.setAttr('fillStyle', grd);
|
|
2089
2089
|
shape._fillFunc(this);
|
|
@@ -2136,20 +2136,20 @@
|
|
|
2136
2136
|
const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
2137
2137
|
if (colorStops) {
|
|
2138
2138
|
// build color stops
|
|
2139
|
-
for (
|
|
2139
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
2140
2140
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
2141
2141
|
}
|
|
2142
2142
|
this.setAttr('strokeStyle', grd);
|
|
2143
2143
|
}
|
|
2144
2144
|
}
|
|
2145
2145
|
_stroke(shape) {
|
|
2146
|
-
|
|
2146
|
+
const dash = shape.dash(),
|
|
2147
2147
|
// ignore strokeScaleEnabled for Text
|
|
2148
2148
|
strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
2149
2149
|
if (shape.hasStroke()) {
|
|
2150
2150
|
if (!strokeScaleEnabled) {
|
|
2151
2151
|
this.save();
|
|
2152
|
-
|
|
2152
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
2153
2153
|
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
2154
2154
|
}
|
|
2155
2155
|
this._applyLineCap(shape);
|
|
@@ -2161,7 +2161,7 @@
|
|
|
2161
2161
|
if (!shape.getShadowForStrokeEnabled()) {
|
|
2162
2162
|
this.setAttr('shadowColor', 'rgba(0,0,0,0)');
|
|
2163
2163
|
}
|
|
2164
|
-
|
|
2164
|
+
const hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
|
2165
2165
|
if (hasLinearGradient) {
|
|
2166
2166
|
this._strokeLinearGradient(shape);
|
|
2167
2167
|
}
|
|
@@ -2176,7 +2176,7 @@
|
|
|
2176
2176
|
}
|
|
2177
2177
|
_applyShadow(shape) {
|
|
2178
2178
|
var _a, _b, _c;
|
|
2179
|
-
|
|
2179
|
+
const color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
|
|
2180
2180
|
x: 0,
|
|
2181
2181
|
y: 0,
|
|
2182
2182
|
}, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
|
@@ -2210,12 +2210,12 @@
|
|
|
2210
2210
|
const strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
2211
2211
|
if (!strokeScaleEnabled) {
|
|
2212
2212
|
this.save();
|
|
2213
|
-
|
|
2213
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
2214
2214
|
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
2215
2215
|
}
|
|
2216
2216
|
this._applyLineCap(shape);
|
|
2217
|
-
|
|
2218
|
-
|
|
2217
|
+
const hitStrokeWidth = shape.hitStrokeWidth();
|
|
2218
|
+
const strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
|
|
2219
2219
|
this.setAttr('lineWidth', strokeWidth);
|
|
2220
2220
|
this.setAttr('strokeStyle', shape.colorKey);
|
|
2221
2221
|
shape._strokeFuncHit(this);
|
|
@@ -2227,15 +2227,15 @@
|
|
|
2227
2227
|
}
|
|
2228
2228
|
|
|
2229
2229
|
// calculate pixel ratio
|
|
2230
|
-
|
|
2230
|
+
let _pixelRatio;
|
|
2231
2231
|
function getDevicePixelRatio() {
|
|
2232
2232
|
if (_pixelRatio) {
|
|
2233
2233
|
return _pixelRatio;
|
|
2234
2234
|
}
|
|
2235
|
-
|
|
2236
|
-
|
|
2235
|
+
const canvas = Util.createCanvasElement();
|
|
2236
|
+
const context = canvas.getContext('2d');
|
|
2237
2237
|
_pixelRatio = (function () {
|
|
2238
|
-
|
|
2238
|
+
const devicePixelRatio = Konva$2._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
|
|
2239
2239
|
context.mozBackingStorePixelRatio ||
|
|
2240
2240
|
context.msBackingStorePixelRatio ||
|
|
2241
2241
|
context.oBackingStorePixelRatio ||
|
|
@@ -2263,8 +2263,8 @@
|
|
|
2263
2263
|
this.width = 0;
|
|
2264
2264
|
this.height = 0;
|
|
2265
2265
|
this.isCache = false;
|
|
2266
|
-
|
|
2267
|
-
|
|
2266
|
+
const conf = config || {};
|
|
2267
|
+
const pixelRatio = conf.pixelRatio || Konva$2.pixelRatio || getDevicePixelRatio();
|
|
2268
2268
|
this.pixelRatio = pixelRatio;
|
|
2269
2269
|
this._canvas = Util.createCanvasElement();
|
|
2270
2270
|
// set inline styles
|
|
@@ -2289,7 +2289,7 @@
|
|
|
2289
2289
|
return this.pixelRatio;
|
|
2290
2290
|
}
|
|
2291
2291
|
setPixelRatio(pixelRatio) {
|
|
2292
|
-
|
|
2292
|
+
const previousRatio = this.pixelRatio;
|
|
2293
2293
|
this.pixelRatio = pixelRatio;
|
|
2294
2294
|
this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
|
|
2295
2295
|
}
|
|
@@ -2297,14 +2297,14 @@
|
|
|
2297
2297
|
// take into account pixel ratio
|
|
2298
2298
|
this.width = this._canvas.width = width * this.pixelRatio;
|
|
2299
2299
|
this._canvas.style.width = width + 'px';
|
|
2300
|
-
|
|
2300
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
2301
2301
|
_context.scale(pixelRatio, pixelRatio);
|
|
2302
2302
|
}
|
|
2303
2303
|
setHeight(height) {
|
|
2304
2304
|
// take into account pixel ratio
|
|
2305
2305
|
this.height = this._canvas.height = height * this.pixelRatio;
|
|
2306
2306
|
this._canvas.style.height = height + 'px';
|
|
2307
|
-
|
|
2307
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
2308
2308
|
_context.scale(pixelRatio, pixelRatio);
|
|
2309
2309
|
}
|
|
2310
2310
|
getWidth() {
|
|
@@ -2385,7 +2385,7 @@
|
|
|
2385
2385
|
|
|
2386
2386
|
const DD = {
|
|
2387
2387
|
get isDragging() {
|
|
2388
|
-
|
|
2388
|
+
let flag = false;
|
|
2389
2389
|
DD._dragElements.forEach((elem) => {
|
|
2390
2390
|
if (elem.dragStatus === 'dragging') {
|
|
2391
2391
|
flag = true;
|
|
@@ -2396,7 +2396,7 @@
|
|
|
2396
2396
|
justDragged: false,
|
|
2397
2397
|
get node() {
|
|
2398
2398
|
// return first dragging node
|
|
2399
|
-
|
|
2399
|
+
let node;
|
|
2400
2400
|
DD._dragElements.forEach((elem) => {
|
|
2401
2401
|
node = elem.node;
|
|
2402
2402
|
});
|
|
@@ -2422,8 +2422,8 @@
|
|
|
2422
2422
|
return;
|
|
2423
2423
|
}
|
|
2424
2424
|
if (elem.dragStatus !== 'dragging') {
|
|
2425
|
-
|
|
2426
|
-
|
|
2425
|
+
const dragDistance = node.dragDistance();
|
|
2426
|
+
const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
|
|
2427
2427
|
if (distance < dragDistance) {
|
|
2428
2428
|
return;
|
|
2429
2429
|
}
|
|
@@ -2500,14 +2500,17 @@
|
|
|
2500
2500
|
if (Konva$2.isBrowser) {
|
|
2501
2501
|
window.addEventListener('mouseup', DD._endDragBefore, true);
|
|
2502
2502
|
window.addEventListener('touchend', DD._endDragBefore, true);
|
|
2503
|
+
// add touchcancel to fix this: https://github.com/konvajs/konva/issues/1843
|
|
2504
|
+
window.addEventListener('touchcancel', DD._endDragBefore, true);
|
|
2503
2505
|
window.addEventListener('mousemove', DD._drag);
|
|
2504
2506
|
window.addEventListener('touchmove', DD._drag);
|
|
2505
2507
|
window.addEventListener('mouseup', DD._endDragAfter, false);
|
|
2506
2508
|
window.addEventListener('touchend', DD._endDragAfter, false);
|
|
2509
|
+
window.addEventListener('touchcancel', DD._endDragAfter, false);
|
|
2507
2510
|
}
|
|
2508
2511
|
|
|
2509
2512
|
// CONSTANTS
|
|
2510
|
-
|
|
2513
|
+
const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER$1 = 'mouseenter', MOUSELEAVE$1 = 'mouseleave', SET = 'set', SHAPE = 'Shape', SPACE$1 = ' ', STAGE$1 = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR$1 = [
|
|
2511
2514
|
'xChange.konva',
|
|
2512
2515
|
'yChange.konva',
|
|
2513
2516
|
'scaleXChange.konva',
|
|
@@ -2590,11 +2593,11 @@
|
|
|
2590
2593
|
}
|
|
2591
2594
|
}
|
|
2592
2595
|
_getCache(attr, privateGetter) {
|
|
2593
|
-
|
|
2596
|
+
let cache = this._cache.get(attr);
|
|
2594
2597
|
// for transform the cache can be NOT empty
|
|
2595
2598
|
// but we still need to recalculate it if it is dirty
|
|
2596
|
-
|
|
2597
|
-
|
|
2599
|
+
const isTransform = attr === TRANSFORM || attr === ABSOLUTE_TRANSFORM;
|
|
2600
|
+
const invalid = cache === undefined || (isTransform && cache.dirty === true);
|
|
2598
2601
|
// if not cached, we need to set it using the private getter method.
|
|
2599
2602
|
if (invalid) {
|
|
2600
2603
|
cache = privateGetter.call(this);
|
|
@@ -2692,8 +2695,8 @@
|
|
|
2692
2695
|
* });
|
|
2693
2696
|
*/
|
|
2694
2697
|
cache(config) {
|
|
2695
|
-
|
|
2696
|
-
|
|
2698
|
+
const conf = config || {};
|
|
2699
|
+
let rect = {};
|
|
2697
2700
|
// don't call getClientRect if we have all attributes
|
|
2698
2701
|
// it means call it only if have one undefined
|
|
2699
2702
|
if (conf.x === undefined ||
|
|
@@ -2705,7 +2708,7 @@
|
|
|
2705
2708
|
relativeTo: this.getParent() || undefined,
|
|
2706
2709
|
});
|
|
2707
2710
|
}
|
|
2708
|
-
|
|
2711
|
+
let width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
2709
2712
|
if (!width || !height) {
|
|
2710
2713
|
Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
2711
2714
|
return;
|
|
@@ -2728,7 +2731,7 @@
|
|
|
2728
2731
|
// // height += 1;
|
|
2729
2732
|
// }
|
|
2730
2733
|
// console.log({ x, y, width, height }, rect);
|
|
2731
|
-
|
|
2734
|
+
const cachedSceneCanvas = new SceneCanvas({
|
|
2732
2735
|
pixelRatio: pixelRatio,
|
|
2733
2736
|
width: width,
|
|
2734
2737
|
height: height,
|
|
@@ -2836,16 +2839,16 @@
|
|
|
2836
2839
|
throw new Error('abstract "getClientRect" method call');
|
|
2837
2840
|
}
|
|
2838
2841
|
_transformedRect(rect, top) {
|
|
2839
|
-
|
|
2842
|
+
const points = [
|
|
2840
2843
|
{ x: rect.x, y: rect.y },
|
|
2841
2844
|
{ x: rect.x + rect.width, y: rect.y },
|
|
2842
2845
|
{ x: rect.x + rect.width, y: rect.y + rect.height },
|
|
2843
2846
|
{ x: rect.x, y: rect.y + rect.height },
|
|
2844
2847
|
];
|
|
2845
|
-
|
|
2846
|
-
|
|
2848
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
2849
|
+
const trans = this.getAbsoluteTransform(top);
|
|
2847
2850
|
points.forEach(function (point) {
|
|
2848
|
-
|
|
2851
|
+
const transformed = trans.point(point);
|
|
2849
2852
|
if (minX === undefined) {
|
|
2850
2853
|
minX = maxX = transformed.x;
|
|
2851
2854
|
minY = maxY = transformed.y;
|
|
@@ -2868,23 +2871,23 @@
|
|
|
2868
2871
|
context._applyGlobalCompositeOperation(this);
|
|
2869
2872
|
const canvasCache = this._getCanvasCache();
|
|
2870
2873
|
context.translate(canvasCache.x, canvasCache.y);
|
|
2871
|
-
|
|
2872
|
-
|
|
2874
|
+
const cacheCanvas = this._getCachedSceneCanvas();
|
|
2875
|
+
const ratio = cacheCanvas.pixelRatio;
|
|
2873
2876
|
context.drawImage(cacheCanvas._canvas, 0, 0, cacheCanvas.width / ratio, cacheCanvas.height / ratio);
|
|
2874
2877
|
context.restore();
|
|
2875
2878
|
}
|
|
2876
2879
|
_drawCachedHitCanvas(context) {
|
|
2877
|
-
|
|
2880
|
+
const canvasCache = this._getCanvasCache(), hitCanvas = canvasCache.hit;
|
|
2878
2881
|
context.save();
|
|
2879
2882
|
context.translate(canvasCache.x, canvasCache.y);
|
|
2880
2883
|
context.drawImage(hitCanvas._canvas, 0, 0, hitCanvas.width / hitCanvas.pixelRatio, hitCanvas.height / hitCanvas.pixelRatio);
|
|
2881
2884
|
context.restore();
|
|
2882
2885
|
}
|
|
2883
2886
|
_getCachedSceneCanvas() {
|
|
2884
|
-
|
|
2887
|
+
let filters = this.filters(), cachedCanvas = this._getCanvasCache(), sceneCanvas = cachedCanvas.scene, filterCanvas = cachedCanvas.filter, filterContext = filterCanvas.getContext(), len, imageData, n, filter;
|
|
2885
2888
|
if (filters) {
|
|
2886
2889
|
if (!this._filterUpToDate) {
|
|
2887
|
-
|
|
2890
|
+
const ratio = sceneCanvas.pixelRatio;
|
|
2888
2891
|
filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
|
|
2889
2892
|
try {
|
|
2890
2893
|
len = filters.length;
|
|
@@ -2982,7 +2985,7 @@
|
|
|
2982
2985
|
if (arguments.length === 3) {
|
|
2983
2986
|
return this._delegate.apply(this, arguments);
|
|
2984
2987
|
}
|
|
2985
|
-
|
|
2988
|
+
let events = evtStr.split(SPACE$1), len = events.length, n, event, parts, baseEvent, name;
|
|
2986
2989
|
/*
|
|
2987
2990
|
* loop through types and attach event listeners to
|
|
2988
2991
|
* each one. eg. 'click mouseover.namespace mouseout'
|
|
@@ -3026,7 +3029,7 @@
|
|
|
3026
3029
|
* node.off('click.foo');
|
|
3027
3030
|
*/
|
|
3028
3031
|
off(evtStr, callback) {
|
|
3029
|
-
|
|
3032
|
+
let events = (evtStr || '').split(SPACE$1), len = events.length, n, t, event, parts, baseEvent, name;
|
|
3030
3033
|
this._cache && this._cache.delete(ALL_LISTENERS);
|
|
3031
3034
|
if (!evtStr) {
|
|
3032
3035
|
// remove all events
|
|
@@ -3054,7 +3057,7 @@
|
|
|
3054
3057
|
}
|
|
3055
3058
|
// some event aliases for third party integration like HammerJS
|
|
3056
3059
|
dispatchEvent(evt) {
|
|
3057
|
-
|
|
3060
|
+
const e = {
|
|
3058
3061
|
target: this,
|
|
3059
3062
|
type: evt.type,
|
|
3060
3063
|
evt: evt,
|
|
@@ -3075,10 +3078,10 @@
|
|
|
3075
3078
|
}
|
|
3076
3079
|
// like node.on
|
|
3077
3080
|
_delegate(event, selector, handler) {
|
|
3078
|
-
|
|
3081
|
+
const stopNode = this;
|
|
3079
3082
|
this.on(event, function (evt) {
|
|
3080
|
-
|
|
3081
|
-
for (
|
|
3083
|
+
const targets = evt.target.findAncestors(selector, true, stopNode);
|
|
3084
|
+
for (let i = 0; i < targets.length; i++) {
|
|
3082
3085
|
evt = Util.cloneObject(evt);
|
|
3083
3086
|
evt.currentTarget = targets[i];
|
|
3084
3087
|
handler.call(targets[i], evt);
|
|
@@ -3115,7 +3118,7 @@
|
|
|
3115
3118
|
// every cached attr that is calculated via node tree
|
|
3116
3119
|
// traversal must be cleared when removing a node
|
|
3117
3120
|
this._clearCaches();
|
|
3118
|
-
|
|
3121
|
+
const parent = this.getParent();
|
|
3119
3122
|
if (parent && parent.children) {
|
|
3120
3123
|
parent.children.splice(this.index, 1);
|
|
3121
3124
|
parent._setChildrenIndices();
|
|
@@ -3145,7 +3148,7 @@
|
|
|
3145
3148
|
* var x = node.getAttr('x');
|
|
3146
3149
|
*/
|
|
3147
3150
|
getAttr(attr) {
|
|
3148
|
-
|
|
3151
|
+
const method = 'get' + Util._capitalize(attr);
|
|
3149
3152
|
if (Util._isFunction(this[method])) {
|
|
3150
3153
|
return this[method]();
|
|
3151
3154
|
}
|
|
@@ -3163,7 +3166,7 @@
|
|
|
3163
3166
|
* })
|
|
3164
3167
|
*/
|
|
3165
3168
|
getAncestors() {
|
|
3166
|
-
|
|
3169
|
+
let parent = this.getParent(), ancestors = [];
|
|
3167
3170
|
while (parent) {
|
|
3168
3171
|
ancestors.push(parent);
|
|
3169
3172
|
parent = parent.getParent();
|
|
@@ -3193,7 +3196,7 @@
|
|
|
3193
3196
|
*/
|
|
3194
3197
|
setAttrs(config) {
|
|
3195
3198
|
this._batchTransformChanges(() => {
|
|
3196
|
-
|
|
3199
|
+
let key, method;
|
|
3197
3200
|
if (!config) {
|
|
3198
3201
|
return this;
|
|
3199
3202
|
}
|
|
@@ -3279,8 +3282,8 @@
|
|
|
3279
3282
|
if (top) {
|
|
3280
3283
|
return this._isVisible(top) && this._isListening(top);
|
|
3281
3284
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3285
|
+
const layer = this.getLayer();
|
|
3286
|
+
let layerUnderDrag = false;
|
|
3284
3287
|
DD._dragElements.forEach((elem) => {
|
|
3285
3288
|
if (elem.dragStatus !== 'dragging') {
|
|
3286
3289
|
return;
|
|
@@ -3292,7 +3295,7 @@
|
|
|
3292
3295
|
layerUnderDrag = true;
|
|
3293
3296
|
}
|
|
3294
3297
|
});
|
|
3295
|
-
|
|
3298
|
+
const dragSkip = !skipDragCheck &&
|
|
3296
3299
|
!Konva$2.hitOnDragEnabled &&
|
|
3297
3300
|
(layerUnderDrag || Konva$2.isTransforming());
|
|
3298
3301
|
return this.isListening() && this.isVisible() && !dragSkip;
|
|
@@ -3328,7 +3331,7 @@
|
|
|
3328
3331
|
* @returns {Integer}
|
|
3329
3332
|
*/
|
|
3330
3333
|
getAbsoluteZIndex() {
|
|
3331
|
-
|
|
3334
|
+
let depth = this.getDepth(), that = this, index = 0, nodes, len, n, child;
|
|
3332
3335
|
function addChildren(children) {
|
|
3333
3336
|
nodes = [];
|
|
3334
3337
|
len = children.length;
|
|
@@ -3361,7 +3364,7 @@
|
|
|
3361
3364
|
* @returns {Integer}
|
|
3362
3365
|
*/
|
|
3363
3366
|
getDepth() {
|
|
3364
|
-
|
|
3367
|
+
let depth = 0, parent = this.parent;
|
|
3365
3368
|
while (parent) {
|
|
3366
3369
|
depth++;
|
|
3367
3370
|
parent = parent.parent;
|
|
@@ -3413,11 +3416,11 @@
|
|
|
3413
3416
|
return null;
|
|
3414
3417
|
}
|
|
3415
3418
|
// get pointer (say mouse or touch) position
|
|
3416
|
-
|
|
3419
|
+
const pos = stage.getPointerPosition();
|
|
3417
3420
|
if (!pos) {
|
|
3418
3421
|
return null;
|
|
3419
3422
|
}
|
|
3420
|
-
|
|
3423
|
+
const transform = this.getAbsoluteTransform().copy();
|
|
3421
3424
|
// to detect relative position we need to invert transform
|
|
3422
3425
|
transform.invert();
|
|
3423
3426
|
// now we can find relative point
|
|
@@ -3453,7 +3456,7 @@
|
|
|
3453
3456
|
// "true" is not a node, but it will just allow skip all caching
|
|
3454
3457
|
top = true;
|
|
3455
3458
|
}
|
|
3456
|
-
|
|
3459
|
+
const absoluteMatrix = this.getAbsoluteTransform(top).getMatrix(), absoluteTransform = new Transform(), offset = this.offset();
|
|
3457
3460
|
// clone the matrix array
|
|
3458
3461
|
absoluteTransform.m = absoluteMatrix.slice();
|
|
3459
3462
|
absoluteTransform.translate(offset.x, offset.y);
|
|
@@ -3466,7 +3469,7 @@
|
|
|
3466
3469
|
this.attrs.y = y;
|
|
3467
3470
|
// important, use non cached value
|
|
3468
3471
|
this._clearCache(TRANSFORM);
|
|
3469
|
-
|
|
3472
|
+
const it = this._getAbsoluteTransform().copy();
|
|
3470
3473
|
it.invert();
|
|
3471
3474
|
it.translate(pos.x, pos.y);
|
|
3472
3475
|
pos = {
|
|
@@ -3480,7 +3483,7 @@
|
|
|
3480
3483
|
return this;
|
|
3481
3484
|
}
|
|
3482
3485
|
_setTransform(trans) {
|
|
3483
|
-
|
|
3486
|
+
let key;
|
|
3484
3487
|
for (key in trans) {
|
|
3485
3488
|
this.attrs[key] = trans[key];
|
|
3486
3489
|
}
|
|
@@ -3488,7 +3491,7 @@
|
|
|
3488
3491
|
// this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
3489
3492
|
}
|
|
3490
3493
|
_clearTransform() {
|
|
3491
|
-
|
|
3494
|
+
const trans = {
|
|
3492
3495
|
x: this.x(),
|
|
3493
3496
|
y: this.y(),
|
|
3494
3497
|
rotation: this.rotation(),
|
|
@@ -3527,7 +3530,7 @@
|
|
|
3527
3530
|
* });
|
|
3528
3531
|
*/
|
|
3529
3532
|
move(change) {
|
|
3530
|
-
|
|
3533
|
+
let changeX = change.x, changeY = change.y, x = this.x(), y = this.y();
|
|
3531
3534
|
if (changeX !== undefined) {
|
|
3532
3535
|
x += changeX;
|
|
3533
3536
|
}
|
|
@@ -3538,7 +3541,7 @@
|
|
|
3538
3541
|
return this;
|
|
3539
3542
|
}
|
|
3540
3543
|
_eachAncestorReverse(func, top) {
|
|
3541
|
-
|
|
3544
|
+
let family = [], parent = this.getParent(), len, n;
|
|
3542
3545
|
// if top node is defined, and this node is top node,
|
|
3543
3546
|
// there's no need to build a family tree. just execute
|
|
3544
3547
|
// func with this because it will be the only node
|
|
@@ -3578,7 +3581,7 @@
|
|
|
3578
3581
|
Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
3579
3582
|
return false;
|
|
3580
3583
|
}
|
|
3581
|
-
|
|
3584
|
+
const index = this.index, len = this.parent.getChildren().length;
|
|
3582
3585
|
if (index < len - 1) {
|
|
3583
3586
|
this.parent.children.splice(index, 1);
|
|
3584
3587
|
this.parent.children.push(this);
|
|
@@ -3598,7 +3601,7 @@
|
|
|
3598
3601
|
Util.warn('Node has no parent. moveUp function is ignored.');
|
|
3599
3602
|
return false;
|
|
3600
3603
|
}
|
|
3601
|
-
|
|
3604
|
+
const index = this.index, len = this.parent.getChildren().length;
|
|
3602
3605
|
if (index < len - 1) {
|
|
3603
3606
|
this.parent.children.splice(index, 1);
|
|
3604
3607
|
this.parent.children.splice(index + 1, 0, this);
|
|
@@ -3618,7 +3621,7 @@
|
|
|
3618
3621
|
Util.warn('Node has no parent. moveDown function is ignored.');
|
|
3619
3622
|
return false;
|
|
3620
3623
|
}
|
|
3621
|
-
|
|
3624
|
+
const index = this.index;
|
|
3622
3625
|
if (index > 0) {
|
|
3623
3626
|
this.parent.children.splice(index, 1);
|
|
3624
3627
|
this.parent.children.splice(index - 1, 0, this);
|
|
@@ -3638,7 +3641,7 @@
|
|
|
3638
3641
|
Util.warn('Node has no parent. moveToBottom function is ignored.');
|
|
3639
3642
|
return false;
|
|
3640
3643
|
}
|
|
3641
|
-
|
|
3644
|
+
const index = this.index;
|
|
3642
3645
|
if (index > 0) {
|
|
3643
3646
|
this.parent.children.splice(index, 1);
|
|
3644
3647
|
this.parent.children.unshift(this);
|
|
@@ -3659,7 +3662,7 @@
|
|
|
3659
3662
|
(this.parent.children.length - 1) +
|
|
3660
3663
|
'.');
|
|
3661
3664
|
}
|
|
3662
|
-
|
|
3665
|
+
const index = this.index;
|
|
3663
3666
|
this.parent.children.splice(index, 1);
|
|
3664
3667
|
this.parent.children.splice(zIndex, 0, this);
|
|
3665
3668
|
this.parent._setChildrenIndices();
|
|
@@ -3675,8 +3678,8 @@
|
|
|
3675
3678
|
return this._getCache(ABSOLUTE_OPACITY, this._getAbsoluteOpacity);
|
|
3676
3679
|
}
|
|
3677
3680
|
_getAbsoluteOpacity() {
|
|
3678
|
-
|
|
3679
|
-
|
|
3681
|
+
let absOpacity = this.opacity();
|
|
3682
|
+
const parent = this.getParent();
|
|
3680
3683
|
if (parent && !parent._isUnderCache) {
|
|
3681
3684
|
absOpacity *= parent.getAbsoluteOpacity();
|
|
3682
3685
|
}
|
|
@@ -3707,7 +3710,7 @@
|
|
|
3707
3710
|
* @returns {Object}
|
|
3708
3711
|
*/
|
|
3709
3712
|
toObject() {
|
|
3710
|
-
|
|
3713
|
+
let attrs = this.getAttrs(), key, val, getter, defaultValue, nonPlainObject;
|
|
3711
3714
|
const obj = {
|
|
3712
3715
|
attrs: {},
|
|
3713
3716
|
className: this.getClassName(),
|
|
@@ -3764,11 +3767,11 @@
|
|
|
3764
3767
|
* var parentGroups = node.findAncestors('Group');
|
|
3765
3768
|
*/
|
|
3766
3769
|
findAncestors(selector, includeSelf, stopNode) {
|
|
3767
|
-
|
|
3770
|
+
const res = [];
|
|
3768
3771
|
if (includeSelf && this._isMatch(selector)) {
|
|
3769
3772
|
res.push(this);
|
|
3770
3773
|
}
|
|
3771
|
-
|
|
3774
|
+
let ancestor = this.parent;
|
|
3772
3775
|
while (ancestor) {
|
|
3773
3776
|
if (ancestor === stopNode) {
|
|
3774
3777
|
return res;
|
|
@@ -3806,7 +3809,7 @@
|
|
|
3806
3809
|
if (typeof selector === 'function') {
|
|
3807
3810
|
return selector(this);
|
|
3808
3811
|
}
|
|
3809
|
-
|
|
3812
|
+
let selectorArr = selector.replace(/ /g, '').split(','), len = selectorArr.length, n, sel;
|
|
3810
3813
|
for (n = 0; n < len; n++) {
|
|
3811
3814
|
sel = selectorArr[n];
|
|
3812
3815
|
if (!Util.isValidSelector(sel)) {
|
|
@@ -3841,7 +3844,7 @@
|
|
|
3841
3844
|
* @returns {Konva.Layer}
|
|
3842
3845
|
*/
|
|
3843
3846
|
getLayer() {
|
|
3844
|
-
|
|
3847
|
+
const parent = this.getParent();
|
|
3845
3848
|
return parent ? parent.getLayer() : null;
|
|
3846
3849
|
}
|
|
3847
3850
|
/**
|
|
@@ -3854,7 +3857,7 @@
|
|
|
3854
3857
|
return this._getCache(STAGE$1, this._getStage);
|
|
3855
3858
|
}
|
|
3856
3859
|
_getStage() {
|
|
3857
|
-
|
|
3860
|
+
const parent = this.getParent();
|
|
3858
3861
|
if (parent) {
|
|
3859
3862
|
return parent.getStage();
|
|
3860
3863
|
}
|
|
@@ -3916,13 +3919,13 @@
|
|
|
3916
3919
|
}
|
|
3917
3920
|
}
|
|
3918
3921
|
_getAbsoluteTransform(top) {
|
|
3919
|
-
|
|
3922
|
+
let at;
|
|
3920
3923
|
// we we need position relative to an ancestor, we will iterate for all
|
|
3921
3924
|
if (top) {
|
|
3922
3925
|
at = new Transform();
|
|
3923
3926
|
// start with stage and traverse downwards to self
|
|
3924
3927
|
this._eachAncestorReverse(function (node) {
|
|
3925
|
-
|
|
3928
|
+
const transformsEnabled = node.transformsEnabled();
|
|
3926
3929
|
if (transformsEnabled === 'all') {
|
|
3927
3930
|
at.multiply(node.getTransform());
|
|
3928
3931
|
}
|
|
@@ -3942,7 +3945,7 @@
|
|
|
3942
3945
|
else {
|
|
3943
3946
|
at.reset();
|
|
3944
3947
|
}
|
|
3945
|
-
|
|
3948
|
+
const transformsEnabled = this.transformsEnabled();
|
|
3946
3949
|
if (transformsEnabled === 'all') {
|
|
3947
3950
|
at.multiply(this.getTransform());
|
|
3948
3951
|
}
|
|
@@ -3972,7 +3975,7 @@
|
|
|
3972
3975
|
// do not cache this calculations,
|
|
3973
3976
|
// because it use cache transform
|
|
3974
3977
|
// this is special logic for caching with some shapes with shadow
|
|
3975
|
-
|
|
3978
|
+
let parent = this;
|
|
3976
3979
|
while (parent) {
|
|
3977
3980
|
if (parent._isUnderCache) {
|
|
3978
3981
|
top = parent;
|
|
@@ -4017,12 +4020,12 @@
|
|
|
4017
4020
|
}
|
|
4018
4021
|
_getTransform() {
|
|
4019
4022
|
var _a, _b;
|
|
4020
|
-
|
|
4023
|
+
const m = this._cache.get(TRANSFORM) || new Transform();
|
|
4021
4024
|
m.reset();
|
|
4022
4025
|
// I was trying to use attributes directly here
|
|
4023
4026
|
// but it doesn't work for Transformer well
|
|
4024
4027
|
// because it overwrite x,y getters
|
|
4025
|
-
|
|
4028
|
+
const x = this.x(), y = this.y(), rotation = Konva$2.getAngle(this.rotation()), scaleX = (_a = this.attrs.scaleX) !== null && _a !== void 0 ? _a : 1, scaleY = (_b = this.attrs.scaleY) !== null && _b !== void 0 ? _b : 1, skewX = this.attrs.skewX || 0, skewY = this.attrs.skewY || 0, offsetX = this.attrs.offsetX || 0, offsetY = this.attrs.offsetY || 0;
|
|
4026
4029
|
if (x !== 0 || y !== 0) {
|
|
4027
4030
|
m.translate(x, y);
|
|
4028
4031
|
}
|
|
@@ -4060,12 +4063,12 @@
|
|
|
4060
4063
|
*/
|
|
4061
4064
|
clone(obj) {
|
|
4062
4065
|
// instantiate new node
|
|
4063
|
-
|
|
4066
|
+
let attrs = Util.cloneObject(this.attrs), key, allListeners, len, n, listener;
|
|
4064
4067
|
// apply attr overrides
|
|
4065
4068
|
for (key in obj) {
|
|
4066
4069
|
attrs[key] = obj[key];
|
|
4067
4070
|
}
|
|
4068
|
-
|
|
4071
|
+
const node = new this.constructor(attrs);
|
|
4069
4072
|
// copy over listeners
|
|
4070
4073
|
for (key in this.eventListeners) {
|
|
4071
4074
|
allListeners = this.eventListeners[key];
|
|
@@ -4089,8 +4092,8 @@
|
|
|
4089
4092
|
}
|
|
4090
4093
|
_toKonvaCanvas(config) {
|
|
4091
4094
|
config = config || {};
|
|
4092
|
-
|
|
4093
|
-
|
|
4095
|
+
const box = this.getClientRect();
|
|
4096
|
+
const stage = this.getStage(), x = config.x !== undefined ? config.x : Math.floor(box.x), y = config.y !== undefined ? config.y : Math.floor(box.y), pixelRatio = config.pixelRatio || 1, canvas = new SceneCanvas({
|
|
4094
4097
|
width: config.width || Math.ceil(box.width) || (stage ? stage.width() : 0),
|
|
4095
4098
|
height: config.height ||
|
|
4096
4099
|
Math.ceil(box.height) ||
|
|
@@ -4162,8 +4165,8 @@
|
|
|
4162
4165
|
*/
|
|
4163
4166
|
toDataURL(config) {
|
|
4164
4167
|
config = config || {};
|
|
4165
|
-
|
|
4166
|
-
|
|
4168
|
+
const mimeType = config.mimeType || null, quality = config.quality || null;
|
|
4169
|
+
const url = this._toKonvaCanvas(config).toDataURL(mimeType, quality);
|
|
4167
4170
|
if (config.callback) {
|
|
4168
4171
|
config.callback(url);
|
|
4169
4172
|
}
|
|
@@ -4295,7 +4298,7 @@
|
|
|
4295
4298
|
}
|
|
4296
4299
|
}
|
|
4297
4300
|
_off(type, name, callback) {
|
|
4298
|
-
|
|
4301
|
+
let evtListeners = this.eventListeners[type], i, evtName, handler;
|
|
4299
4302
|
for (i = 0; i < evtListeners.length; i++) {
|
|
4300
4303
|
evtName = evtListeners[i].name;
|
|
4301
4304
|
handler = evtListeners[i].handler;
|
|
@@ -4334,8 +4337,8 @@
|
|
|
4334
4337
|
*/
|
|
4335
4338
|
addName(name) {
|
|
4336
4339
|
if (!this.hasName(name)) {
|
|
4337
|
-
|
|
4338
|
-
|
|
4340
|
+
const oldName = this.name();
|
|
4341
|
+
const newName = oldName ? oldName + ' ' + name : name;
|
|
4339
4342
|
this.name(newName);
|
|
4340
4343
|
}
|
|
4341
4344
|
return this;
|
|
@@ -4361,7 +4364,7 @@
|
|
|
4361
4364
|
return false;
|
|
4362
4365
|
}
|
|
4363
4366
|
// if name is '' the "names" will be [''], so I added extra check above
|
|
4364
|
-
|
|
4367
|
+
const names = (fullName || '').split(/\s/g);
|
|
4365
4368
|
return names.indexOf(name) !== -1;
|
|
4366
4369
|
}
|
|
4367
4370
|
/**
|
|
@@ -4377,8 +4380,8 @@
|
|
|
4377
4380
|
* node.name(); // return 'red'
|
|
4378
4381
|
*/
|
|
4379
4382
|
removeName(name) {
|
|
4380
|
-
|
|
4381
|
-
|
|
4383
|
+
const names = (this.name() || '').split(/\s/g);
|
|
4384
|
+
const index = names.indexOf(name);
|
|
4382
4385
|
if (index !== -1) {
|
|
4383
4386
|
names.splice(index, 1);
|
|
4384
4387
|
this.name(names.join(' '));
|
|
@@ -4396,7 +4399,7 @@
|
|
|
4396
4399
|
* node.setAttr('x', 5);
|
|
4397
4400
|
*/
|
|
4398
4401
|
setAttr(attr, val) {
|
|
4399
|
-
|
|
4402
|
+
const func = this[SET + Util._capitalize(attr)];
|
|
4400
4403
|
if (Util._isFunction(func)) {
|
|
4401
4404
|
func.call(this, val);
|
|
4402
4405
|
}
|
|
@@ -4413,7 +4416,7 @@
|
|
|
4413
4416
|
}
|
|
4414
4417
|
}
|
|
4415
4418
|
_setAttr(key, val) {
|
|
4416
|
-
|
|
4419
|
+
const oldVal = this.attrs[key];
|
|
4417
4420
|
if (oldVal === val && !Util.isObject(val)) {
|
|
4418
4421
|
return;
|
|
4419
4422
|
}
|
|
@@ -4429,7 +4432,7 @@
|
|
|
4429
4432
|
this._requestDraw();
|
|
4430
4433
|
}
|
|
4431
4434
|
_setComponentAttr(key, component, val) {
|
|
4432
|
-
|
|
4435
|
+
let oldVal;
|
|
4433
4436
|
if (val !== undefined) {
|
|
4434
4437
|
oldVal = this.attrs[key];
|
|
4435
4438
|
if (!oldVal) {
|
|
@@ -4444,7 +4447,7 @@
|
|
|
4444
4447
|
if (evt && this.nodeType === SHAPE) {
|
|
4445
4448
|
evt.target = this;
|
|
4446
4449
|
}
|
|
4447
|
-
|
|
4450
|
+
const shouldStop = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
|
|
4448
4451
|
((compareShape &&
|
|
4449
4452
|
(this === compareShape ||
|
|
4450
4453
|
(this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
|
|
@@ -4452,7 +4455,7 @@
|
|
|
4452
4455
|
if (!shouldStop) {
|
|
4453
4456
|
this._fire(eventType, evt);
|
|
4454
4457
|
// simulate event bubbling
|
|
4455
|
-
|
|
4458
|
+
const stopBubble = (eventType === MOUSEENTER$1 || eventType === MOUSELEAVE$1) &&
|
|
4456
4459
|
compareShape &&
|
|
4457
4460
|
compareShape.isAncestorOf &&
|
|
4458
4461
|
compareShape.isAncestorOf(this) &&
|
|
@@ -4521,13 +4524,13 @@
|
|
|
4521
4524
|
}
|
|
4522
4525
|
// drag & drop
|
|
4523
4526
|
_createDragElement(evt) {
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
+
const pointerId = evt ? evt.pointerId : undefined;
|
|
4528
|
+
const stage = this.getStage();
|
|
4529
|
+
const ap = this.getAbsolutePosition();
|
|
4527
4530
|
if (!stage) {
|
|
4528
4531
|
return;
|
|
4529
4532
|
}
|
|
4530
|
-
|
|
4533
|
+
const pos = stage._getPointerById(pointerId) ||
|
|
4531
4534
|
stage._changedPointerPositions[0] ||
|
|
4532
4535
|
ap;
|
|
4533
4536
|
DD._dragElements.set(this._id, {
|
|
@@ -4565,11 +4568,11 @@
|
|
|
4565
4568
|
if (!pos) {
|
|
4566
4569
|
return;
|
|
4567
4570
|
}
|
|
4568
|
-
|
|
4571
|
+
let newNodePos = {
|
|
4569
4572
|
x: pos.x - elem.offset.x,
|
|
4570
4573
|
y: pos.y - elem.offset.y,
|
|
4571
4574
|
};
|
|
4572
|
-
|
|
4575
|
+
const dbf = this.dragBoundFunc();
|
|
4573
4576
|
if (dbf !== undefined) {
|
|
4574
4577
|
const bounded = dbf.call(this, newNodePos, evt);
|
|
4575
4578
|
if (!bounded) {
|
|
@@ -4616,15 +4619,15 @@
|
|
|
4616
4619
|
_listenDrag() {
|
|
4617
4620
|
this._dragCleanup();
|
|
4618
4621
|
this.on('mousedown.konva touchstart.konva', function (evt) {
|
|
4619
|
-
|
|
4620
|
-
|
|
4622
|
+
const shouldCheckButton = evt.evt['button'] !== undefined;
|
|
4623
|
+
const canDrag = !shouldCheckButton || Konva$2.dragButtons.indexOf(evt.evt['button']) >= 0;
|
|
4621
4624
|
if (!canDrag) {
|
|
4622
4625
|
return;
|
|
4623
4626
|
}
|
|
4624
4627
|
if (this.isDragging()) {
|
|
4625
4628
|
return;
|
|
4626
4629
|
}
|
|
4627
|
-
|
|
4630
|
+
let hasDraggingChild = false;
|
|
4628
4631
|
DD._dragElements.forEach((elem) => {
|
|
4629
4632
|
if (this.isAncestorOf(elem.node)) {
|
|
4630
4633
|
hasDraggingChild = true;
|
|
@@ -4649,7 +4652,7 @@
|
|
|
4649
4652
|
* if this node is currently in
|
|
4650
4653
|
* drag and drop mode
|
|
4651
4654
|
*/
|
|
4652
|
-
|
|
4655
|
+
const stage = this.getStage();
|
|
4653
4656
|
if (!stage) {
|
|
4654
4657
|
return;
|
|
4655
4658
|
}
|
|
@@ -4716,7 +4719,7 @@
|
|
|
4716
4719
|
return this._createNode(data, container);
|
|
4717
4720
|
}
|
|
4718
4721
|
static _createNode(obj, container) {
|
|
4719
|
-
|
|
4722
|
+
let className = Node.prototype.getClassName.call(obj), children = obj.children, no, len, n;
|
|
4720
4723
|
// if container was passed in, add it to attrs
|
|
4721
4724
|
if (container) {
|
|
4722
4725
|
obj.attrs.container = container;
|
|
@@ -5328,7 +5331,7 @@
|
|
|
5328
5331
|
return this.children || [];
|
|
5329
5332
|
}
|
|
5330
5333
|
const children = this.children || [];
|
|
5331
|
-
|
|
5334
|
+
const results = [];
|
|
5332
5335
|
children.forEach(function (child) {
|
|
5333
5336
|
if (filterFunc(child)) {
|
|
5334
5337
|
results.push(child);
|
|
@@ -5399,7 +5402,7 @@
|
|
|
5399
5402
|
return this;
|
|
5400
5403
|
}
|
|
5401
5404
|
if (children.length > 1) {
|
|
5402
|
-
for (
|
|
5405
|
+
for (let i = 0; i < children.length; i++) {
|
|
5403
5406
|
this.add(children[i]);
|
|
5404
5407
|
}
|
|
5405
5408
|
return this;
|
|
@@ -5492,11 +5495,11 @@
|
|
|
5492
5495
|
* })
|
|
5493
5496
|
*/
|
|
5494
5497
|
findOne(selector) {
|
|
5495
|
-
|
|
5498
|
+
const result = this._generalFind(selector, true);
|
|
5496
5499
|
return result.length > 0 ? result[0] : undefined;
|
|
5497
5500
|
}
|
|
5498
5501
|
_generalFind(selector, findOne) {
|
|
5499
|
-
|
|
5502
|
+
const retArr = [];
|
|
5500
5503
|
this._descendants((node) => {
|
|
5501
5504
|
const valid = node._isMatch(selector);
|
|
5502
5505
|
if (valid) {
|
|
@@ -5529,7 +5532,7 @@
|
|
|
5529
5532
|
}
|
|
5530
5533
|
// extenders
|
|
5531
5534
|
toObject() {
|
|
5532
|
-
|
|
5535
|
+
const obj = Node.prototype.toObject.call(this);
|
|
5533
5536
|
obj.children = [];
|
|
5534
5537
|
this.getChildren().forEach((child) => {
|
|
5535
5538
|
obj.children.push(child.toObject());
|
|
@@ -5544,7 +5547,7 @@
|
|
|
5544
5547
|
* @param {Konva.Node} node
|
|
5545
5548
|
*/
|
|
5546
5549
|
isAncestorOf(node) {
|
|
5547
|
-
|
|
5550
|
+
let parent = node.getParent();
|
|
5548
5551
|
while (parent) {
|
|
5549
5552
|
if (parent._id === this._id) {
|
|
5550
5553
|
return true;
|
|
@@ -5555,7 +5558,7 @@
|
|
|
5555
5558
|
}
|
|
5556
5559
|
clone(obj) {
|
|
5557
5560
|
// call super method
|
|
5558
|
-
|
|
5561
|
+
const node = Node.prototype.clone.call(this, obj);
|
|
5559
5562
|
this.getChildren().forEach(function (no) {
|
|
5560
5563
|
node.add(no.clone());
|
|
5561
5564
|
});
|
|
@@ -5575,7 +5578,7 @@
|
|
|
5575
5578
|
* @returns {Array} array of shapes
|
|
5576
5579
|
*/
|
|
5577
5580
|
getAllIntersections(pos) {
|
|
5578
|
-
|
|
5581
|
+
const arr = [];
|
|
5579
5582
|
this.find('Shape').forEach((shape) => {
|
|
5580
5583
|
if (shape.isVisible() && shape.intersects(pos)) {
|
|
5581
5584
|
arr.push(shape);
|
|
@@ -5603,14 +5606,14 @@
|
|
|
5603
5606
|
this._requestDraw();
|
|
5604
5607
|
}
|
|
5605
5608
|
drawScene(can, top, bufferCanvas) {
|
|
5606
|
-
|
|
5607
|
-
|
|
5609
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
|
|
5610
|
+
const caching = canvas && canvas.isCache;
|
|
5608
5611
|
if (!this.isVisible() && !caching) {
|
|
5609
5612
|
return this;
|
|
5610
5613
|
}
|
|
5611
5614
|
if (cachedSceneCanvas) {
|
|
5612
5615
|
context.save();
|
|
5613
|
-
|
|
5616
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
5614
5617
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
5615
5618
|
this._drawCachedSceneCanvas(context);
|
|
5616
5619
|
context.restore();
|
|
@@ -5624,10 +5627,10 @@
|
|
|
5624
5627
|
if (!this.shouldDrawHit(top)) {
|
|
5625
5628
|
return this;
|
|
5626
5629
|
}
|
|
5627
|
-
|
|
5630
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
|
5628
5631
|
if (cachedHitCanvas) {
|
|
5629
5632
|
context.save();
|
|
5630
|
-
|
|
5633
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
5631
5634
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
5632
5635
|
this._drawCachedHitCanvas(context);
|
|
5633
5636
|
context.restore();
|
|
@@ -5639,13 +5642,13 @@
|
|
|
5639
5642
|
}
|
|
5640
5643
|
_drawChildren(drawMethod, canvas, top, bufferCanvas) {
|
|
5641
5644
|
var _a;
|
|
5642
|
-
|
|
5645
|
+
const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
|
|
5643
5646
|
clipFunc;
|
|
5644
5647
|
const selfCache = top === this;
|
|
5645
5648
|
if (hasClip) {
|
|
5646
5649
|
context.save();
|
|
5647
|
-
|
|
5648
|
-
|
|
5650
|
+
const transform = this.getAbsoluteTransform(top);
|
|
5651
|
+
let m = transform.getMatrix();
|
|
5649
5652
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
5650
5653
|
context.beginPath();
|
|
5651
5654
|
let clipArgs;
|
|
@@ -5653,15 +5656,15 @@
|
|
|
5653
5656
|
clipArgs = clipFunc.call(this, context, this);
|
|
5654
5657
|
}
|
|
5655
5658
|
else {
|
|
5656
|
-
|
|
5657
|
-
|
|
5659
|
+
const clipX = this.clipX();
|
|
5660
|
+
const clipY = this.clipY();
|
|
5658
5661
|
context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight);
|
|
5659
5662
|
}
|
|
5660
5663
|
context.clip.apply(context, clipArgs);
|
|
5661
5664
|
m = transform.copy().invert().getMatrix();
|
|
5662
5665
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
5663
5666
|
}
|
|
5664
|
-
|
|
5667
|
+
const hasComposition = !selfCache &&
|
|
5665
5668
|
this.globalCompositeOperation() !== 'source-over' &&
|
|
5666
5669
|
drawMethod === 'drawScene';
|
|
5667
5670
|
if (hasComposition) {
|
|
@@ -5680,22 +5683,22 @@
|
|
|
5680
5683
|
}
|
|
5681
5684
|
getClientRect(config = {}) {
|
|
5682
5685
|
var _a;
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
|
|
5686
|
-
|
|
5686
|
+
const skipTransform = config.skipTransform;
|
|
5687
|
+
const relativeTo = config.relativeTo;
|
|
5688
|
+
let minX, minY, maxX, maxY;
|
|
5689
|
+
let selfRect = {
|
|
5687
5690
|
x: Infinity,
|
|
5688
5691
|
y: Infinity,
|
|
5689
5692
|
width: 0,
|
|
5690
5693
|
height: 0,
|
|
5691
5694
|
};
|
|
5692
|
-
|
|
5695
|
+
const that = this;
|
|
5693
5696
|
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
|
5694
5697
|
// skip invisible children
|
|
5695
5698
|
if (!child.visible()) {
|
|
5696
5699
|
return;
|
|
5697
5700
|
}
|
|
5698
|
-
|
|
5701
|
+
const rect = child.getClientRect({
|
|
5699
5702
|
relativeTo: that,
|
|
5700
5703
|
skipShadow: config.skipShadow,
|
|
5701
5704
|
skipStroke: config.skipStroke,
|
|
@@ -5719,10 +5722,10 @@
|
|
|
5719
5722
|
}
|
|
5720
5723
|
});
|
|
5721
5724
|
// if child is group we need to make sure it has visible shapes inside
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
for (
|
|
5725
|
-
|
|
5725
|
+
const shapes = this.find('Shape');
|
|
5726
|
+
let hasVisible = false;
|
|
5727
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
5728
|
+
const shape = shapes[i];
|
|
5726
5729
|
if (shape._isVisible(this)) {
|
|
5727
5730
|
hasVisible = true;
|
|
5728
5731
|
break;
|
|
@@ -5896,7 +5899,7 @@
|
|
|
5896
5899
|
}
|
|
5897
5900
|
|
|
5898
5901
|
// CONSTANTS
|
|
5899
|
-
|
|
5902
|
+
const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
|
|
5900
5903
|
[MOUSEENTER, '_pointerenter'],
|
|
5901
5904
|
[MOUSEDOWN, '_pointerdown'],
|
|
5902
5905
|
[MOUSEMOVE, '_pointermove'],
|
|
@@ -6055,7 +6058,7 @@
|
|
|
6055
6058
|
setContainer(container) {
|
|
6056
6059
|
if (typeof container === STRING) {
|
|
6057
6060
|
if (container.charAt(0) === '.') {
|
|
6058
|
-
|
|
6061
|
+
const className = container.slice(1);
|
|
6059
6062
|
container = document.getElementsByClassName(className)[0];
|
|
6060
6063
|
}
|
|
6061
6064
|
else {
|
|
@@ -6090,7 +6093,7 @@
|
|
|
6090
6093
|
* @name Konva.Stage#clear
|
|
6091
6094
|
*/
|
|
6092
6095
|
clear() {
|
|
6093
|
-
|
|
6096
|
+
let layers = this.children, len = layers.length, n;
|
|
6094
6097
|
for (n = 0; n < len; n++) {
|
|
6095
6098
|
layers[n].clear();
|
|
6096
6099
|
}
|
|
@@ -6106,11 +6109,11 @@
|
|
|
6106
6109
|
}
|
|
6107
6110
|
destroy() {
|
|
6108
6111
|
super.destroy();
|
|
6109
|
-
|
|
6112
|
+
const content = this.content;
|
|
6110
6113
|
if (content && Util._isInDocument(content)) {
|
|
6111
6114
|
this.container().removeChild(content);
|
|
6112
6115
|
}
|
|
6113
|
-
|
|
6116
|
+
const index = stages.indexOf(this);
|
|
6114
6117
|
if (index > -1) {
|
|
6115
6118
|
stages.splice(index, 1);
|
|
6116
6119
|
}
|
|
@@ -6154,13 +6157,13 @@
|
|
|
6154
6157
|
config.y = config.y || 0;
|
|
6155
6158
|
config.width = config.width || this.width();
|
|
6156
6159
|
config.height = config.height || this.height();
|
|
6157
|
-
|
|
6160
|
+
const canvas = new SceneCanvas({
|
|
6158
6161
|
width: config.width,
|
|
6159
6162
|
height: config.height,
|
|
6160
6163
|
pixelRatio: config.pixelRatio || 1,
|
|
6161
6164
|
});
|
|
6162
|
-
|
|
6163
|
-
|
|
6165
|
+
const _context = canvas.getContext()._context;
|
|
6166
|
+
const layers = this.children;
|
|
6164
6167
|
if (config.x || config.y) {
|
|
6165
6168
|
_context.translate(-1 * config.x, -1 * config.y);
|
|
6166
6169
|
}
|
|
@@ -6168,7 +6171,7 @@
|
|
|
6168
6171
|
if (!layer.isVisible()) {
|
|
6169
6172
|
return;
|
|
6170
6173
|
}
|
|
6171
|
-
|
|
6174
|
+
const layerCanvas = layer._toKonvaCanvas(config);
|
|
6172
6175
|
_context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio());
|
|
6173
6176
|
});
|
|
6174
6177
|
return canvas;
|
|
@@ -6190,7 +6193,7 @@
|
|
|
6190
6193
|
if (!pos) {
|
|
6191
6194
|
return null;
|
|
6192
6195
|
}
|
|
6193
|
-
|
|
6196
|
+
let layers = this.children, len = layers.length, end = len - 1, n;
|
|
6194
6197
|
for (n = end; n >= 0; n--) {
|
|
6195
6198
|
const shape = layers[n].getIntersection(pos);
|
|
6196
6199
|
if (shape) {
|
|
@@ -6200,8 +6203,8 @@
|
|
|
6200
6203
|
return null;
|
|
6201
6204
|
}
|
|
6202
6205
|
_resizeDOM() {
|
|
6203
|
-
|
|
6204
|
-
|
|
6206
|
+
const width = this.width();
|
|
6207
|
+
const height = this.height();
|
|
6205
6208
|
if (this.content) {
|
|
6206
6209
|
// set content dimensions
|
|
6207
6210
|
this.content.style.width = width + PX;
|
|
@@ -6217,13 +6220,13 @@
|
|
|
6217
6220
|
}
|
|
6218
6221
|
add(layer, ...rest) {
|
|
6219
6222
|
if (arguments.length > 1) {
|
|
6220
|
-
for (
|
|
6223
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
6221
6224
|
this.add(arguments[i]);
|
|
6222
6225
|
}
|
|
6223
6226
|
return this;
|
|
6224
6227
|
}
|
|
6225
6228
|
super.add(layer);
|
|
6226
|
-
|
|
6229
|
+
const length = this.children.length;
|
|
6227
6230
|
if (length > MAX_LAYERS_NUMBER) {
|
|
6228
6231
|
Util.warn('The stage has ' +
|
|
6229
6232
|
length +
|
|
@@ -6307,8 +6310,8 @@
|
|
|
6307
6310
|
return;
|
|
6308
6311
|
}
|
|
6309
6312
|
this.setPointersPositions(evt);
|
|
6310
|
-
|
|
6311
|
-
|
|
6313
|
+
const targetShape = this._getTargetShape(eventType);
|
|
6314
|
+
const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
|
|
6312
6315
|
if (targetShape && eventsEnabled) {
|
|
6313
6316
|
targetShape._fireAndBubble(events.pointerout, { evt: evt });
|
|
6314
6317
|
targetShape._fireAndBubble(events.pointerleave, { evt: evt });
|
|
@@ -6341,9 +6344,9 @@
|
|
|
6341
6344
|
return;
|
|
6342
6345
|
}
|
|
6343
6346
|
this.setPointersPositions(evt);
|
|
6344
|
-
|
|
6347
|
+
let triggeredOnShape = false;
|
|
6345
6348
|
this._changedPointerPositions.forEach((pos) => {
|
|
6346
|
-
|
|
6349
|
+
const shape = this.getIntersection(pos);
|
|
6347
6350
|
DD.justDragged = false;
|
|
6348
6351
|
// probably we are staring a click
|
|
6349
6352
|
Konva$2['_' + eventType + 'ListenClick'] = true;
|
|
@@ -6389,19 +6392,19 @@
|
|
|
6389
6392
|
evt.preventDefault();
|
|
6390
6393
|
}
|
|
6391
6394
|
this.setPointersPositions(evt);
|
|
6392
|
-
|
|
6395
|
+
const eventsEnabled = !(Konva$2.isDragging() || Konva$2.isTransforming()) || Konva$2.hitOnDragEnabled;
|
|
6393
6396
|
if (!eventsEnabled) {
|
|
6394
6397
|
return;
|
|
6395
6398
|
}
|
|
6396
|
-
|
|
6399
|
+
const processedShapesIds = {};
|
|
6397
6400
|
let triggeredOnShape = false;
|
|
6398
|
-
|
|
6401
|
+
const targetShape = this._getTargetShape(eventType);
|
|
6399
6402
|
this._changedPointerPositions.forEach((pos) => {
|
|
6400
6403
|
const shape = (getCapturedShape(pos.id) ||
|
|
6401
6404
|
this.getIntersection(pos));
|
|
6402
6405
|
const pointerId = pos.id;
|
|
6403
6406
|
const event = { evt: evt, pointerId };
|
|
6404
|
-
|
|
6407
|
+
const differentTarget = targetShape !== shape;
|
|
6405
6408
|
if (differentTarget && targetShape) {
|
|
6406
6409
|
targetShape._fireAndBubble(events.pointerout, { ...event }, shape);
|
|
6407
6410
|
targetShape._fireAndBubble(events.pointerleave, { ...event }, shape);
|
|
@@ -6451,7 +6454,7 @@
|
|
|
6451
6454
|
this.setPointersPositions(evt);
|
|
6452
6455
|
const clickStartShape = this[eventType + 'ClickStartShape'];
|
|
6453
6456
|
const clickEndShape = this[eventType + 'ClickEndShape'];
|
|
6454
|
-
|
|
6457
|
+
const processedShapesIds = {};
|
|
6455
6458
|
let triggeredOnShape = false;
|
|
6456
6459
|
this._changedPointerPositions.forEach((pos) => {
|
|
6457
6460
|
const shape = (getCapturedShape(pos.id) ||
|
|
@@ -6532,7 +6535,7 @@
|
|
|
6532
6535
|
}
|
|
6533
6536
|
_contextmenu(evt) {
|
|
6534
6537
|
this.setPointersPositions(evt);
|
|
6535
|
-
|
|
6538
|
+
const shape = this.getIntersection(this.getPointerPosition());
|
|
6536
6539
|
if (shape && shape.isListening()) {
|
|
6537
6540
|
shape._fireAndBubble(CONTEXTMENU, { evt: evt });
|
|
6538
6541
|
}
|
|
@@ -6546,7 +6549,7 @@
|
|
|
6546
6549
|
}
|
|
6547
6550
|
_wheel(evt) {
|
|
6548
6551
|
this.setPointersPositions(evt);
|
|
6549
|
-
|
|
6552
|
+
const shape = this.getIntersection(this.getPointerPosition());
|
|
6550
6553
|
if (shape && shape.isListening()) {
|
|
6551
6554
|
shape._fireAndBubble(WHEEL, { evt: evt });
|
|
6552
6555
|
}
|
|
@@ -6585,7 +6588,7 @@
|
|
|
6585
6588
|
* });
|
|
6586
6589
|
*/
|
|
6587
6590
|
setPointersPositions(evt) {
|
|
6588
|
-
|
|
6591
|
+
let contentPosition = this._getContentPosition(), x = null, y = null;
|
|
6589
6592
|
evt = evt ? evt : window.event;
|
|
6590
6593
|
// touch events
|
|
6591
6594
|
if (evt.touches !== undefined) {
|
|
@@ -6635,7 +6638,7 @@
|
|
|
6635
6638
|
scaleY: 1,
|
|
6636
6639
|
};
|
|
6637
6640
|
}
|
|
6638
|
-
|
|
6641
|
+
const rect = this.content.getBoundingClientRect();
|
|
6639
6642
|
return {
|
|
6640
6643
|
top: rect.top,
|
|
6641
6644
|
left: rect.left,
|
|
@@ -6658,7 +6661,7 @@
|
|
|
6658
6661
|
if (!Konva$2.isBrowser) {
|
|
6659
6662
|
return;
|
|
6660
6663
|
}
|
|
6661
|
-
|
|
6664
|
+
const container = this.container();
|
|
6662
6665
|
if (!container) {
|
|
6663
6666
|
throw 'Stage has no container. A container is required.';
|
|
6664
6667
|
}
|
|
@@ -6722,11 +6725,11 @@
|
|
|
6722
6725
|
});
|
|
6723
6726
|
}
|
|
6724
6727
|
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6728
|
+
const HAS_SHADOW = 'hasShadow';
|
|
6729
|
+
const SHADOW_RGBA = 'shadowRGBA';
|
|
6730
|
+
const patternImage = 'patternImage';
|
|
6731
|
+
const linearGradient = 'linearGradient';
|
|
6732
|
+
const radialGradient = 'radialGradient';
|
|
6730
6733
|
let dummyContext$1;
|
|
6731
6734
|
function getDummyContext$1() {
|
|
6732
6735
|
if (dummyContext$1) {
|
|
@@ -6928,7 +6931,7 @@
|
|
|
6928
6931
|
}
|
|
6929
6932
|
__getFillPattern() {
|
|
6930
6933
|
if (this.fillPatternImage()) {
|
|
6931
|
-
|
|
6934
|
+
const ctx = getDummyContext$1();
|
|
6932
6935
|
const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
|
|
6933
6936
|
if (pattern && pattern.setTransform) {
|
|
6934
6937
|
const tr = new Transform();
|
|
@@ -6956,14 +6959,14 @@
|
|
|
6956
6959
|
return this._getCache(linearGradient, this.__getLinearGradient);
|
|
6957
6960
|
}
|
|
6958
6961
|
__getLinearGradient() {
|
|
6959
|
-
|
|
6962
|
+
const colorStops = this.fillLinearGradientColorStops();
|
|
6960
6963
|
if (colorStops) {
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6964
|
+
const ctx = getDummyContext$1();
|
|
6965
|
+
const start = this.fillLinearGradientStartPoint();
|
|
6966
|
+
const end = this.fillLinearGradientEndPoint();
|
|
6967
|
+
const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
6965
6968
|
// build color stops
|
|
6966
|
-
for (
|
|
6969
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
6967
6970
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
6968
6971
|
}
|
|
6969
6972
|
return grd;
|
|
@@ -6973,14 +6976,14 @@
|
|
|
6973
6976
|
return this._getCache(radialGradient, this.__getRadialGradient);
|
|
6974
6977
|
}
|
|
6975
6978
|
__getRadialGradient() {
|
|
6976
|
-
|
|
6979
|
+
const colorStops = this.fillRadialGradientColorStops();
|
|
6977
6980
|
if (colorStops) {
|
|
6978
|
-
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6981
|
+
const ctx = getDummyContext$1();
|
|
6982
|
+
const start = this.fillRadialGradientStartPoint();
|
|
6983
|
+
const end = this.fillRadialGradientEndPoint();
|
|
6984
|
+
const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
|
6982
6985
|
// build color stops
|
|
6983
|
-
for (
|
|
6986
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
6984
6987
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
6985
6988
|
}
|
|
6986
6989
|
return grd;
|
|
@@ -6993,7 +6996,7 @@
|
|
|
6993
6996
|
if (!this.hasShadow()) {
|
|
6994
6997
|
return;
|
|
6995
6998
|
}
|
|
6996
|
-
|
|
6999
|
+
const rgba = Util.colorToRGBA(this.shadowColor());
|
|
6997
7000
|
if (rgba) {
|
|
6998
7001
|
return ('rgba(' +
|
|
6999
7002
|
rgba.r +
|
|
@@ -7076,7 +7079,7 @@
|
|
|
7076
7079
|
* @returns {Boolean}
|
|
7077
7080
|
*/
|
|
7078
7081
|
intersects(point) {
|
|
7079
|
-
|
|
7082
|
+
const stage = this.getStage();
|
|
7080
7083
|
if (!stage) {
|
|
7081
7084
|
return false;
|
|
7082
7085
|
}
|
|
@@ -7148,7 +7151,7 @@
|
|
|
7148
7151
|
*
|
|
7149
7152
|
*/
|
|
7150
7153
|
getSelfRect() {
|
|
7151
|
-
|
|
7154
|
+
const size = this.size();
|
|
7152
7155
|
return {
|
|
7153
7156
|
x: this._centroid ? -size.width / 2 : 0,
|
|
7154
7157
|
y: this._centroid ? -size.height / 2 : 0,
|
|
@@ -7204,17 +7207,17 @@
|
|
|
7204
7207
|
// 1 - simple drawing when nothing is cached.
|
|
7205
7208
|
// 2 - when we are caching current
|
|
7206
7209
|
// 3 - when node is cached and we need to draw it into layer
|
|
7207
|
-
|
|
7208
|
-
|
|
7209
|
-
|
|
7210
|
-
|
|
7210
|
+
const layer = this.getLayer();
|
|
7211
|
+
let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
|
|
7212
|
+
const skipBuffer = canvas.isCache;
|
|
7213
|
+
const cachingSelf = top === this;
|
|
7211
7214
|
if (!this.isVisible() && !cachingSelf) {
|
|
7212
7215
|
return this;
|
|
7213
7216
|
}
|
|
7214
7217
|
// if node is cached we just need to draw from cache
|
|
7215
7218
|
if (cachedCanvas) {
|
|
7216
7219
|
context.save();
|
|
7217
|
-
|
|
7220
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
7218
7221
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
7219
7222
|
this._drawCachedSceneCanvas(context);
|
|
7220
7223
|
context.restore();
|
|
@@ -7237,7 +7240,7 @@
|
|
|
7237
7240
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7238
7241
|
drawFunc.call(this, bufferContext, this);
|
|
7239
7242
|
bufferContext.restore();
|
|
7240
|
-
|
|
7243
|
+
const ratio = bc.pixelRatio;
|
|
7241
7244
|
if (hasShadow) {
|
|
7242
7245
|
context._applyShadow(this);
|
|
7243
7246
|
}
|
|
@@ -7265,13 +7268,13 @@
|
|
|
7265
7268
|
if (!this.shouldDrawHit(top, skipDragCheck)) {
|
|
7266
7269
|
return this;
|
|
7267
7270
|
}
|
|
7268
|
-
|
|
7271
|
+
const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
|
7269
7272
|
if (!this.colorKey) {
|
|
7270
7273
|
Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()');
|
|
7271
7274
|
}
|
|
7272
7275
|
if (cachedHitCanvas) {
|
|
7273
7276
|
context.save();
|
|
7274
|
-
|
|
7277
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
7275
7278
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
7276
7279
|
this._drawCachedHitCanvas(context);
|
|
7277
7280
|
context.restore();
|
|
@@ -7284,7 +7287,7 @@
|
|
|
7284
7287
|
context._applyLineJoin(this);
|
|
7285
7288
|
const selfCache = this === top;
|
|
7286
7289
|
if (!selfCache) {
|
|
7287
|
-
|
|
7290
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
7288
7291
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
7289
7292
|
}
|
|
7290
7293
|
drawFunc.call(this, context, this);
|
|
@@ -7304,7 +7307,7 @@
|
|
|
7304
7307
|
* shape.drawHitFromCache();
|
|
7305
7308
|
*/
|
|
7306
7309
|
drawHitFromCache(alphaThreshold = 0) {
|
|
7307
|
-
|
|
7310
|
+
let cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
|
|
7308
7311
|
hitContext.clear();
|
|
7309
7312
|
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
|
7310
7313
|
try {
|
|
@@ -8368,7 +8371,7 @@
|
|
|
8368
8371
|
});
|
|
8369
8372
|
|
|
8370
8373
|
// constants
|
|
8371
|
-
|
|
8374
|
+
const HASH = '#', BEFORE_DRAW = 'beforeDraw', DRAW = 'draw',
|
|
8372
8375
|
/*
|
|
8373
8376
|
* 2 - 3 - 4
|
|
8374
8377
|
* | |
|
|
@@ -8483,7 +8486,7 @@
|
|
|
8483
8486
|
// extend Node.prototype.setZIndex
|
|
8484
8487
|
setZIndex(index) {
|
|
8485
8488
|
super.setZIndex(index);
|
|
8486
|
-
|
|
8489
|
+
const stage = this.getStage();
|
|
8487
8490
|
if (stage && stage.content) {
|
|
8488
8491
|
stage.content.removeChild(this.getNativeCanvasElement());
|
|
8489
8492
|
if (index < stage.children.length - 1) {
|
|
@@ -8497,7 +8500,7 @@
|
|
|
8497
8500
|
}
|
|
8498
8501
|
moveToTop() {
|
|
8499
8502
|
Node.prototype.moveToTop.call(this);
|
|
8500
|
-
|
|
8503
|
+
const stage = this.getStage();
|
|
8501
8504
|
if (stage && stage.content) {
|
|
8502
8505
|
stage.content.removeChild(this.getNativeCanvasElement());
|
|
8503
8506
|
stage.content.appendChild(this.getNativeCanvasElement());
|
|
@@ -8505,11 +8508,11 @@
|
|
|
8505
8508
|
return true;
|
|
8506
8509
|
}
|
|
8507
8510
|
moveUp() {
|
|
8508
|
-
|
|
8511
|
+
const moved = Node.prototype.moveUp.call(this);
|
|
8509
8512
|
if (!moved) {
|
|
8510
8513
|
return false;
|
|
8511
8514
|
}
|
|
8512
|
-
|
|
8515
|
+
const stage = this.getStage();
|
|
8513
8516
|
if (!stage || !stage.content) {
|
|
8514
8517
|
return false;
|
|
8515
8518
|
}
|
|
@@ -8525,9 +8528,9 @@
|
|
|
8525
8528
|
// extend Node.prototype.moveDown
|
|
8526
8529
|
moveDown() {
|
|
8527
8530
|
if (Node.prototype.moveDown.call(this)) {
|
|
8528
|
-
|
|
8531
|
+
const stage = this.getStage();
|
|
8529
8532
|
if (stage) {
|
|
8530
|
-
|
|
8533
|
+
const children = stage.children;
|
|
8531
8534
|
if (stage.content) {
|
|
8532
8535
|
stage.content.removeChild(this.getNativeCanvasElement());
|
|
8533
8536
|
stage.content.insertBefore(this.getNativeCanvasElement(), children[this.index + 1].getCanvas()._canvas);
|
|
@@ -8540,9 +8543,9 @@
|
|
|
8540
8543
|
// extend Node.prototype.moveToBottom
|
|
8541
8544
|
moveToBottom() {
|
|
8542
8545
|
if (Node.prototype.moveToBottom.call(this)) {
|
|
8543
|
-
|
|
8546
|
+
const stage = this.getStage();
|
|
8544
8547
|
if (stage) {
|
|
8545
|
-
|
|
8548
|
+
const children = stage.children;
|
|
8546
8549
|
if (stage.content) {
|
|
8547
8550
|
stage.content.removeChild(this.getNativeCanvasElement());
|
|
8548
8551
|
stage.content.insertBefore(this.getNativeCanvasElement(), children[1].getCanvas()._canvas);
|
|
@@ -8556,7 +8559,7 @@
|
|
|
8556
8559
|
return this;
|
|
8557
8560
|
}
|
|
8558
8561
|
remove() {
|
|
8559
|
-
|
|
8562
|
+
const _canvas = this.getNativeCanvasElement();
|
|
8560
8563
|
Node.prototype.remove.call(this);
|
|
8561
8564
|
if (_canvas && _canvas.parentNode && Util._isInDocument(_canvas)) {
|
|
8562
8565
|
_canvas.parentNode.removeChild(_canvas);
|
|
@@ -8573,7 +8576,7 @@
|
|
|
8573
8576
|
return this;
|
|
8574
8577
|
}
|
|
8575
8578
|
_validateAdd(child) {
|
|
8576
|
-
|
|
8579
|
+
const type = child.getType();
|
|
8577
8580
|
if (type !== 'Group' && type !== 'Shape') {
|
|
8578
8581
|
Util.throw('You may only add groups and shapes to a layer.');
|
|
8579
8582
|
}
|
|
@@ -8670,8 +8673,8 @@
|
|
|
8670
8673
|
}
|
|
8671
8674
|
// in some cases antialiased area may be bigger than 1px
|
|
8672
8675
|
// it is possible if we will cache node, then scale it a lot
|
|
8673
|
-
|
|
8674
|
-
|
|
8676
|
+
let spiralSearchDistance = 1;
|
|
8677
|
+
let continueSearch = false;
|
|
8675
8678
|
while (true) {
|
|
8676
8679
|
for (let i = 0; i < INTERSECTION_OFFSETS_LEN; i++) {
|
|
8677
8680
|
const intersectionOffset = INTERSECTION_OFFSETS[i];
|
|
@@ -8727,7 +8730,7 @@
|
|
|
8727
8730
|
return {};
|
|
8728
8731
|
}
|
|
8729
8732
|
drawScene(can, top) {
|
|
8730
|
-
|
|
8733
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
|
8731
8734
|
this._fire(BEFORE_DRAW, {
|
|
8732
8735
|
node: this,
|
|
8733
8736
|
});
|
|
@@ -8741,7 +8744,7 @@
|
|
|
8741
8744
|
return this;
|
|
8742
8745
|
}
|
|
8743
8746
|
drawHit(can, top) {
|
|
8744
|
-
|
|
8747
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas);
|
|
8745
8748
|
if (layer && layer.clearBeforeDraw()) {
|
|
8746
8749
|
layer.getHitCanvas().getContext().clear();
|
|
8747
8750
|
}
|
|
@@ -8785,8 +8788,8 @@
|
|
|
8785
8788
|
if (!this.parent || !this.parent['content']) {
|
|
8786
8789
|
return;
|
|
8787
8790
|
}
|
|
8788
|
-
|
|
8789
|
-
|
|
8791
|
+
const parent = this.parent;
|
|
8792
|
+
const added = !!this.hitCanvas._canvas.parentNode;
|
|
8790
8793
|
if (added) {
|
|
8791
8794
|
parent.content.removeChild(this.hitCanvas._canvas);
|
|
8792
8795
|
}
|
|
@@ -8923,7 +8926,7 @@
|
|
|
8923
8926
|
*/
|
|
8924
8927
|
class Group extends Container {
|
|
8925
8928
|
_validateAdd(child) {
|
|
8926
|
-
|
|
8929
|
+
const type = child.getType();
|
|
8927
8930
|
if (type !== 'Group' && type !== 'Shape') {
|
|
8928
8931
|
Util.throw('You may only add groups and shapes to groups.');
|
|
8929
8932
|
}
|
|
@@ -9120,7 +9123,7 @@
|
|
|
9120
9123
|
}
|
|
9121
9124
|
}
|
|
9122
9125
|
}
|
|
9123
|
-
for (
|
|
9126
|
+
for (const key in layerHash) {
|
|
9124
9127
|
if (!layerHash.hasOwnProperty(key)) {
|
|
9125
9128
|
continue;
|
|
9126
9129
|
}
|
|
@@ -9148,7 +9151,7 @@
|
|
|
9148
9151
|
Animation.animIdCounter = 0;
|
|
9149
9152
|
Animation.animRunning = false;
|
|
9150
9153
|
|
|
9151
|
-
|
|
9154
|
+
let blacklist = {
|
|
9152
9155
|
node: 1,
|
|
9153
9156
|
duration: 1,
|
|
9154
9157
|
easing: 1,
|
|
@@ -9174,7 +9177,7 @@
|
|
|
9174
9177
|
this.pause();
|
|
9175
9178
|
}
|
|
9176
9179
|
fire(str) {
|
|
9177
|
-
|
|
9180
|
+
const handler = this[str];
|
|
9178
9181
|
if (handler) {
|
|
9179
9182
|
handler();
|
|
9180
9183
|
}
|
|
@@ -9253,7 +9256,7 @@
|
|
|
9253
9256
|
this.fire('onUpdate');
|
|
9254
9257
|
}
|
|
9255
9258
|
onEnterFrame() {
|
|
9256
|
-
|
|
9259
|
+
const t = this.getTimer() - this._startTime;
|
|
9257
9260
|
if (this.state === PLAYING) {
|
|
9258
9261
|
this.setTime(t);
|
|
9259
9262
|
}
|
|
@@ -9297,7 +9300,7 @@
|
|
|
9297
9300
|
*/
|
|
9298
9301
|
class Tween {
|
|
9299
9302
|
constructor(config) {
|
|
9300
|
-
|
|
9303
|
+
let that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo, key;
|
|
9301
9304
|
if (typeof config.duration === 'undefined') {
|
|
9302
9305
|
duration = 0.3;
|
|
9303
9306
|
}
|
|
@@ -9310,7 +9313,7 @@
|
|
|
9310
9313
|
}
|
|
9311
9314
|
this.node = node;
|
|
9312
9315
|
this._id = idCounter++;
|
|
9313
|
-
|
|
9316
|
+
const layers = node.getLayer() ||
|
|
9314
9317
|
(node instanceof Konva$2['Stage'] ? node.getLayers() : null);
|
|
9315
9318
|
if (!layers) {
|
|
9316
9319
|
Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
|
|
@@ -9345,7 +9348,7 @@
|
|
|
9345
9348
|
this.onUpdate = config.onUpdate;
|
|
9346
9349
|
}
|
|
9347
9350
|
_addAttr(key, end) {
|
|
9348
|
-
|
|
9351
|
+
let node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
|
|
9349
9352
|
// remove conflict from tween map if it exists
|
|
9350
9353
|
tweenId = Tween.tweens[nodeId][key];
|
|
9351
9354
|
if (tweenId) {
|
|
@@ -9376,7 +9379,7 @@
|
|
|
9376
9379
|
diff.push(end[n] - start[n]);
|
|
9377
9380
|
}
|
|
9378
9381
|
else {
|
|
9379
|
-
|
|
9382
|
+
const startRGBA = Util.colorToRGBA(start[n]);
|
|
9380
9383
|
endRGBA = Util.colorToRGBA(end[n]);
|
|
9381
9384
|
start[n] = startRGBA;
|
|
9382
9385
|
diff.push({
|
|
@@ -9417,7 +9420,7 @@
|
|
|
9417
9420
|
Tween.tweens[nodeId][key] = this._id;
|
|
9418
9421
|
}
|
|
9419
9422
|
_tweenFunc(i) {
|
|
9420
|
-
|
|
9423
|
+
let node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
|
|
9421
9424
|
for (key in attrs) {
|
|
9422
9425
|
attr = attrs[key];
|
|
9423
9426
|
start = attr.start;
|
|
@@ -9481,9 +9484,9 @@
|
|
|
9481
9484
|
this.anim.stop();
|
|
9482
9485
|
};
|
|
9483
9486
|
this.tween.onFinish = () => {
|
|
9484
|
-
|
|
9487
|
+
const node = this.node;
|
|
9485
9488
|
// after tweening points of line we need to set original end
|
|
9486
|
-
|
|
9489
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
9487
9490
|
if (attrs.points && attrs.points.trueEnd) {
|
|
9488
9491
|
node.setAttr('points', attrs.points.trueEnd);
|
|
9489
9492
|
}
|
|
@@ -9492,9 +9495,9 @@
|
|
|
9492
9495
|
}
|
|
9493
9496
|
};
|
|
9494
9497
|
this.tween.onReset = () => {
|
|
9495
|
-
|
|
9498
|
+
const node = this.node;
|
|
9496
9499
|
// after tweening points of line we need to set original start
|
|
9497
|
-
|
|
9500
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
9498
9501
|
if (attrs.points && attrs.points.trueStart) {
|
|
9499
9502
|
node.points(attrs.points.trueStart);
|
|
9500
9503
|
}
|
|
@@ -9575,7 +9578,7 @@
|
|
|
9575
9578
|
* @name Konva.Tween#destroy
|
|
9576
9579
|
*/
|
|
9577
9580
|
destroy() {
|
|
9578
|
-
|
|
9581
|
+
let nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
|
|
9579
9582
|
this.pause();
|
|
9580
9583
|
for (key in attrs) {
|
|
9581
9584
|
delete Tween.tweens[nodeId][key];
|
|
@@ -9600,7 +9603,7 @@
|
|
|
9600
9603
|
* });
|
|
9601
9604
|
*/
|
|
9602
9605
|
Node.prototype.to = function (params) {
|
|
9603
|
-
|
|
9606
|
+
const onFinish = params.onFinish;
|
|
9604
9607
|
params.node = this;
|
|
9605
9608
|
params.onFinish = function () {
|
|
9606
9609
|
this.destroy();
|
|
@@ -9608,7 +9611,7 @@
|
|
|
9608
9611
|
onFinish();
|
|
9609
9612
|
}
|
|
9610
9613
|
};
|
|
9611
|
-
|
|
9614
|
+
const tween = new Tween(params);
|
|
9612
9615
|
tween.play();
|
|
9613
9616
|
};
|
|
9614
9617
|
/*
|
|
@@ -9626,7 +9629,7 @@
|
|
|
9626
9629
|
* @memberof Konva.Easings
|
|
9627
9630
|
*/
|
|
9628
9631
|
BackEaseIn(t, b, c, d) {
|
|
9629
|
-
|
|
9632
|
+
const s = 1.70158;
|
|
9630
9633
|
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
|
9631
9634
|
},
|
|
9632
9635
|
/**
|
|
@@ -9635,7 +9638,7 @@
|
|
|
9635
9638
|
* @memberof Konva.Easings
|
|
9636
9639
|
*/
|
|
9637
9640
|
BackEaseOut(t, b, c, d) {
|
|
9638
|
-
|
|
9641
|
+
const s = 1.70158;
|
|
9639
9642
|
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
|
9640
9643
|
},
|
|
9641
9644
|
/**
|
|
@@ -9644,7 +9647,7 @@
|
|
|
9644
9647
|
* @memberof Konva.Easings
|
|
9645
9648
|
*/
|
|
9646
9649
|
BackEaseInOut(t, b, c, d) {
|
|
9647
|
-
|
|
9650
|
+
let s = 1.70158;
|
|
9648
9651
|
if ((t /= d / 2) < 1) {
|
|
9649
9652
|
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
|
|
9650
9653
|
}
|
|
@@ -9657,7 +9660,7 @@
|
|
|
9657
9660
|
*/
|
|
9658
9661
|
ElasticEaseIn(t, b, c, d, a, p) {
|
|
9659
9662
|
// added s = 0
|
|
9660
|
-
|
|
9663
|
+
let s = 0;
|
|
9661
9664
|
if (t === 0) {
|
|
9662
9665
|
return b;
|
|
9663
9666
|
}
|
|
@@ -9685,7 +9688,7 @@
|
|
|
9685
9688
|
*/
|
|
9686
9689
|
ElasticEaseOut(t, b, c, d, a, p) {
|
|
9687
9690
|
// added s = 0
|
|
9688
|
-
|
|
9691
|
+
let s = 0;
|
|
9689
9692
|
if (t === 0) {
|
|
9690
9693
|
return b;
|
|
9691
9694
|
}
|
|
@@ -9713,7 +9716,7 @@
|
|
|
9713
9716
|
*/
|
|
9714
9717
|
ElasticEaseInOut(t, b, c, d, a, p) {
|
|
9715
9718
|
// added s = 0
|
|
9716
|
-
|
|
9719
|
+
let s = 0;
|
|
9717
9720
|
if (t === 0) {
|
|
9718
9721
|
return b;
|
|
9719
9722
|
}
|
|
@@ -9967,7 +9970,7 @@
|
|
|
9967
9970
|
*/
|
|
9968
9971
|
class Arc extends Shape {
|
|
9969
9972
|
_sceneFunc(context) {
|
|
9970
|
-
|
|
9973
|
+
const angle = Konva$2.getAngle(this.angle()), clockwise = this.clockwise();
|
|
9971
9974
|
context.beginPath();
|
|
9972
9975
|
context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
|
|
9973
9976
|
context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
|
|
@@ -10073,13 +10076,13 @@
|
|
|
10073
10076
|
*/
|
|
10074
10077
|
|
|
10075
10078
|
function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
|
|
10076
|
-
|
|
10079
|
+
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);
|
|
10077
10080
|
return [p1x, p1y, p2x, p2y];
|
|
10078
10081
|
}
|
|
10079
10082
|
function expandPoints(p, tension) {
|
|
10080
|
-
|
|
10081
|
-
for (n = 2; n < len - 2; n += 2) {
|
|
10082
|
-
cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
10083
|
+
const len = p.length, allPoints = [];
|
|
10084
|
+
for (let n = 2; n < len - 2; n += 2) {
|
|
10085
|
+
const cp = getControlPoints(p[n - 2], p[n - 1], p[n], p[n + 1], p[n + 2], p[n + 3], tension);
|
|
10083
10086
|
if (isNaN(cp[0])) {
|
|
10084
10087
|
continue;
|
|
10085
10088
|
}
|
|
@@ -10195,7 +10198,7 @@
|
|
|
10195
10198
|
});
|
|
10196
10199
|
}
|
|
10197
10200
|
_sceneFunc(context) {
|
|
10198
|
-
|
|
10201
|
+
let points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier(), tp, len, n;
|
|
10199
10202
|
if (!length) {
|
|
10200
10203
|
return;
|
|
10201
10204
|
}
|
|
@@ -10251,7 +10254,7 @@
|
|
|
10251
10254
|
}
|
|
10252
10255
|
}
|
|
10253
10256
|
_getTensionPointsClosed() {
|
|
10254
|
-
|
|
10257
|
+
const p = this.points(), len = p.length, tension = this.tension(), firstControlPoints = getControlPoints(p[len - 2], p[len - 1], p[0], p[1], p[2], p[3], tension), lastControlPoints = getControlPoints(p[len - 4], p[len - 3], p[len - 2], p[len - 1], p[0], p[1], tension), middle = expandPoints(p, tension), tp = [firstControlPoints[2], firstControlPoints[3]]
|
|
10255
10258
|
.concat(middle)
|
|
10256
10259
|
.concat([
|
|
10257
10260
|
lastControlPoints[0],
|
|
@@ -10275,7 +10278,7 @@
|
|
|
10275
10278
|
}
|
|
10276
10279
|
// overload size detection
|
|
10277
10280
|
getSelfRect() {
|
|
10278
|
-
|
|
10281
|
+
let points = this.points();
|
|
10279
10282
|
if (points.length < 4) {
|
|
10280
10283
|
return {
|
|
10281
10284
|
x: points[0] || 0,
|
|
@@ -10296,12 +10299,12 @@
|
|
|
10296
10299
|
else {
|
|
10297
10300
|
points = this.points();
|
|
10298
10301
|
}
|
|
10299
|
-
|
|
10300
|
-
|
|
10301
|
-
|
|
10302
|
-
|
|
10303
|
-
|
|
10304
|
-
for (
|
|
10302
|
+
let minX = points[0];
|
|
10303
|
+
let maxX = points[0];
|
|
10304
|
+
let minY = points[1];
|
|
10305
|
+
let maxY = points[1];
|
|
10306
|
+
let x, y;
|
|
10307
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
10305
10308
|
x = points[i * 2];
|
|
10306
10309
|
y = points[i * 2 + 1];
|
|
10307
10310
|
minX = Math.min(minX, x);
|
|
@@ -11074,14 +11077,13 @@
|
|
|
11074
11077
|
// LUT for binomial coefficient arrays per curve order 'n'
|
|
11075
11078
|
const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
|
|
11076
11079
|
const getCubicArcLength = (xs, ys, t) => {
|
|
11077
|
-
let z;
|
|
11078
11080
|
let sum;
|
|
11079
11081
|
let correctedT;
|
|
11080
11082
|
/*if (xs.length >= tValues.length) {
|
|
11081
11083
|
throw new Error('too high n bezier');
|
|
11082
11084
|
}*/
|
|
11083
11085
|
const n = 20;
|
|
11084
|
-
z = t / 2;
|
|
11086
|
+
const z = t / 2;
|
|
11085
11087
|
sum = 0;
|
|
11086
11088
|
for (let i = 0; i < n; i++) {
|
|
11087
11089
|
correctedT = z * tValues[n][i] + z;
|
|
@@ -11291,13 +11293,13 @@
|
|
|
11291
11293
|
this.pathLength = Path.getPathLength(this.dataArray);
|
|
11292
11294
|
}
|
|
11293
11295
|
_sceneFunc(context) {
|
|
11294
|
-
|
|
11296
|
+
const ca = this.dataArray;
|
|
11295
11297
|
// context position
|
|
11296
11298
|
context.beginPath();
|
|
11297
|
-
|
|
11298
|
-
for (
|
|
11299
|
-
|
|
11300
|
-
|
|
11299
|
+
let isClosed = false;
|
|
11300
|
+
for (let n = 0; n < ca.length; n++) {
|
|
11301
|
+
const c = ca[n].command;
|
|
11302
|
+
const p = ca[n].points;
|
|
11301
11303
|
switch (c) {
|
|
11302
11304
|
case 'L':
|
|
11303
11305
|
context.lineTo(p[0], p[1]);
|
|
@@ -11338,16 +11340,16 @@
|
|
|
11338
11340
|
}
|
|
11339
11341
|
}
|
|
11340
11342
|
getSelfRect() {
|
|
11341
|
-
|
|
11343
|
+
let points = [];
|
|
11342
11344
|
this.dataArray.forEach(function (data) {
|
|
11343
11345
|
if (data.command === 'A') {
|
|
11344
11346
|
// Approximates by breaking curve into line segments
|
|
11345
|
-
|
|
11347
|
+
const start = data.points[4];
|
|
11346
11348
|
// 4 = theta
|
|
11347
|
-
|
|
11349
|
+
const dTheta = data.points[5];
|
|
11348
11350
|
// 5 = dTheta
|
|
11349
|
-
|
|
11350
|
-
|
|
11351
|
+
const end = data.points[4] + dTheta;
|
|
11352
|
+
let inc = Math.PI / 180.0;
|
|
11351
11353
|
// 1 degree resolution
|
|
11352
11354
|
if (Math.abs(start - end) < inc) {
|
|
11353
11355
|
inc = Math.abs(start - end);
|
|
@@ -11379,12 +11381,12 @@
|
|
|
11379
11381
|
points = points.concat(data.points);
|
|
11380
11382
|
}
|
|
11381
11383
|
});
|
|
11382
|
-
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
for (
|
|
11384
|
+
let minX = points[0];
|
|
11385
|
+
let maxX = points[0];
|
|
11386
|
+
let minY = points[1];
|
|
11387
|
+
let maxY = points[1];
|
|
11388
|
+
let x, y;
|
|
11389
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
11388
11390
|
x = points[i * 2];
|
|
11389
11391
|
y = points[i * 2 + 1];
|
|
11390
11392
|
// skip bad values
|
|
@@ -11432,13 +11434,13 @@
|
|
|
11432
11434
|
}
|
|
11433
11435
|
static getPathLength(dataArray) {
|
|
11434
11436
|
let pathLength = 0;
|
|
11435
|
-
for (
|
|
11437
|
+
for (let i = 0; i < dataArray.length; ++i) {
|
|
11436
11438
|
pathLength += dataArray[i].pathLength;
|
|
11437
11439
|
}
|
|
11438
11440
|
return pathLength;
|
|
11439
11441
|
}
|
|
11440
11442
|
static getPointAtLengthOfDataArray(length, dataArray) {
|
|
11441
|
-
|
|
11443
|
+
let points, i = 0, ii = dataArray.length;
|
|
11442
11444
|
if (!ii) {
|
|
11443
11445
|
return null;
|
|
11444
11446
|
}
|
|
@@ -11447,21 +11449,21 @@
|
|
|
11447
11449
|
++i;
|
|
11448
11450
|
}
|
|
11449
11451
|
if (i === ii) {
|
|
11450
|
-
|
|
11452
|
+
points = dataArray[i - 1].points.slice(-2);
|
|
11451
11453
|
return {
|
|
11452
|
-
x:
|
|
11453
|
-
y:
|
|
11454
|
+
x: points[0],
|
|
11455
|
+
y: points[1],
|
|
11454
11456
|
};
|
|
11455
11457
|
}
|
|
11456
11458
|
if (length < 0.01) {
|
|
11457
|
-
|
|
11459
|
+
points = dataArray[i].points.slice(0, 2);
|
|
11458
11460
|
return {
|
|
11459
|
-
x:
|
|
11460
|
-
y:
|
|
11461
|
+
x: points[0],
|
|
11462
|
+
y: points[1],
|
|
11461
11463
|
};
|
|
11462
11464
|
}
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
+
const cp = dataArray[i];
|
|
11466
|
+
const p = cp.points;
|
|
11465
11467
|
switch (cp.command) {
|
|
11466
11468
|
case 'L':
|
|
11467
11469
|
return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
|
|
@@ -11519,8 +11521,8 @@
|
|
|
11519
11521
|
function CB4(t) {
|
|
11520
11522
|
return (1 - t) * (1 - t) * (1 - t);
|
|
11521
11523
|
}
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
+
const x = P4x * CB1(pct) + P3x * CB2(pct) + P2x * CB3(pct) + P1x * CB4(pct);
|
|
11525
|
+
const y = P4y * CB1(pct) + P3y * CB2(pct) + P2y * CB3(pct) + P1y * CB4(pct);
|
|
11524
11526
|
return {
|
|
11525
11527
|
x: x,
|
|
11526
11528
|
y: y,
|
|
@@ -11536,16 +11538,16 @@
|
|
|
11536
11538
|
function QB3(t) {
|
|
11537
11539
|
return (1 - t) * (1 - t);
|
|
11538
11540
|
}
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
+
const x = P3x * QB1(pct) + P2x * QB2(pct) + P1x * QB3(pct);
|
|
11542
|
+
const y = P3y * QB1(pct) + P2y * QB2(pct) + P1y * QB3(pct);
|
|
11541
11543
|
return {
|
|
11542
11544
|
x: x,
|
|
11543
11545
|
y: y,
|
|
11544
11546
|
};
|
|
11545
11547
|
}
|
|
11546
11548
|
static getPointOnEllipticalArc(cx, cy, rx, ry, theta, psi) {
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
+
const cosPsi = Math.cos(psi), sinPsi = Math.sin(psi);
|
|
11550
|
+
const pt = {
|
|
11549
11551
|
x: rx * Math.cos(theta),
|
|
11550
11552
|
y: ry * Math.sin(theta),
|
|
11551
11553
|
};
|
|
@@ -11587,9 +11589,9 @@
|
|
|
11587
11589
|
return [];
|
|
11588
11590
|
}
|
|
11589
11591
|
// command string
|
|
11590
|
-
|
|
11592
|
+
let cs = data;
|
|
11591
11593
|
// command chars
|
|
11592
|
-
|
|
11594
|
+
const cc = [
|
|
11593
11595
|
'm',
|
|
11594
11596
|
'M',
|
|
11595
11597
|
'l',
|
|
@@ -11618,17 +11620,17 @@
|
|
|
11618
11620
|
cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
|
|
11619
11621
|
}
|
|
11620
11622
|
// create array
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11623
|
+
const arr = cs.split('|');
|
|
11624
|
+
const ca = [];
|
|
11625
|
+
const coords = [];
|
|
11624
11626
|
// init context point
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11627
|
+
let cpx = 0;
|
|
11628
|
+
let cpy = 0;
|
|
11629
|
+
const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
|
11630
|
+
let match;
|
|
11629
11631
|
for (n = 1; n < arr.length; n++) {
|
|
11630
|
-
|
|
11631
|
-
|
|
11632
|
+
let str = arr[n];
|
|
11633
|
+
let c = str.charAt(0);
|
|
11632
11634
|
str = str.slice(1);
|
|
11633
11635
|
coords.length = 0;
|
|
11634
11636
|
while ((match = re.exec(str))) {
|
|
@@ -11637,14 +11639,14 @@
|
|
|
11637
11639
|
// while ((match = re.exec(str))) {
|
|
11638
11640
|
// coords.push(match[0]);
|
|
11639
11641
|
// }
|
|
11640
|
-
|
|
11641
|
-
for (
|
|
11642
|
+
const p = [];
|
|
11643
|
+
for (let j = 0, jlen = coords.length; j < jlen; j++) {
|
|
11642
11644
|
// extra case for merged flags
|
|
11643
11645
|
if (coords[j] === '00') {
|
|
11644
11646
|
p.push(0, 0);
|
|
11645
11647
|
continue;
|
|
11646
11648
|
}
|
|
11647
|
-
|
|
11649
|
+
const parsed = parseFloat(coords[j]);
|
|
11648
11650
|
if (!isNaN(parsed)) {
|
|
11649
11651
|
p.push(parsed);
|
|
11650
11652
|
}
|
|
@@ -11657,9 +11659,9 @@
|
|
|
11657
11659
|
// case for a trailing comma before next command
|
|
11658
11660
|
break;
|
|
11659
11661
|
}
|
|
11660
|
-
|
|
11661
|
-
|
|
11662
|
-
|
|
11662
|
+
let cmd = '';
|
|
11663
|
+
let points = [];
|
|
11664
|
+
const startX = cpx, startY = cpy;
|
|
11663
11665
|
// Move var from within the switch to up here (jshint)
|
|
11664
11666
|
var prevCmd, ctlPtx, ctlPty; // Ss, Tt
|
|
11665
11667
|
var rx, ry, psi, fa, fs, x1, y1; // Aa
|
|
@@ -11687,7 +11689,7 @@
|
|
|
11687
11689
|
// After closing the path move the current position
|
|
11688
11690
|
// to the the first point of the path (if any).
|
|
11689
11691
|
if (ca.length > 2 && ca[ca.length - 1].command === 'z') {
|
|
11690
|
-
for (
|
|
11692
|
+
for (let idx = ca.length - 2; idx >= 0; idx--) {
|
|
11691
11693
|
if (ca[idx].command === 'M') {
|
|
11692
11694
|
cpx = ca[idx].points[0] + dx;
|
|
11693
11695
|
cpy = ca[idx].points[1] + dy;
|
|
@@ -11856,8 +11858,8 @@
|
|
|
11856
11858
|
return ca;
|
|
11857
11859
|
}
|
|
11858
11860
|
static calcLength(x, y, cmd, points) {
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
+
let len, p1, p2, t;
|
|
11862
|
+
const path = Path;
|
|
11861
11863
|
switch (cmd) {
|
|
11862
11864
|
case 'L':
|
|
11863
11865
|
return path.getLineLength(x, y, points[0], points[1]);
|
|
@@ -11904,16 +11906,16 @@
|
|
|
11904
11906
|
}
|
|
11905
11907
|
static convertEndpointToCenterParameterization(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg) {
|
|
11906
11908
|
// Derived from: http://www.w3.org/TR/SVG/implnote.html#ArcImplementationNotes
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11909
|
+
const psi = psiDeg * (Math.PI / 180.0);
|
|
11910
|
+
const xp = (Math.cos(psi) * (x1 - x2)) / 2.0 + (Math.sin(psi) * (y1 - y2)) / 2.0;
|
|
11911
|
+
const yp = (-1 * Math.sin(psi) * (x1 - x2)) / 2.0 +
|
|
11910
11912
|
(Math.cos(psi) * (y1 - y2)) / 2.0;
|
|
11911
|
-
|
|
11913
|
+
const lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
|
|
11912
11914
|
if (lambda > 1) {
|
|
11913
11915
|
rx *= Math.sqrt(lambda);
|
|
11914
11916
|
ry *= Math.sqrt(lambda);
|
|
11915
11917
|
}
|
|
11916
|
-
|
|
11918
|
+
let f = Math.sqrt((rx * rx * (ry * ry) - rx * rx * (yp * yp) - ry * ry * (xp * xp)) /
|
|
11917
11919
|
(rx * rx * (yp * yp) + ry * ry * (xp * xp)));
|
|
11918
11920
|
if (fa === fs) {
|
|
11919
11921
|
f *= -1;
|
|
@@ -11921,23 +11923,23 @@
|
|
|
11921
11923
|
if (isNaN(f)) {
|
|
11922
11924
|
f = 0;
|
|
11923
11925
|
}
|
|
11924
|
-
|
|
11925
|
-
|
|
11926
|
-
|
|
11927
|
-
|
|
11928
|
-
|
|
11926
|
+
const cxp = (f * rx * yp) / ry;
|
|
11927
|
+
const cyp = (f * -ry * xp) / rx;
|
|
11928
|
+
const cx = (x1 + x2) / 2.0 + Math.cos(psi) * cxp - Math.sin(psi) * cyp;
|
|
11929
|
+
const cy = (y1 + y2) / 2.0 + Math.sin(psi) * cxp + Math.cos(psi) * cyp;
|
|
11930
|
+
const vMag = function (v) {
|
|
11929
11931
|
return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
11930
11932
|
};
|
|
11931
|
-
|
|
11933
|
+
const vRatio = function (u, v) {
|
|
11932
11934
|
return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
|
|
11933
11935
|
};
|
|
11934
|
-
|
|
11936
|
+
const vAngle = function (u, v) {
|
|
11935
11937
|
return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
|
|
11936
11938
|
};
|
|
11937
|
-
|
|
11938
|
-
|
|
11939
|
-
|
|
11940
|
-
|
|
11939
|
+
const theta = vAngle([1, 0], [(xp - cxp) / rx, (yp - cyp) / ry]);
|
|
11940
|
+
const u = [(xp - cxp) / rx, (yp - cyp) / ry];
|
|
11941
|
+
const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
|
|
11942
|
+
let dTheta = vAngle(u, v);
|
|
11941
11943
|
if (vRatio(u, v) <= -1) {
|
|
11942
11944
|
dTheta = Math.PI;
|
|
11943
11945
|
}
|
|
@@ -12073,16 +12075,16 @@
|
|
|
12073
12075
|
class Arrow extends Line {
|
|
12074
12076
|
_sceneFunc(ctx) {
|
|
12075
12077
|
super._sceneFunc(ctx);
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
|
|
12079
|
-
|
|
12078
|
+
const PI2 = Math.PI * 2;
|
|
12079
|
+
const points = this.points();
|
|
12080
|
+
let tp = points;
|
|
12081
|
+
const fromTension = this.tension() !== 0 && points.length > 4;
|
|
12080
12082
|
if (fromTension) {
|
|
12081
12083
|
tp = this.getTensionPoints();
|
|
12082
12084
|
}
|
|
12083
|
-
|
|
12084
|
-
|
|
12085
|
-
|
|
12085
|
+
const length = this.pointerLength();
|
|
12086
|
+
const n = points.length;
|
|
12087
|
+
let dx, dy;
|
|
12086
12088
|
if (fromTension) {
|
|
12087
12089
|
const lp = [
|
|
12088
12090
|
tp[tp.length - 4],
|
|
@@ -12101,8 +12103,8 @@
|
|
|
12101
12103
|
dx = points[n - 2] - points[n - 4];
|
|
12102
12104
|
dy = points[n - 1] - points[n - 3];
|
|
12103
12105
|
}
|
|
12104
|
-
|
|
12105
|
-
|
|
12106
|
+
const radians = (Math.atan2(dy, dx) + PI2) % PI2;
|
|
12107
|
+
const width = this.pointerWidth();
|
|
12106
12108
|
if (this.pointerAtEnding()) {
|
|
12107
12109
|
ctx.save();
|
|
12108
12110
|
ctx.beginPath();
|
|
@@ -12139,7 +12141,7 @@
|
|
|
12139
12141
|
__fillStroke(ctx) {
|
|
12140
12142
|
// here is a tricky part
|
|
12141
12143
|
// we need to disable dash for arrow pointers
|
|
12142
|
-
|
|
12144
|
+
const isDashEnabled = this.dashEnabled();
|
|
12143
12145
|
if (isDashEnabled) {
|
|
12144
12146
|
// manually disable dash for head
|
|
12145
12147
|
// it is better not to use setter here,
|
|
@@ -12449,7 +12451,7 @@
|
|
|
12449
12451
|
*/
|
|
12450
12452
|
class Ellipse extends Shape {
|
|
12451
12453
|
_sceneFunc(context) {
|
|
12452
|
-
|
|
12454
|
+
const rx = this.radiusX(), ry = this.radiusY();
|
|
12453
12455
|
context.beginPath();
|
|
12454
12456
|
context.save();
|
|
12455
12457
|
if (rx !== ry) {
|
|
@@ -12696,7 +12698,7 @@
|
|
|
12696
12698
|
// If you need to draw later, you need to execute save/restore
|
|
12697
12699
|
}
|
|
12698
12700
|
_hitFunc(context) {
|
|
12699
|
-
|
|
12701
|
+
const width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
12700
12702
|
context.beginPath();
|
|
12701
12703
|
if (!cornerRadius) {
|
|
12702
12704
|
context.rect(0, 0, width, height);
|
|
@@ -12730,9 +12732,9 @@
|
|
|
12730
12732
|
* });
|
|
12731
12733
|
*/
|
|
12732
12734
|
static fromURL(url, callback, onError = null) {
|
|
12733
|
-
|
|
12735
|
+
const img = Util.createImageElement();
|
|
12734
12736
|
img.onload = function () {
|
|
12735
|
-
|
|
12737
|
+
const image = new Image({
|
|
12736
12738
|
image: img,
|
|
12737
12739
|
});
|
|
12738
12740
|
callback(image);
|
|
@@ -12857,7 +12859,7 @@
|
|
|
12857
12859
|
*/
|
|
12858
12860
|
|
|
12859
12861
|
// constants
|
|
12860
|
-
|
|
12862
|
+
const ATTR_CHANGE_LIST$2 = [
|
|
12861
12863
|
'fontFamily',
|
|
12862
12864
|
'fontSize',
|
|
12863
12865
|
'fontStyle',
|
|
@@ -12958,8 +12960,8 @@
|
|
|
12958
12960
|
return this.find('Tag')[0];
|
|
12959
12961
|
}
|
|
12960
12962
|
_addListeners(text) {
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
+
let that = this, n;
|
|
12964
|
+
const func = function () {
|
|
12963
12965
|
that._sync();
|
|
12964
12966
|
};
|
|
12965
12967
|
// update text data for certain attr changes
|
|
@@ -12974,7 +12976,7 @@
|
|
|
12974
12976
|
return this.getText().height();
|
|
12975
12977
|
}
|
|
12976
12978
|
_sync() {
|
|
12977
|
-
|
|
12979
|
+
let text = this.getText(), tag = this.getTag(), width, height, pointerDirection, pointerWidth, x, y, pointerHeight;
|
|
12978
12980
|
if (text && tag) {
|
|
12979
12981
|
width = text.width();
|
|
12980
12982
|
height = text.height();
|
|
@@ -13030,7 +13032,7 @@
|
|
|
13030
13032
|
*/
|
|
13031
13033
|
class Tag extends Shape {
|
|
13032
13034
|
_sceneFunc(context) {
|
|
13033
|
-
|
|
13035
|
+
const width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
|
|
13034
13036
|
let topLeft = 0;
|
|
13035
13037
|
let topRight = 0;
|
|
13036
13038
|
let bottomLeft = 0;
|
|
@@ -13082,7 +13084,7 @@
|
|
|
13082
13084
|
context.fillStrokeShape(this);
|
|
13083
13085
|
}
|
|
13084
13086
|
getSelfRect() {
|
|
13085
|
-
|
|
13087
|
+
let x = 0, y = 0, pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), direction = this.pointerDirection(), width = this.width(), height = this.height();
|
|
13086
13088
|
if (direction === UP) {
|
|
13087
13089
|
y -= pointerHeight;
|
|
13088
13090
|
height += pointerHeight;
|
|
@@ -13245,7 +13247,7 @@
|
|
|
13245
13247
|
*/
|
|
13246
13248
|
class Rect extends Shape {
|
|
13247
13249
|
_sceneFunc(context) {
|
|
13248
|
-
|
|
13250
|
+
const cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
|
|
13249
13251
|
context.beginPath();
|
|
13250
13252
|
if (!cornerRadius) {
|
|
13251
13253
|
// simple rect - don't bother doing all that complicated maths stuff.
|
|
@@ -13377,7 +13379,7 @@
|
|
|
13377
13379
|
const points = this._getPoints();
|
|
13378
13380
|
context.beginPath();
|
|
13379
13381
|
context.moveTo(points[0].x, points[0].y);
|
|
13380
|
-
for (
|
|
13382
|
+
for (let n = 1; n < points.length; n++) {
|
|
13381
13383
|
context.lineTo(points[n].x, points[n].y);
|
|
13382
13384
|
}
|
|
13383
13385
|
context.closePath();
|
|
@@ -13387,7 +13389,7 @@
|
|
|
13387
13389
|
const sides = this.attrs.sides;
|
|
13388
13390
|
const radius = this.attrs.radius || 0;
|
|
13389
13391
|
const points = [];
|
|
13390
|
-
for (
|
|
13392
|
+
for (let n = 0; n < sides; n++) {
|
|
13391
13393
|
points.push({
|
|
13392
13394
|
x: radius * Math.sin((n * 2 * Math.PI) / sides),
|
|
13393
13395
|
y: -1 * radius * Math.cos((n * 2 * Math.PI) / sides),
|
|
@@ -13397,10 +13399,10 @@
|
|
|
13397
13399
|
}
|
|
13398
13400
|
getSelfRect() {
|
|
13399
13401
|
const points = this._getPoints();
|
|
13400
|
-
|
|
13401
|
-
|
|
13402
|
-
|
|
13403
|
-
|
|
13402
|
+
let minX = points[0].x;
|
|
13403
|
+
let maxX = points[0].y;
|
|
13404
|
+
let minY = points[0].x;
|
|
13405
|
+
let maxY = points[0].y;
|
|
13404
13406
|
points.forEach((point) => {
|
|
13405
13407
|
minX = Math.min(minX, point.x);
|
|
13406
13408
|
maxX = Math.max(maxX, point.x);
|
|
@@ -13460,7 +13462,7 @@
|
|
|
13460
13462
|
*/
|
|
13461
13463
|
Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
|
|
13462
13464
|
|
|
13463
|
-
|
|
13465
|
+
const PIx2 = Math.PI * 2;
|
|
13464
13466
|
/**
|
|
13465
13467
|
* Ring constructor
|
|
13466
13468
|
* @constructor
|
|
@@ -13732,7 +13734,7 @@
|
|
|
13732
13734
|
this._updated = true;
|
|
13733
13735
|
this.anim = new Animation(() => {
|
|
13734
13736
|
// if we don't need to redraw layer we should return false
|
|
13735
|
-
|
|
13737
|
+
const updated = this._updated;
|
|
13736
13738
|
this._updated = false;
|
|
13737
13739
|
return updated;
|
|
13738
13740
|
});
|
|
@@ -13753,7 +13755,7 @@
|
|
|
13753
13755
|
});
|
|
13754
13756
|
}
|
|
13755
13757
|
_sceneFunc(context) {
|
|
13756
|
-
|
|
13758
|
+
const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), x = set[ix4 + 0], y = set[ix4 + 1], width = set[ix4 + 2], height = set[ix4 + 3], image = this.image();
|
|
13757
13759
|
if (this.hasFill() || this.hasStroke()) {
|
|
13758
13760
|
context.beginPath();
|
|
13759
13761
|
context.rect(0, 0, width, height);
|
|
@@ -13762,7 +13764,7 @@
|
|
|
13762
13764
|
}
|
|
13763
13765
|
if (image) {
|
|
13764
13766
|
if (offsets) {
|
|
13765
|
-
|
|
13767
|
+
const offset = offsets[anim], ix2 = index * 2;
|
|
13766
13768
|
context.drawImage(image, x, y, width, height, offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
13767
13769
|
}
|
|
13768
13770
|
else {
|
|
@@ -13771,11 +13773,11 @@
|
|
|
13771
13773
|
}
|
|
13772
13774
|
}
|
|
13773
13775
|
_hitFunc(context) {
|
|
13774
|
-
|
|
13776
|
+
const anim = this.animation(), index = this.frameIndex(), ix4 = index * 4, set = this.animations()[anim], offsets = this.frameOffsets(), width = set[ix4 + 2], height = set[ix4 + 3];
|
|
13775
13777
|
context.beginPath();
|
|
13776
13778
|
if (offsets) {
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
+
const offset = offsets[anim];
|
|
13780
|
+
const ix2 = index * 2;
|
|
13779
13781
|
context.rect(offset[ix2 + 0], offset[ix2 + 1], width, height);
|
|
13780
13782
|
}
|
|
13781
13783
|
else {
|
|
@@ -13788,7 +13790,7 @@
|
|
|
13788
13790
|
return super._useBufferCanvas(true);
|
|
13789
13791
|
}
|
|
13790
13792
|
_setInterval() {
|
|
13791
|
-
|
|
13793
|
+
const that = this;
|
|
13792
13794
|
this.interval = setInterval(function () {
|
|
13793
13795
|
that._updateIndex();
|
|
13794
13796
|
}, 1000 / this.frameRate());
|
|
@@ -13802,7 +13804,7 @@
|
|
|
13802
13804
|
if (this.isRunning()) {
|
|
13803
13805
|
return;
|
|
13804
13806
|
}
|
|
13805
|
-
|
|
13807
|
+
const layer = this.getLayer();
|
|
13806
13808
|
/*
|
|
13807
13809
|
* animation object has no executable function because
|
|
13808
13810
|
* the updates are done with a fixed FPS with the setInterval
|
|
@@ -13832,7 +13834,7 @@
|
|
|
13832
13834
|
return this.anim.isRunning();
|
|
13833
13835
|
}
|
|
13834
13836
|
_updateIndex() {
|
|
13835
|
-
|
|
13837
|
+
const index = this.frameIndex(), animation = this.animation(), animations = this.animations(), anim = animations[animation], len = anim.length / 4;
|
|
13836
13838
|
if (index < len - 1) {
|
|
13837
13839
|
this.frameIndex(index + 1);
|
|
13838
13840
|
}
|
|
@@ -14071,13 +14073,13 @@
|
|
|
14071
14073
|
*/
|
|
14072
14074
|
class Star extends Shape {
|
|
14073
14075
|
_sceneFunc(context) {
|
|
14074
|
-
|
|
14076
|
+
const innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
|
|
14075
14077
|
context.beginPath();
|
|
14076
14078
|
context.moveTo(0, 0 - outerRadius);
|
|
14077
|
-
for (
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14079
|
+
for (let n = 1; n < numPoints * 2; n++) {
|
|
14080
|
+
const radius = n % 2 === 0 ? outerRadius : innerRadius;
|
|
14081
|
+
const x = radius * Math.sin((n * Math.PI) / numPoints);
|
|
14082
|
+
const y = -1 * radius * Math.cos((n * Math.PI) / numPoints);
|
|
14081
14083
|
context.lineTo(x, y);
|
|
14082
14084
|
}
|
|
14083
14085
|
context.closePath();
|
|
@@ -14144,14 +14146,29 @@
|
|
|
14144
14146
|
Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator());
|
|
14145
14147
|
|
|
14146
14148
|
function stringToArray(string) {
|
|
14147
|
-
//
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
|
|
14149
|
+
// Use Unicode-aware splitting
|
|
14150
|
+
return [...string].reduce((acc, char, index, array) => {
|
|
14151
|
+
// Handle emoji sequences (including ZWJ sequences)
|
|
14152
|
+
if (/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?(?:\u200D\p{Emoji_Presentation})+/u.test(char)) {
|
|
14153
|
+
acc.push(char);
|
|
14154
|
+
}
|
|
14155
|
+
// Handle regional indicator symbols (flags)
|
|
14156
|
+
else if (/\p{Regional_Indicator}{2}/u.test(char + (array[index + 1] || ''))) {
|
|
14157
|
+
acc.push(char + array[index + 1]);
|
|
14158
|
+
}
|
|
14159
|
+
// Handle Indic scripts and other combining characters
|
|
14160
|
+
else if (index > 0 && /\p{Mn}|\p{Me}|\p{Mc}/u.test(char)) {
|
|
14161
|
+
acc[acc.length - 1] += char;
|
|
14162
|
+
}
|
|
14163
|
+
// Handle other characters
|
|
14164
|
+
else {
|
|
14165
|
+
acc.push(char);
|
|
14166
|
+
}
|
|
14167
|
+
return acc;
|
|
14168
|
+
}, []);
|
|
14152
14169
|
}
|
|
14153
14170
|
// constants
|
|
14154
|
-
|
|
14171
|
+
const AUTO = 'auto',
|
|
14155
14172
|
//CANVAS = 'canvas',
|
|
14156
14173
|
CENTER = 'center', INHERIT = 'inherit', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL$1 = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', RTL = 'rtl', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST$1 = [
|
|
14157
14174
|
'direction',
|
|
@@ -14186,7 +14203,7 @@
|
|
|
14186
14203
|
})
|
|
14187
14204
|
.join(', ');
|
|
14188
14205
|
}
|
|
14189
|
-
|
|
14206
|
+
let dummyContext;
|
|
14190
14207
|
function getDummyContext() {
|
|
14191
14208
|
if (dummyContext) {
|
|
14192
14209
|
return dummyContext;
|
|
@@ -14320,22 +14337,22 @@
|
|
|
14320
14337
|
this._partialTextX = 0;
|
|
14321
14338
|
this._partialTextY = 0;
|
|
14322
14339
|
// update text data for certain attr changes
|
|
14323
|
-
for (
|
|
14340
|
+
for (let n = 0; n < attrChangeListLen; n++) {
|
|
14324
14341
|
this.on(ATTR_CHANGE_LIST$1[n] + CHANGE_KONVA, this._setTextData);
|
|
14325
14342
|
}
|
|
14326
14343
|
this._setTextData();
|
|
14327
14344
|
}
|
|
14328
14345
|
_sceneFunc(context) {
|
|
14329
|
-
|
|
14346
|
+
const textArr = this.textArr, textArrLen = textArr.length;
|
|
14330
14347
|
if (!this.text()) {
|
|
14331
14348
|
return;
|
|
14332
14349
|
}
|
|
14333
|
-
|
|
14350
|
+
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
14334
14351
|
direction = direction === INHERIT ? context.direction : direction;
|
|
14335
|
-
|
|
14336
|
-
|
|
14352
|
+
let translateY = lineHeightPx / 2;
|
|
14353
|
+
let baseline = MIDDLE;
|
|
14337
14354
|
if (Konva$2._fixTextRendering) {
|
|
14338
|
-
|
|
14355
|
+
const metrics = this.measureSize('M'); // Use a sample character to get the ascent
|
|
14339
14356
|
baseline = 'alphabetic';
|
|
14340
14357
|
translateY =
|
|
14341
14358
|
(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
|
|
@@ -14373,7 +14390,7 @@
|
|
|
14373
14390
|
if (shouldUnderline) {
|
|
14374
14391
|
context.save();
|
|
14375
14392
|
context.beginPath();
|
|
14376
|
-
|
|
14393
|
+
const yOffset = Konva$2._fixTextRendering
|
|
14377
14394
|
? Math.round(fontSize / 4)
|
|
14378
14395
|
: Math.round(fontSize / 2);
|
|
14379
14396
|
const x = lineTranslateX;
|
|
@@ -14395,7 +14412,7 @@
|
|
|
14395
14412
|
if (shouldLineThrough) {
|
|
14396
14413
|
context.save();
|
|
14397
14414
|
context.beginPath();
|
|
14398
|
-
|
|
14415
|
+
const yOffset = Konva$2._fixTextRendering ? -Math.round(fontSize / 4) : 0;
|
|
14399
14416
|
context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
|
|
14400
14417
|
spacesNumber = text.split(' ').length - 1;
|
|
14401
14418
|
oneWord = spacesNumber === 0;
|
|
@@ -14416,9 +14433,9 @@
|
|
|
14416
14433
|
if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
|
|
14417
14434
|
// var words = text.split(' ');
|
|
14418
14435
|
spacesNumber = text.split(' ').length - 1;
|
|
14419
|
-
|
|
14420
|
-
for (
|
|
14421
|
-
|
|
14436
|
+
const array = stringToArray(text);
|
|
14437
|
+
for (let li = 0; li < array.length; li++) {
|
|
14438
|
+
const letter = array[li];
|
|
14422
14439
|
// skip justify for the last line
|
|
14423
14440
|
if (letter === ' ' && !lastLine && align === JUSTIFY) {
|
|
14424
14441
|
lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
|
|
@@ -14450,14 +14467,14 @@
|
|
|
14450
14467
|
}
|
|
14451
14468
|
}
|
|
14452
14469
|
_hitFunc(context) {
|
|
14453
|
-
|
|
14470
|
+
const width = this.getWidth(), height = this.getHeight();
|
|
14454
14471
|
context.beginPath();
|
|
14455
14472
|
context.rect(0, 0, width, height);
|
|
14456
14473
|
context.closePath();
|
|
14457
14474
|
context.fillStrokeShape(this);
|
|
14458
14475
|
}
|
|
14459
14476
|
setText(text) {
|
|
14460
|
-
|
|
14477
|
+
const str = Util._isString(text)
|
|
14461
14478
|
? text
|
|
14462
14479
|
: text === null || text === undefined
|
|
14463
14480
|
? ''
|
|
@@ -14466,11 +14483,11 @@
|
|
|
14466
14483
|
return this;
|
|
14467
14484
|
}
|
|
14468
14485
|
getWidth() {
|
|
14469
|
-
|
|
14486
|
+
const isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
|
|
14470
14487
|
return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
|
|
14471
14488
|
}
|
|
14472
14489
|
getHeight() {
|
|
14473
|
-
|
|
14490
|
+
const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
|
|
14474
14491
|
return isAuto
|
|
14475
14492
|
? this.fontSize() * this.textArr.length * this.lineHeight() +
|
|
14476
14493
|
this.padding() * 2
|
|
@@ -14494,12 +14511,12 @@
|
|
|
14494
14511
|
* That method can't handle multiline text.
|
|
14495
14512
|
* @method
|
|
14496
14513
|
* @name Konva.Text#measureSize
|
|
14497
|
-
* @param {String}
|
|
14498
|
-
* @returns {Object} { width , height} of measured text
|
|
14514
|
+
* @param {String} text text to measure
|
|
14515
|
+
* @returns {Object} { width , height } of measured text
|
|
14499
14516
|
*/
|
|
14500
14517
|
measureSize(text) {
|
|
14501
14518
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
14502
|
-
|
|
14519
|
+
let _context = getDummyContext(), fontSize = this.fontSize(), metrics;
|
|
14503
14520
|
_context.save();
|
|
14504
14521
|
_context.font = this._getContextFont();
|
|
14505
14522
|
metrics = _context.measureText(text);
|
|
@@ -14537,7 +14554,7 @@
|
|
|
14537
14554
|
if (align === JUSTIFY) {
|
|
14538
14555
|
line = line.trim();
|
|
14539
14556
|
}
|
|
14540
|
-
|
|
14557
|
+
const width = this._getTextWidth(line);
|
|
14541
14558
|
return this.textArr.push({
|
|
14542
14559
|
text: line,
|
|
14543
14560
|
width: width,
|
|
@@ -14545,21 +14562,21 @@
|
|
|
14545
14562
|
});
|
|
14546
14563
|
}
|
|
14547
14564
|
_getTextWidth(text) {
|
|
14548
|
-
|
|
14549
|
-
|
|
14565
|
+
const letterSpacing = this.letterSpacing();
|
|
14566
|
+
const length = text.length;
|
|
14550
14567
|
return (getDummyContext().measureText(text).width +
|
|
14551
14568
|
(length ? letterSpacing * (length - 1) : 0));
|
|
14552
14569
|
}
|
|
14553
14570
|
_setTextData() {
|
|
14554
|
-
|
|
14571
|
+
let lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(),
|
|
14555
14572
|
// align = this.align(),
|
|
14556
14573
|
shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
|
|
14557
14574
|
this.textArr = [];
|
|
14558
14575
|
getDummyContext().font = this._getContextFont();
|
|
14559
|
-
|
|
14560
|
-
for (
|
|
14561
|
-
|
|
14562
|
-
|
|
14576
|
+
const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
|
|
14577
|
+
for (let i = 0, max = lines.length; i < max; ++i) {
|
|
14578
|
+
let line = lines[i];
|
|
14579
|
+
let lineWidth = this._getTextWidth(line);
|
|
14563
14580
|
if (fixedWidth && lineWidth > maxWidth) {
|
|
14564
14581
|
/*
|
|
14565
14582
|
* if width is fixed and line does not fit entirely
|
|
@@ -14570,9 +14587,9 @@
|
|
|
14570
14587
|
* use binary search to find the longest substring that
|
|
14571
14588
|
* that would fit in the specified width
|
|
14572
14589
|
*/
|
|
14573
|
-
|
|
14590
|
+
let low = 0, high = line.length, match = '', matchWidth = 0;
|
|
14574
14591
|
while (low < high) {
|
|
14575
|
-
|
|
14592
|
+
const mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
|
|
14576
14593
|
if (substrWidth <= maxWidth) {
|
|
14577
14594
|
low = mid + 1;
|
|
14578
14595
|
match = substr;
|
|
@@ -14592,8 +14609,8 @@
|
|
|
14592
14609
|
if (wrapAtWord) {
|
|
14593
14610
|
// try to find a space or dash where wrapping could be done
|
|
14594
14611
|
var wrapIndex;
|
|
14595
|
-
|
|
14596
|
-
|
|
14612
|
+
const nextChar = line[match.length];
|
|
14613
|
+
const nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
|
|
14597
14614
|
if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
|
|
14598
14615
|
wrapIndex = match.length;
|
|
14599
14616
|
}
|
|
@@ -14615,7 +14632,7 @@
|
|
|
14615
14632
|
this._addTextLine(match);
|
|
14616
14633
|
textWidth = Math.max(textWidth, matchWidth);
|
|
14617
14634
|
currentHeightPx += lineHeightPx;
|
|
14618
|
-
|
|
14635
|
+
const shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
|
|
14619
14636
|
if (shouldHandleEllipsis) {
|
|
14620
14637
|
this._tryToAddEllipsisToLastLine();
|
|
14621
14638
|
/*
|
|
@@ -14676,18 +14693,18 @@
|
|
|
14676
14693
|
* @returns
|
|
14677
14694
|
*/
|
|
14678
14695
|
_shouldHandleEllipsis(currentHeightPx) {
|
|
14679
|
-
|
|
14696
|
+
const fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
|
|
14680
14697
|
return (!shouldWrap ||
|
|
14681
14698
|
(fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
|
|
14682
14699
|
}
|
|
14683
14700
|
_tryToAddEllipsisToLastLine() {
|
|
14684
|
-
|
|
14685
|
-
|
|
14701
|
+
const width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
|
|
14702
|
+
const lastLine = this.textArr[this.textArr.length - 1];
|
|
14686
14703
|
if (!lastLine || !shouldAddEllipsis) {
|
|
14687
14704
|
return;
|
|
14688
14705
|
}
|
|
14689
14706
|
if (fixedWidth) {
|
|
14690
|
-
|
|
14707
|
+
const haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
|
|
14691
14708
|
if (!haveSpace) {
|
|
14692
14709
|
lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
|
|
14693
14710
|
}
|
|
@@ -14961,7 +14978,7 @@
|
|
|
14961
14978
|
*/
|
|
14962
14979
|
Factory.addGetterSetter(Text, 'textDecoration', '');
|
|
14963
14980
|
|
|
14964
|
-
|
|
14981
|
+
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
14965
14982
|
function _fillFunc(context) {
|
|
14966
14983
|
context.fillText(this.partialText, 0, 0);
|
|
14967
14984
|
}
|
|
@@ -15123,16 +15140,16 @@
|
|
|
15123
15140
|
context.setAttr('textBaseline', this.textBaseline());
|
|
15124
15141
|
context.setAttr('textAlign', 'left');
|
|
15125
15142
|
context.save();
|
|
15126
|
-
|
|
15127
|
-
|
|
15128
|
-
|
|
15129
|
-
|
|
15143
|
+
const textDecoration = this.textDecoration();
|
|
15144
|
+
const fill = this.fill();
|
|
15145
|
+
const fontSize = this.fontSize();
|
|
15146
|
+
const glyphInfo = this.glyphInfo;
|
|
15130
15147
|
if (textDecoration === 'underline') {
|
|
15131
15148
|
context.beginPath();
|
|
15132
15149
|
}
|
|
15133
|
-
for (
|
|
15150
|
+
for (let i = 0; i < glyphInfo.length; i++) {
|
|
15134
15151
|
context.save();
|
|
15135
|
-
|
|
15152
|
+
const p0 = glyphInfo[i].p0;
|
|
15136
15153
|
context.translate(p0.x, p0.y);
|
|
15137
15154
|
context.rotate(glyphInfo[i].rotation);
|
|
15138
15155
|
this.partialText = glyphInfo[i].text;
|
|
@@ -15162,13 +15179,13 @@
|
|
|
15162
15179
|
}
|
|
15163
15180
|
_hitFunc(context) {
|
|
15164
15181
|
context.beginPath();
|
|
15165
|
-
|
|
15182
|
+
const glyphInfo = this.glyphInfo;
|
|
15166
15183
|
if (glyphInfo.length >= 1) {
|
|
15167
|
-
|
|
15184
|
+
const p0 = glyphInfo[0].p0;
|
|
15168
15185
|
context.moveTo(p0.x, p0.y);
|
|
15169
15186
|
}
|
|
15170
|
-
for (
|
|
15171
|
-
|
|
15187
|
+
for (let i = 0; i < glyphInfo.length; i++) {
|
|
15188
|
+
const p1 = glyphInfo[i].p1;
|
|
15172
15189
|
context.lineTo(p1.x, p1.y);
|
|
15173
15190
|
}
|
|
15174
15191
|
context.setAttr('lineWidth', this.fontSize());
|
|
@@ -15194,11 +15211,11 @@
|
|
|
15194
15211
|
return Text.prototype._getContextFont.call(this);
|
|
15195
15212
|
}
|
|
15196
15213
|
_getTextSize(text) {
|
|
15197
|
-
|
|
15198
|
-
|
|
15214
|
+
const dummyCanvas = this.dummyCanvas;
|
|
15215
|
+
const _context = dummyCanvas.getContext('2d');
|
|
15199
15216
|
_context.save();
|
|
15200
15217
|
_context.font = this._getContextFont();
|
|
15201
|
-
|
|
15218
|
+
const metrics = _context.measureText(text);
|
|
15202
15219
|
_context.restore();
|
|
15203
15220
|
return {
|
|
15204
15221
|
width: metrics.width,
|
|
@@ -15232,7 +15249,7 @@
|
|
|
15232
15249
|
// 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
|
|
15233
15250
|
// 4. Add glyph width to the offsetToGlyph and repeat
|
|
15234
15251
|
let offsetToGlyph = offset;
|
|
15235
|
-
for (
|
|
15252
|
+
for (let i = 0; i < charArr.length; i++) {
|
|
15236
15253
|
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
15237
15254
|
if (!charStartPoint)
|
|
15238
15255
|
return;
|
|
@@ -15280,19 +15297,19 @@
|
|
|
15280
15297
|
height: 0,
|
|
15281
15298
|
};
|
|
15282
15299
|
}
|
|
15283
|
-
|
|
15300
|
+
const points = [];
|
|
15284
15301
|
this.glyphInfo.forEach(function (info) {
|
|
15285
15302
|
points.push(info.p0.x);
|
|
15286
15303
|
points.push(info.p0.y);
|
|
15287
15304
|
points.push(info.p1.x);
|
|
15288
15305
|
points.push(info.p1.y);
|
|
15289
15306
|
});
|
|
15290
|
-
|
|
15291
|
-
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
for (
|
|
15307
|
+
let minX = points[0] || 0;
|
|
15308
|
+
let maxX = points[0] || 0;
|
|
15309
|
+
let minY = points[1] || 0;
|
|
15310
|
+
let maxY = points[1] || 0;
|
|
15311
|
+
let x, y;
|
|
15312
|
+
for (let i = 0; i < points.length / 2; i++) {
|
|
15296
15313
|
x = points[i * 2];
|
|
15297
15314
|
y = points[i * 2 + 1];
|
|
15298
15315
|
minX = Math.min(minX, x);
|
|
@@ -15300,7 +15317,7 @@
|
|
|
15300
15317
|
minY = Math.min(minY, y);
|
|
15301
15318
|
maxY = Math.max(maxY, y);
|
|
15302
15319
|
}
|
|
15303
|
-
|
|
15320
|
+
const fontSize = this.fontSize();
|
|
15304
15321
|
return {
|
|
15305
15322
|
x: minX - fontSize / 2,
|
|
15306
15323
|
y: minY - fontSize / 2,
|
|
@@ -15483,8 +15500,8 @@
|
|
|
15483
15500
|
*/
|
|
15484
15501
|
Factory.addGetterSetter(TextPath, 'kerningFunc', null);
|
|
15485
15502
|
|
|
15486
|
-
|
|
15487
|
-
|
|
15503
|
+
const EVENTS_NAME = 'tr-konva';
|
|
15504
|
+
const ATTR_CHANGE_LIST = [
|
|
15488
15505
|
'resizeEnabledChange',
|
|
15489
15506
|
'rotateAnchorOffsetChange',
|
|
15490
15507
|
'rotateEnabledChange',
|
|
@@ -15503,8 +15520,8 @@
|
|
|
15503
15520
|
]
|
|
15504
15521
|
.map((e) => e + `.${EVENTS_NAME}`)
|
|
15505
15522
|
.join(' ');
|
|
15506
|
-
|
|
15507
|
-
|
|
15523
|
+
const NODES_RECT = 'nodesRect';
|
|
15524
|
+
const TRANSFORM_CHANGE_STR = [
|
|
15508
15525
|
'widthChange',
|
|
15509
15526
|
'heightChange',
|
|
15510
15527
|
'scaleXChange',
|
|
@@ -15517,7 +15534,7 @@
|
|
|
15517
15534
|
'transformsEnabledChange',
|
|
15518
15535
|
'strokeWidthChange',
|
|
15519
15536
|
];
|
|
15520
|
-
|
|
15537
|
+
const ANGLES = {
|
|
15521
15538
|
'top-left': -45,
|
|
15522
15539
|
'top-center': 0,
|
|
15523
15540
|
'top-right': 45,
|
|
@@ -15533,7 +15550,7 @@
|
|
|
15533
15550
|
return rotateCursor;
|
|
15534
15551
|
}
|
|
15535
15552
|
rad += Util.degToRad(ANGLES[anchorName] || 0);
|
|
15536
|
-
|
|
15553
|
+
const angle = ((Util.radToDeg(rad) % 360) + 360) % 360;
|
|
15537
15554
|
if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) {
|
|
15538
15555
|
// TOP
|
|
15539
15556
|
return 'ns-resize';
|
|
@@ -15572,7 +15589,7 @@
|
|
|
15572
15589
|
return 'pointer';
|
|
15573
15590
|
}
|
|
15574
15591
|
}
|
|
15575
|
-
|
|
15592
|
+
const ANCHORS_NAMES = [
|
|
15576
15593
|
'top-left',
|
|
15577
15594
|
'top-center',
|
|
15578
15595
|
'top-right',
|
|
@@ -15582,7 +15599,7 @@
|
|
|
15582
15599
|
'bottom-center',
|
|
15583
15600
|
'bottom-right',
|
|
15584
15601
|
];
|
|
15585
|
-
|
|
15602
|
+
const MAX_SAFE_INTEGER = 100000000;
|
|
15586
15603
|
function getCenter(shape) {
|
|
15587
15604
|
return {
|
|
15588
15605
|
x: shape.x +
|
|
@@ -15744,7 +15761,7 @@
|
|
|
15744
15761
|
this._resetTransformCache();
|
|
15745
15762
|
// we may need it if we set node in initial props
|
|
15746
15763
|
// so elements are not defined yet
|
|
15747
|
-
|
|
15764
|
+
const elementsCreated = !!this.findOne('.top-left');
|
|
15748
15765
|
if (elementsCreated) {
|
|
15749
15766
|
this.update();
|
|
15750
15767
|
}
|
|
@@ -15839,15 +15856,15 @@
|
|
|
15839
15856
|
}
|
|
15840
15857
|
// return absolute rotated bounding rectangle
|
|
15841
15858
|
__getNodeShape(node, rot = this.rotation(), relative) {
|
|
15842
|
-
|
|
15859
|
+
const rect = node.getClientRect({
|
|
15843
15860
|
skipTransform: true,
|
|
15844
15861
|
skipShadow: true,
|
|
15845
15862
|
skipStroke: this.ignoreStroke(),
|
|
15846
15863
|
});
|
|
15847
|
-
|
|
15848
|
-
|
|
15849
|
-
|
|
15850
|
-
|
|
15864
|
+
const absScale = node.getAbsoluteScale(relative);
|
|
15865
|
+
const absPos = node.getAbsolutePosition(relative);
|
|
15866
|
+
const dx = rect.x * absScale.x - node.offsetX() * absScale.x;
|
|
15867
|
+
const dy = rect.y * absScale.y - node.offsetY() * absScale.y;
|
|
15851
15868
|
const rotation = (Konva$2.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
|
|
15852
15869
|
(Math.PI * 2);
|
|
15853
15870
|
const box = {
|
|
@@ -15864,7 +15881,7 @@
|
|
|
15864
15881
|
}
|
|
15865
15882
|
// returns box + rotation of all shapes
|
|
15866
15883
|
__getNodeRect() {
|
|
15867
|
-
|
|
15884
|
+
const node = this.getNode();
|
|
15868
15885
|
if (!node) {
|
|
15869
15886
|
return {
|
|
15870
15887
|
x: -MAX_SAFE_INTEGER,
|
|
@@ -15881,23 +15898,23 @@
|
|
|
15881
15898
|
skipShadow: true,
|
|
15882
15899
|
skipStroke: this.ignoreStroke(),
|
|
15883
15900
|
});
|
|
15884
|
-
|
|
15901
|
+
const points = [
|
|
15885
15902
|
{ x: box.x, y: box.y },
|
|
15886
15903
|
{ x: box.x + box.width, y: box.y },
|
|
15887
15904
|
{ x: box.x + box.width, y: box.y + box.height },
|
|
15888
15905
|
{ x: box.x, y: box.y + box.height },
|
|
15889
15906
|
];
|
|
15890
|
-
|
|
15907
|
+
const trans = node.getAbsoluteTransform();
|
|
15891
15908
|
points.forEach(function (point) {
|
|
15892
|
-
|
|
15909
|
+
const transformed = trans.point(point);
|
|
15893
15910
|
totalPoints.push(transformed);
|
|
15894
15911
|
});
|
|
15895
15912
|
});
|
|
15896
15913
|
const tr = new Transform();
|
|
15897
15914
|
tr.rotate(-Konva$2.getAngle(this.rotation()));
|
|
15898
|
-
|
|
15915
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
15899
15916
|
totalPoints.forEach(function (point) {
|
|
15900
|
-
|
|
15917
|
+
const transformed = tr.point(point);
|
|
15901
15918
|
if (minX === undefined) {
|
|
15902
15919
|
minX = maxX = transformed.x;
|
|
15903
15920
|
minY = maxY = transformed.y;
|
|
@@ -15945,7 +15962,7 @@
|
|
|
15945
15962
|
this._createAnchor('rotater');
|
|
15946
15963
|
}
|
|
15947
15964
|
_createAnchor(name) {
|
|
15948
|
-
|
|
15965
|
+
const anchor = new Rect({
|
|
15949
15966
|
stroke: 'rgb(0, 161, 255)',
|
|
15950
15967
|
fill: 'white',
|
|
15951
15968
|
strokeWidth: 1,
|
|
@@ -15956,7 +15973,7 @@
|
|
|
15956
15973
|
draggable: true,
|
|
15957
15974
|
hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto',
|
|
15958
15975
|
});
|
|
15959
|
-
|
|
15976
|
+
const self = this;
|
|
15960
15977
|
anchor.on('mousedown touchstart', function (e) {
|
|
15961
15978
|
self._handleMouseDown(e);
|
|
15962
15979
|
});
|
|
@@ -15969,9 +15986,9 @@
|
|
|
15969
15986
|
});
|
|
15970
15987
|
// add hover styling
|
|
15971
15988
|
anchor.on('mouseenter', () => {
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
|
|
15989
|
+
const rad = Konva$2.getAngle(this.rotation());
|
|
15990
|
+
const rotateCursor = this.rotateAnchorCursor();
|
|
15991
|
+
const cursor = getCursor(name, rad, rotateCursor);
|
|
15975
15992
|
anchor.getStage().content &&
|
|
15976
15993
|
(anchor.getStage().content.style.cursor = cursor);
|
|
15977
15994
|
this._cursorChange = true;
|
|
@@ -15984,14 +16001,14 @@
|
|
|
15984
16001
|
this.add(anchor);
|
|
15985
16002
|
}
|
|
15986
16003
|
_createBack() {
|
|
15987
|
-
|
|
16004
|
+
const back = new Shape({
|
|
15988
16005
|
name: 'back',
|
|
15989
16006
|
width: 0,
|
|
15990
16007
|
height: 0,
|
|
15991
16008
|
draggable: true,
|
|
15992
16009
|
sceneFunc(ctx, shape) {
|
|
15993
|
-
|
|
15994
|
-
|
|
16010
|
+
const tr = shape.getParent();
|
|
16011
|
+
const padding = tr.padding();
|
|
15995
16012
|
ctx.beginPath();
|
|
15996
16013
|
ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
|
|
15997
16014
|
ctx.moveTo(shape.width() / 2, -padding);
|
|
@@ -16004,7 +16021,7 @@
|
|
|
16004
16021
|
if (!this.shouldOverdrawWholeArea()) {
|
|
16005
16022
|
return;
|
|
16006
16023
|
}
|
|
16007
|
-
|
|
16024
|
+
const padding = this.padding();
|
|
16008
16025
|
ctx.beginPath();
|
|
16009
16026
|
ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
|
|
16010
16027
|
ctx.fillStrokeShape(shape);
|
|
@@ -16036,10 +16053,10 @@
|
|
|
16036
16053
|
return;
|
|
16037
16054
|
}
|
|
16038
16055
|
this._movingAnchorName = e.target.name().split(' ')[0];
|
|
16039
|
-
|
|
16040
|
-
|
|
16041
|
-
|
|
16042
|
-
|
|
16056
|
+
const attrs = this._getNodeRect();
|
|
16057
|
+
const width = attrs.width;
|
|
16058
|
+
const height = attrs.height;
|
|
16059
|
+
const hypotenuse = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
|
|
16043
16060
|
this.sin = Math.abs(height / hypotenuse);
|
|
16044
16061
|
this.cos = Math.abs(width / hypotenuse);
|
|
16045
16062
|
if (typeof window !== 'undefined') {
|
|
@@ -16049,8 +16066,8 @@
|
|
|
16049
16066
|
window.addEventListener('touchend', this._handleMouseUp, true);
|
|
16050
16067
|
}
|
|
16051
16068
|
this._transforming = true;
|
|
16052
|
-
|
|
16053
|
-
|
|
16069
|
+
const ap = e.target.getAbsolutePosition();
|
|
16070
|
+
const pos = e.target.getStage().getPointerPosition();
|
|
16054
16071
|
this._anchorDragOffset = {
|
|
16055
16072
|
x: pos.x - ap.x,
|
|
16056
16073
|
y: pos.y - ap.y,
|
|
@@ -16062,9 +16079,9 @@
|
|
|
16062
16079
|
});
|
|
16063
16080
|
}
|
|
16064
16081
|
_handleMouseMove(e) {
|
|
16065
|
-
|
|
16066
|
-
|
|
16067
|
-
|
|
16082
|
+
let x, y, newHypotenuse;
|
|
16083
|
+
const anchorNode = this.findOne('.' + this._movingAnchorName);
|
|
16084
|
+
const stage = anchorNode.getStage();
|
|
16068
16085
|
stage.setPointersPositions(e);
|
|
16069
16086
|
const pp = stage.getPointerPosition();
|
|
16070
16087
|
let newNodePos = {
|
|
@@ -16083,7 +16100,7 @@
|
|
|
16083
16100
|
}
|
|
16084
16101
|
// rotater is working very differently, so do it first
|
|
16085
16102
|
if (this._movingAnchorName === 'rotater') {
|
|
16086
|
-
|
|
16103
|
+
const attrs = this._getNodeRect();
|
|
16087
16104
|
x = anchorNode.x() - attrs.width / 2;
|
|
16088
16105
|
y = -anchorNode.y() + attrs.height / 2;
|
|
16089
16106
|
// hor angle is changed?
|
|
@@ -16091,7 +16108,7 @@
|
|
|
16091
16108
|
if (attrs.height < 0) {
|
|
16092
16109
|
delta -= Math.PI;
|
|
16093
16110
|
}
|
|
16094
|
-
|
|
16111
|
+
const oldRotation = Konva$2.getAngle(this.rotation());
|
|
16095
16112
|
const newRotation = oldRotation + delta;
|
|
16096
16113
|
const tol = Konva$2.getAngle(this.rotationSnapTolerance());
|
|
16097
16114
|
const snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
|
|
@@ -16100,8 +16117,8 @@
|
|
|
16100
16117
|
this._fitNodesInto(shape, e);
|
|
16101
16118
|
return;
|
|
16102
16119
|
}
|
|
16103
|
-
|
|
16104
|
-
|
|
16120
|
+
const shiftBehavior = this.shiftBehavior();
|
|
16121
|
+
let keepProportion;
|
|
16105
16122
|
if (shiftBehavior === 'inverted') {
|
|
16106
16123
|
keepProportion = this.keepRatio() && !e.shiftKey;
|
|
16107
16124
|
}
|
|
@@ -16220,12 +16237,12 @@
|
|
|
16220
16237
|
}
|
|
16221
16238
|
var centeredScaling = this.centeredScaling() || e.altKey;
|
|
16222
16239
|
if (centeredScaling) {
|
|
16223
|
-
|
|
16224
|
-
|
|
16225
|
-
|
|
16226
|
-
|
|
16227
|
-
|
|
16228
|
-
|
|
16240
|
+
const topLeft = this.findOne('.top-left');
|
|
16241
|
+
const bottomRight = this.findOne('.bottom-right');
|
|
16242
|
+
const topOffsetX = topLeft.x();
|
|
16243
|
+
const topOffsetY = topLeft.y();
|
|
16244
|
+
const bottomOffsetX = this.getWidth() - bottomRight.x();
|
|
16245
|
+
const bottomOffsetY = this.getHeight() - bottomRight.y();
|
|
16229
16246
|
bottomRight.move({
|
|
16230
16247
|
x: -topOffsetX,
|
|
16231
16248
|
y: -topOffsetY,
|
|
@@ -16235,11 +16252,11 @@
|
|
|
16235
16252
|
y: bottomOffsetY,
|
|
16236
16253
|
});
|
|
16237
16254
|
}
|
|
16238
|
-
|
|
16255
|
+
const absPos = this.findOne('.top-left').getAbsolutePosition();
|
|
16239
16256
|
x = absPos.x;
|
|
16240
16257
|
y = absPos.y;
|
|
16241
|
-
|
|
16242
|
-
|
|
16258
|
+
const width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
|
|
16259
|
+
const height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
|
|
16243
16260
|
this._fitNodesInto({
|
|
16244
16261
|
x: x,
|
|
16245
16262
|
y: y,
|
|
@@ -16264,7 +16281,7 @@
|
|
|
16264
16281
|
window.removeEventListener('mouseup', this._handleMouseUp, true);
|
|
16265
16282
|
window.removeEventListener('touchend', this._handleMouseUp, true);
|
|
16266
16283
|
}
|
|
16267
|
-
|
|
16284
|
+
const node = this.getNode();
|
|
16268
16285
|
activeTransformersCount--;
|
|
16269
16286
|
this._fire('transformend', { evt: e, target: node });
|
|
16270
16287
|
// redraw layer to restore hit graph
|
|
@@ -16281,7 +16298,7 @@
|
|
|
16281
16298
|
}
|
|
16282
16299
|
}
|
|
16283
16300
|
_fitNodesInto(newAttrs, evt) {
|
|
16284
|
-
|
|
16301
|
+
const oldAttrs = this._getNodeRect();
|
|
16285
16302
|
const minSize = 1;
|
|
16286
16303
|
if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
|
|
16287
16304
|
this.update();
|
|
@@ -16291,7 +16308,7 @@
|
|
|
16291
16308
|
this.update();
|
|
16292
16309
|
return;
|
|
16293
16310
|
}
|
|
16294
|
-
|
|
16311
|
+
const t = new Transform();
|
|
16295
16312
|
t.rotate(Konva$2.getAngle(this.rotation()));
|
|
16296
16313
|
if (this._movingAnchorName &&
|
|
16297
16314
|
newAttrs.width < 0 &&
|
|
@@ -16431,14 +16448,14 @@
|
|
|
16431
16448
|
}
|
|
16432
16449
|
update() {
|
|
16433
16450
|
var _a;
|
|
16434
|
-
|
|
16451
|
+
const attrs = this._getNodeRect();
|
|
16435
16452
|
this.rotation(Util._getRotation(attrs.rotation));
|
|
16436
|
-
|
|
16437
|
-
|
|
16438
|
-
|
|
16439
|
-
|
|
16440
|
-
|
|
16441
|
-
|
|
16453
|
+
const width = attrs.width;
|
|
16454
|
+
const height = attrs.height;
|
|
16455
|
+
const enabledAnchors = this.enabledAnchors();
|
|
16456
|
+
const resizeEnabled = this.resizeEnabled();
|
|
16457
|
+
const padding = this.padding();
|
|
16458
|
+
const anchorSize = this.anchorSize();
|
|
16442
16459
|
const anchors = this.find('._anchor');
|
|
16443
16460
|
anchors.forEach((node) => {
|
|
16444
16461
|
node.setAttrs({
|
|
@@ -16545,7 +16562,7 @@
|
|
|
16545
16562
|
stopTransform() {
|
|
16546
16563
|
if (this._transforming) {
|
|
16547
16564
|
this._removeEvents();
|
|
16548
|
-
|
|
16565
|
+
const anchorNode = this.findOne('.' + this._movingAnchorName);
|
|
16549
16566
|
if (anchorNode) {
|
|
16550
16567
|
anchorNode.stopDrag();
|
|
16551
16568
|
}
|
|
@@ -16567,7 +16584,7 @@
|
|
|
16567
16584
|
}
|
|
16568
16585
|
// overwrite clone to NOT use method from Container
|
|
16569
16586
|
clone(obj) {
|
|
16570
|
-
|
|
16587
|
+
const node = Node.prototype.clone.call(this, obj);
|
|
16571
16588
|
return node;
|
|
16572
16589
|
}
|
|
16573
16590
|
getClientRect() {
|
|
@@ -17265,7 +17282,7 @@
|
|
|
17265
17282
|
this.a = 0;
|
|
17266
17283
|
this.next = null;
|
|
17267
17284
|
}
|
|
17268
|
-
|
|
17285
|
+
const mul_table = [
|
|
17269
17286
|
512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292,
|
|
17270
17287
|
512, 454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292,
|
|
17271
17288
|
273, 512, 482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259,
|
|
@@ -17284,7 +17301,7 @@
|
|
|
17284
17301
|
329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292,
|
|
17285
17302
|
289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259,
|
|
17286
17303
|
];
|
|
17287
|
-
|
|
17304
|
+
const shg_table = [
|
|
17288
17305
|
9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17,
|
|
17289
17306
|
17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 19, 19,
|
|
17290
17307
|
19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
|
|
@@ -17301,9 +17318,9 @@
|
|
|
17301
17318
|
24, 24, 24, 24, 24, 24, 24,
|
|
17302
17319
|
];
|
|
17303
17320
|
function filterGaussBlurRGBA(imageData, radius) {
|
|
17304
|
-
|
|
17305
|
-
|
|
17306
|
-
|
|
17321
|
+
const pixels = imageData.data, width = imageData.width, height = imageData.height;
|
|
17322
|
+
let x, y, i, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
|
17323
|
+
let div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), stackEnd = null, stack = stackStart, stackIn = null, stackOut = null, mul_sum = mul_table[radius], shg_sum = shg_table[radius];
|
|
17307
17324
|
for (i = 1; i < div; i++) {
|
|
17308
17325
|
stack = stack.next = new BlurStack();
|
|
17309
17326
|
if (i === radiusPlus1) {
|
|
@@ -17494,7 +17511,7 @@
|
|
|
17494
17511
|
* node.blurRadius(10);
|
|
17495
17512
|
*/
|
|
17496
17513
|
const Blur = function Blur(imageData) {
|
|
17497
|
-
|
|
17514
|
+
const radius = Math.round(this.blurRadius());
|
|
17498
17515
|
if (radius > 0) {
|
|
17499
17516
|
filterGaussBlurRGBA(imageData, radius);
|
|
17500
17517
|
}
|
|
@@ -17519,7 +17536,7 @@
|
|
|
17519
17536
|
* node.brightness(0.8);
|
|
17520
17537
|
*/
|
|
17521
17538
|
const Brighten = function (imageData) {
|
|
17522
|
-
|
|
17539
|
+
let brightness = this.brightness() * 255, data = imageData.data, len = data.length, i;
|
|
17523
17540
|
for (i = 0; i < len; i += 4) {
|
|
17524
17541
|
// red
|
|
17525
17542
|
data[i] += brightness;
|
|
@@ -17551,8 +17568,8 @@
|
|
|
17551
17568
|
* node.contrast(10);
|
|
17552
17569
|
*/
|
|
17553
17570
|
const Contrast = function (imageData) {
|
|
17554
|
-
|
|
17555
|
-
|
|
17571
|
+
const adjust = Math.pow((this.contrast() + 100) / 100, 2);
|
|
17572
|
+
let data = imageData.data, nPixels = data.length, red = 150, green = 150, blue = 150, i;
|
|
17556
17573
|
for (i = 0; i < nPixels; i += 4) {
|
|
17557
17574
|
red = data[i];
|
|
17558
17575
|
green = data[i + 1];
|
|
@@ -17614,7 +17631,7 @@
|
|
|
17614
17631
|
// pixastic greyLevel is between 0 and 255. I want it between 0 and 1. Also,
|
|
17615
17632
|
// a max value of greyLevel yields a white emboss, and the min value yields a black
|
|
17616
17633
|
// emboss. Therefore, I changed greyLevel to whiteLevel
|
|
17617
|
-
|
|
17634
|
+
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;
|
|
17618
17635
|
switch (direction) {
|
|
17619
17636
|
case 'top-left':
|
|
17620
17637
|
dirY = -1;
|
|
@@ -17652,33 +17669,33 @@
|
|
|
17652
17669
|
Util.error('Unknown emboss direction: ' + direction);
|
|
17653
17670
|
}
|
|
17654
17671
|
do {
|
|
17655
|
-
|
|
17656
|
-
|
|
17672
|
+
const offsetY = (y - 1) * w4;
|
|
17673
|
+
let otherY = dirY;
|
|
17657
17674
|
if (y + otherY < 1) {
|
|
17658
17675
|
otherY = 0;
|
|
17659
17676
|
}
|
|
17660
17677
|
if (y + otherY > h) {
|
|
17661
17678
|
otherY = 0;
|
|
17662
17679
|
}
|
|
17663
|
-
|
|
17664
|
-
|
|
17680
|
+
const offsetYOther = (y - 1 + otherY) * w * 4;
|
|
17681
|
+
let x = w;
|
|
17665
17682
|
do {
|
|
17666
|
-
|
|
17667
|
-
|
|
17683
|
+
const offset = offsetY + (x - 1) * 4;
|
|
17684
|
+
let otherX = dirX;
|
|
17668
17685
|
if (x + otherX < 1) {
|
|
17669
17686
|
otherX = 0;
|
|
17670
17687
|
}
|
|
17671
17688
|
if (x + otherX > w) {
|
|
17672
17689
|
otherX = 0;
|
|
17673
17690
|
}
|
|
17674
|
-
|
|
17675
|
-
|
|
17676
|
-
|
|
17677
|
-
|
|
17678
|
-
|
|
17679
|
-
|
|
17680
|
-
|
|
17681
|
-
|
|
17691
|
+
const offsetOther = offsetYOther + (x - 1 + otherX) * 4;
|
|
17692
|
+
const dR = data[offset] - data[offsetOther];
|
|
17693
|
+
const dG = data[offset + 1] - data[offsetOther + 1];
|
|
17694
|
+
const dB = data[offset + 2] - data[offsetOther + 2];
|
|
17695
|
+
let dif = dR;
|
|
17696
|
+
const absDif = dif > 0 ? dif : -dif;
|
|
17697
|
+
const absG = dG > 0 ? dG : -dG;
|
|
17698
|
+
const absB = dB > 0 ? dB : -dB;
|
|
17682
17699
|
if (absG > absDif) {
|
|
17683
17700
|
dif = dG;
|
|
17684
17701
|
}
|
|
@@ -17687,15 +17704,15 @@
|
|
|
17687
17704
|
}
|
|
17688
17705
|
dif *= strength;
|
|
17689
17706
|
if (blend) {
|
|
17690
|
-
|
|
17691
|
-
|
|
17692
|
-
|
|
17707
|
+
const r = data[offset] + dif;
|
|
17708
|
+
const g = data[offset + 1] + dif;
|
|
17709
|
+
const b = data[offset + 2] + dif;
|
|
17693
17710
|
data[offset] = r > 255 ? 255 : r < 0 ? 0 : r;
|
|
17694
17711
|
data[offset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
|
|
17695
17712
|
data[offset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
|
|
17696
17713
|
}
|
|
17697
17714
|
else {
|
|
17698
|
-
|
|
17715
|
+
let grey = greyLevel - dif;
|
|
17699
17716
|
if (grey < 0) {
|
|
17700
17717
|
grey = 0;
|
|
17701
17718
|
}
|
|
@@ -17743,7 +17760,7 @@
|
|
|
17743
17760
|
|
|
17744
17761
|
function remap(fromValue, fromMin, fromMax, toMin, toMax) {
|
|
17745
17762
|
// Compute the range of the data
|
|
17746
|
-
|
|
17763
|
+
let fromRange = fromMax - fromMin, toRange = toMax - toMin, toValue;
|
|
17747
17764
|
// If either range is 0, then the value can only be mapped to 1 value
|
|
17748
17765
|
if (fromRange === 0) {
|
|
17749
17766
|
return toMin + toRange / 2;
|
|
@@ -17771,9 +17788,9 @@
|
|
|
17771
17788
|
* node.enhance(0.4);
|
|
17772
17789
|
*/
|
|
17773
17790
|
const Enhance = function (imageData) {
|
|
17774
|
-
|
|
17791
|
+
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;
|
|
17775
17792
|
// If we are not enhancing anything - don't do any computation
|
|
17776
|
-
|
|
17793
|
+
const enhanceAmount = this.enhance();
|
|
17777
17794
|
if (enhanceAmount === 0) {
|
|
17778
17795
|
return;
|
|
17779
17796
|
}
|
|
@@ -17817,7 +17834,7 @@
|
|
|
17817
17834
|
bMax = 255;
|
|
17818
17835
|
bMin = 0;
|
|
17819
17836
|
}
|
|
17820
|
-
|
|
17837
|
+
let rMid, rGoalMax, rGoalMin, gMid, gGoalMax, gGoalMin, bMid, bGoalMax, bGoalMin;
|
|
17821
17838
|
// If the enhancement is positive - stretch the histogram
|
|
17822
17839
|
if (enhanceAmount > 0) {
|
|
17823
17840
|
rGoalMax = rMax + enhanceAmount * (255 - rMax);
|
|
@@ -17866,7 +17883,7 @@
|
|
|
17866
17883
|
* node.filters([Konva.Filters.Grayscale]);
|
|
17867
17884
|
*/
|
|
17868
17885
|
const Grayscale = function (imageData) {
|
|
17869
|
-
|
|
17886
|
+
let data = imageData.data, len = data.length, i, brightness;
|
|
17870
17887
|
for (i = 0; i < len; i += 4) {
|
|
17871
17888
|
brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
|
|
17872
17889
|
// red
|
|
@@ -17913,7 +17930,7 @@
|
|
|
17913
17930
|
* image.luminance(0.2);
|
|
17914
17931
|
*/
|
|
17915
17932
|
const HSL = function (imageData) {
|
|
17916
|
-
|
|
17933
|
+
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;
|
|
17917
17934
|
// Basis for the technique used:
|
|
17918
17935
|
// http://beesbuzz.biz/code/hsv_color_transforms.php
|
|
17919
17936
|
// V is the value multiplier (1 for none, 2 for double, 0.5 for half)
|
|
@@ -17925,12 +17942,12 @@
|
|
|
17925
17942
|
//[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
|
|
17926
17943
|
//[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
|
|
17927
17944
|
// Precompute the values in the matrix:
|
|
17928
|
-
|
|
17945
|
+
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
17929
17946
|
// (result spot)(source spot)
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17947
|
+
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;
|
|
17948
|
+
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;
|
|
17949
|
+
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;
|
|
17950
|
+
let r, g, b, a;
|
|
17934
17951
|
for (i = 0; i < nPixels; i += 4) {
|
|
17935
17952
|
r = data[i + 0];
|
|
17936
17953
|
g = data[i + 1];
|
|
@@ -17955,7 +17972,7 @@
|
|
|
17955
17972
|
* image.value(200);
|
|
17956
17973
|
*/
|
|
17957
17974
|
const HSV = function (imageData) {
|
|
17958
|
-
|
|
17975
|
+
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;
|
|
17959
17976
|
// Basis for the technique used:
|
|
17960
17977
|
// http://beesbuzz.biz/code/hsv_color_transforms.php
|
|
17961
17978
|
// V is the value multiplier (1 for none, 2 for double, 0.5 for half)
|
|
@@ -17967,13 +17984,13 @@
|
|
|
17967
17984
|
//[ .299V-.299vsu-.328vsw .587V+.413vsu+.035vsw .114V-.114vsu+.292vsw ]*[G]
|
|
17968
17985
|
//[ .299V-.300vsu+1.25vsw .587V-.588vsu-1.05vsw .114V+.886vsu-.203vsw ] [B]
|
|
17969
17986
|
// Precompute the values in the matrix:
|
|
17970
|
-
|
|
17987
|
+
const vsu = v * s * Math.cos((h * Math.PI) / 180), vsw = v * s * Math.sin((h * Math.PI) / 180);
|
|
17971
17988
|
// (result spot)(source spot)
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
17989
|
+
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;
|
|
17990
|
+
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;
|
|
17991
|
+
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;
|
|
17992
|
+
let r, g, b, a;
|
|
17993
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
17977
17994
|
r = data[i + 0];
|
|
17978
17995
|
g = data[i + 1];
|
|
17979
17996
|
b = data[i + 2];
|
|
@@ -18019,7 +18036,7 @@
|
|
|
18019
18036
|
* node.filters([Konva.Filters.Invert]);
|
|
18020
18037
|
*/
|
|
18021
18038
|
const Invert = function (imageData) {
|
|
18022
|
-
|
|
18039
|
+
let data = imageData.data, len = data.length, i;
|
|
18023
18040
|
for (i = 0; i < len; i += 4) {
|
|
18024
18041
|
// red
|
|
18025
18042
|
data[i] = 255 - data[i];
|
|
@@ -18045,19 +18062,19 @@
|
|
|
18045
18062
|
* @param {Number} [opt.polarCenterY] vertical location for the center of the circle,
|
|
18046
18063
|
* default is in the middle
|
|
18047
18064
|
*/
|
|
18048
|
-
|
|
18049
|
-
|
|
18065
|
+
const ToPolar = function (src, dst, opt) {
|
|
18066
|
+
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;
|
|
18050
18067
|
// Find the largest radius
|
|
18051
|
-
|
|
18068
|
+
let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
18052
18069
|
x = xSize - xMid;
|
|
18053
18070
|
y = ySize - yMid;
|
|
18054
18071
|
rad = Math.sqrt(x * x + y * y);
|
|
18055
18072
|
rMax = rad > rMax ? rad : rMax;
|
|
18056
18073
|
// We'll be uisng y as the radius, and x as the angle (theta=t)
|
|
18057
|
-
|
|
18074
|
+
let rSize = ySize, tSize = xSize, radius, theta;
|
|
18058
18075
|
// We want to cover all angles (0-360) and we need to convert to
|
|
18059
18076
|
// radians (*PI/180)
|
|
18060
|
-
|
|
18077
|
+
let conversion = ((360 / tSize) * Math.PI) / 180, sin, cos;
|
|
18061
18078
|
// var x1, x2, x1i, x2i, y1, y2, y1i, y2i, scale;
|
|
18062
18079
|
for (theta = 0; theta < tSize; theta += 1) {
|
|
18063
18080
|
sin = Math.sin(theta * conversion);
|
|
@@ -18096,21 +18113,21 @@
|
|
|
18096
18113
|
* @param {Number} [opt.polarRotation] amount to rotate the image counterclockwis,
|
|
18097
18114
|
* 0 is no rotation, 360 degrees is a full rotation
|
|
18098
18115
|
*/
|
|
18099
|
-
|
|
18100
|
-
|
|
18116
|
+
const FromPolar = function (src, dst, opt) {
|
|
18117
|
+
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;
|
|
18101
18118
|
// Find the largest radius
|
|
18102
|
-
|
|
18119
|
+
let rad, rMax = Math.sqrt(xMid * xMid + yMid * yMid);
|
|
18103
18120
|
x = xSize - xMid;
|
|
18104
18121
|
y = ySize - yMid;
|
|
18105
18122
|
rad = Math.sqrt(x * x + y * y);
|
|
18106
18123
|
rMax = rad > rMax ? rad : rMax;
|
|
18107
18124
|
// We'll be uisng x as the radius, and y as the angle (theta=t)
|
|
18108
|
-
|
|
18125
|
+
let rSize = ySize, tSize = xSize, radius, theta, phaseShift = 0;
|
|
18109
18126
|
// We need to convert to degrees and we need to make sure
|
|
18110
18127
|
// it's between (0-360)
|
|
18111
18128
|
// var conversion = tSize/360*180/Math.PI;
|
|
18112
18129
|
//var conversion = tSize/360*180/Math.PI;
|
|
18113
|
-
|
|
18130
|
+
let x1, y1;
|
|
18114
18131
|
for (x = 0; x < xSize; x += 1) {
|
|
18115
18132
|
for (y = 0; y < ySize; y += 1) {
|
|
18116
18133
|
dx = x - xMid;
|
|
@@ -18150,19 +18167,19 @@
|
|
|
18150
18167
|
* node.kaleidoscopeAngle(45);
|
|
18151
18168
|
*/
|
|
18152
18169
|
const Kaleidoscope = function (imageData) {
|
|
18153
|
-
|
|
18154
|
-
|
|
18155
|
-
|
|
18156
|
-
|
|
18157
|
-
|
|
18170
|
+
const xSize = imageData.width, ySize = imageData.height;
|
|
18171
|
+
let x, y, xoff, i, r, g, b, a, srcPos, dstPos;
|
|
18172
|
+
let power = Math.round(this.kaleidoscopePower());
|
|
18173
|
+
const angle = Math.round(this.kaleidoscopeAngle());
|
|
18174
|
+
const offset = Math.floor((xSize * (angle % 360)) / 360);
|
|
18158
18175
|
if (power < 1) {
|
|
18159
18176
|
return;
|
|
18160
18177
|
}
|
|
18161
18178
|
// Work with our shared buffer canvas
|
|
18162
|
-
|
|
18179
|
+
const tempCanvas = Util.createCanvasElement();
|
|
18163
18180
|
tempCanvas.width = xSize;
|
|
18164
18181
|
tempCanvas.height = ySize;
|
|
18165
|
-
|
|
18182
|
+
const scratchData = tempCanvas
|
|
18166
18183
|
.getContext('2d')
|
|
18167
18184
|
.getImageData(0, 0, xSize, ySize);
|
|
18168
18185
|
Util.releaseCanvas(tempCanvas);
|
|
@@ -18173,17 +18190,17 @@
|
|
|
18173
18190
|
});
|
|
18174
18191
|
// Determine how big each section will be, if it's too small
|
|
18175
18192
|
// make it bigger
|
|
18176
|
-
|
|
18193
|
+
let minSectionSize = xSize / Math.pow(2, power);
|
|
18177
18194
|
while (minSectionSize <= 8) {
|
|
18178
18195
|
minSectionSize = minSectionSize * 2;
|
|
18179
18196
|
power -= 1;
|
|
18180
18197
|
}
|
|
18181
18198
|
minSectionSize = Math.ceil(minSectionSize);
|
|
18182
|
-
|
|
18199
|
+
let sectionSize = minSectionSize;
|
|
18183
18200
|
// Copy the offset region to 0
|
|
18184
18201
|
// Depending on the size of filter and location of the offset we may need
|
|
18185
18202
|
// to copy the section backwards to prevent it from rewriting itself
|
|
18186
|
-
|
|
18203
|
+
let xStart = 0, xEnd = sectionSize, xDelta = 1;
|
|
18187
18204
|
if (offset + minSectionSize > xSize) {
|
|
18188
18205
|
xStart = sectionSize;
|
|
18189
18206
|
xEnd = 0;
|
|
@@ -18244,8 +18261,8 @@
|
|
|
18244
18261
|
Factory.addGetterSetter(Node, 'kaleidoscopeAngle', 0, getNumberValidator(), Factory.afterSetFilter);
|
|
18245
18262
|
|
|
18246
18263
|
function pixelAt(idata, x, y) {
|
|
18247
|
-
|
|
18248
|
-
|
|
18264
|
+
let idx = (y * idata.width + x) * 4;
|
|
18265
|
+
const d = [];
|
|
18249
18266
|
d.push(idata.data[idx++], idata.data[idx++], idata.data[idx++], idata.data[idx++]);
|
|
18250
18267
|
return d;
|
|
18251
18268
|
}
|
|
@@ -18255,8 +18272,8 @@
|
|
|
18255
18272
|
Math.pow(p1[2] - p2[2], 2));
|
|
18256
18273
|
}
|
|
18257
18274
|
function rgbMean(pTab) {
|
|
18258
|
-
|
|
18259
|
-
for (
|
|
18275
|
+
const m = [0, 0, 0];
|
|
18276
|
+
for (let i = 0; i < pTab.length; i++) {
|
|
18260
18277
|
m[0] += pTab[i][0];
|
|
18261
18278
|
m[1] += pTab[i][1];
|
|
18262
18279
|
m[2] += pTab[i][2];
|
|
@@ -18267,21 +18284,21 @@
|
|
|
18267
18284
|
return m;
|
|
18268
18285
|
}
|
|
18269
18286
|
function backgroundMask(idata, threshold) {
|
|
18270
|
-
|
|
18271
|
-
|
|
18272
|
-
|
|
18273
|
-
|
|
18274
|
-
|
|
18287
|
+
const rgbv_no = pixelAt(idata, 0, 0);
|
|
18288
|
+
const rgbv_ne = pixelAt(idata, idata.width - 1, 0);
|
|
18289
|
+
const rgbv_so = pixelAt(idata, 0, idata.height - 1);
|
|
18290
|
+
const rgbv_se = pixelAt(idata, idata.width - 1, idata.height - 1);
|
|
18291
|
+
const thres = threshold || 10;
|
|
18275
18292
|
if (rgbDistance(rgbv_no, rgbv_ne) < thres &&
|
|
18276
18293
|
rgbDistance(rgbv_ne, rgbv_se) < thres &&
|
|
18277
18294
|
rgbDistance(rgbv_se, rgbv_so) < thres &&
|
|
18278
18295
|
rgbDistance(rgbv_so, rgbv_no) < thres) {
|
|
18279
18296
|
// Mean color
|
|
18280
|
-
|
|
18297
|
+
const mean = rgbMean([rgbv_ne, rgbv_no, rgbv_se, rgbv_so]);
|
|
18281
18298
|
// Mask based on color distance
|
|
18282
|
-
|
|
18283
|
-
for (
|
|
18284
|
-
|
|
18299
|
+
const mask = [];
|
|
18300
|
+
for (let i = 0; i < idata.width * idata.height; i++) {
|
|
18301
|
+
const d = rgbDistance(mean, [
|
|
18285
18302
|
idata.data[i * 4],
|
|
18286
18303
|
idata.data[i * 4 + 1],
|
|
18287
18304
|
idata.data[i * 4 + 2],
|
|
@@ -18292,26 +18309,26 @@
|
|
|
18292
18309
|
}
|
|
18293
18310
|
}
|
|
18294
18311
|
function applyMask(idata, mask) {
|
|
18295
|
-
for (
|
|
18312
|
+
for (let i = 0; i < idata.width * idata.height; i++) {
|
|
18296
18313
|
idata.data[4 * i + 3] = mask[i];
|
|
18297
18314
|
}
|
|
18298
18315
|
}
|
|
18299
18316
|
function erodeMask(mask, sw, sh) {
|
|
18300
|
-
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
|
|
18304
|
-
for (
|
|
18305
|
-
for (
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
for (
|
|
18309
|
-
for (
|
|
18310
|
-
|
|
18311
|
-
|
|
18317
|
+
const weights = [1, 1, 1, 1, 0, 1, 1, 1, 1];
|
|
18318
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
18319
|
+
const halfSide = Math.floor(side / 2);
|
|
18320
|
+
const maskResult = [];
|
|
18321
|
+
for (let y = 0; y < sh; y++) {
|
|
18322
|
+
for (let x = 0; x < sw; x++) {
|
|
18323
|
+
const so = y * sw + x;
|
|
18324
|
+
let a = 0;
|
|
18325
|
+
for (let cy = 0; cy < side; cy++) {
|
|
18326
|
+
for (let cx = 0; cx < side; cx++) {
|
|
18327
|
+
const scy = y + cy - halfSide;
|
|
18328
|
+
const scx = x + cx - halfSide;
|
|
18312
18329
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
18313
|
-
|
|
18314
|
-
|
|
18330
|
+
const srcOff = scy * sw + scx;
|
|
18331
|
+
const wt = weights[cy * side + cx];
|
|
18315
18332
|
a += mask[srcOff] * wt;
|
|
18316
18333
|
}
|
|
18317
18334
|
}
|
|
@@ -18322,21 +18339,21 @@
|
|
|
18322
18339
|
return maskResult;
|
|
18323
18340
|
}
|
|
18324
18341
|
function dilateMask(mask, sw, sh) {
|
|
18325
|
-
|
|
18326
|
-
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
for (
|
|
18330
|
-
for (
|
|
18331
|
-
|
|
18332
|
-
|
|
18333
|
-
for (
|
|
18334
|
-
for (
|
|
18335
|
-
|
|
18336
|
-
|
|
18342
|
+
const weights = [1, 1, 1, 1, 1, 1, 1, 1, 1];
|
|
18343
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
18344
|
+
const halfSide = Math.floor(side / 2);
|
|
18345
|
+
const maskResult = [];
|
|
18346
|
+
for (let y = 0; y < sh; y++) {
|
|
18347
|
+
for (let x = 0; x < sw; x++) {
|
|
18348
|
+
const so = y * sw + x;
|
|
18349
|
+
let a = 0;
|
|
18350
|
+
for (let cy = 0; cy < side; cy++) {
|
|
18351
|
+
for (let cx = 0; cx < side; cx++) {
|
|
18352
|
+
const scy = y + cy - halfSide;
|
|
18353
|
+
const scx = x + cx - halfSide;
|
|
18337
18354
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
18338
|
-
|
|
18339
|
-
|
|
18355
|
+
const srcOff = scy * sw + scx;
|
|
18356
|
+
const wt = weights[cy * side + cx];
|
|
18340
18357
|
a += mask[srcOff] * wt;
|
|
18341
18358
|
}
|
|
18342
18359
|
}
|
|
@@ -18347,21 +18364,21 @@
|
|
|
18347
18364
|
return maskResult;
|
|
18348
18365
|
}
|
|
18349
18366
|
function smoothEdgeMask(mask, sw, sh) {
|
|
18350
|
-
|
|
18351
|
-
|
|
18352
|
-
|
|
18353
|
-
|
|
18354
|
-
for (
|
|
18355
|
-
for (
|
|
18356
|
-
|
|
18357
|
-
|
|
18358
|
-
for (
|
|
18359
|
-
for (
|
|
18360
|
-
|
|
18361
|
-
|
|
18367
|
+
const weights = [1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9, 1 / 9];
|
|
18368
|
+
const side = Math.round(Math.sqrt(weights.length));
|
|
18369
|
+
const halfSide = Math.floor(side / 2);
|
|
18370
|
+
const maskResult = [];
|
|
18371
|
+
for (let y = 0; y < sh; y++) {
|
|
18372
|
+
for (let x = 0; x < sw; x++) {
|
|
18373
|
+
const so = y * sw + x;
|
|
18374
|
+
let a = 0;
|
|
18375
|
+
for (let cy = 0; cy < side; cy++) {
|
|
18376
|
+
for (let cx = 0; cx < side; cx++) {
|
|
18377
|
+
const scy = y + cy - halfSide;
|
|
18378
|
+
const scx = x + cx - halfSide;
|
|
18362
18379
|
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
|
|
18363
|
-
|
|
18364
|
-
|
|
18380
|
+
const srcOff = scy * sw + scx;
|
|
18381
|
+
const wt = weights[cy * side + cx];
|
|
18365
18382
|
a += mask[srcOff] * wt;
|
|
18366
18383
|
}
|
|
18367
18384
|
}
|
|
@@ -18384,7 +18401,7 @@
|
|
|
18384
18401
|
*/
|
|
18385
18402
|
const Mask = function (imageData) {
|
|
18386
18403
|
// Detect pixels close to the background color
|
|
18387
|
-
|
|
18404
|
+
let threshold = this.threshold(), mask = backgroundMask(imageData, threshold);
|
|
18388
18405
|
if (mask) {
|
|
18389
18406
|
// Erode
|
|
18390
18407
|
mask = erodeMask(mask, imageData.width, imageData.height);
|
|
@@ -18412,8 +18429,8 @@
|
|
|
18412
18429
|
* node.noise(0.8);
|
|
18413
18430
|
*/
|
|
18414
18431
|
const Noise = function (imageData) {
|
|
18415
|
-
|
|
18416
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
18432
|
+
const amount = this.noise() * 255, data = imageData.data, nPixels = data.length, half = amount / 2;
|
|
18433
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
18417
18434
|
data[i + 0] += half - 2 * half * Math.random();
|
|
18418
18435
|
data[i + 1] += half - 2 * half * Math.random();
|
|
18419
18436
|
data[i + 2] += half - 2 * half * Math.random();
|
|
@@ -18428,7 +18445,6 @@
|
|
|
18428
18445
|
* @returns {Number}
|
|
18429
18446
|
*/
|
|
18430
18447
|
|
|
18431
|
-
/*eslint-disable max-depth */
|
|
18432
18448
|
/**
|
|
18433
18449
|
* Pixelate Filter. Averages groups of pixels and redraws
|
|
18434
18450
|
* them as larger pixels
|
|
@@ -18443,7 +18459,7 @@
|
|
|
18443
18459
|
* node.pixelSize(10);
|
|
18444
18460
|
*/
|
|
18445
18461
|
const Pixelate = function (imageData) {
|
|
18446
|
-
|
|
18462
|
+
let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, x, y, i,
|
|
18447
18463
|
//pixelsPerBin = pixelSize * pixelSize,
|
|
18448
18464
|
red, green, blue, alpha, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), xBinStart, xBinEnd, yBinStart, yBinEnd, xBin, yBin, pixelsInBin, data = imageData.data;
|
|
18449
18465
|
if (pixelSize <= 0) {
|
|
@@ -18529,7 +18545,7 @@
|
|
|
18529
18545
|
*/
|
|
18530
18546
|
const Posterize = function (imageData) {
|
|
18531
18547
|
// level must be between 1 and 255
|
|
18532
|
-
|
|
18548
|
+
let levels = Math.round(this.levels() * 254) + 1, data = imageData.data, len = data.length, scale = 255 / levels, i;
|
|
18533
18549
|
for (i = 0; i < len; i += 1) {
|
|
18534
18550
|
data[i] = Math.floor(data[i] / scale) * scale;
|
|
18535
18551
|
}
|
|
@@ -18557,7 +18573,7 @@
|
|
|
18557
18573
|
* node.green(200);
|
|
18558
18574
|
*/
|
|
18559
18575
|
const RGB = function (imageData) {
|
|
18560
|
-
|
|
18576
|
+
let data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), i, brightness;
|
|
18561
18577
|
for (i = 0; i < nPixels; i += 4) {
|
|
18562
18578
|
brightness =
|
|
18563
18579
|
(0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2]) / 255;
|
|
@@ -18632,9 +18648,9 @@
|
|
|
18632
18648
|
* node.alpha(0.3);
|
|
18633
18649
|
*/
|
|
18634
18650
|
const RGBA = function (imageData) {
|
|
18635
|
-
|
|
18636
|
-
for (i = 0; i < nPixels; i += 4) {
|
|
18637
|
-
ia = 1 - alpha;
|
|
18651
|
+
const data = imageData.data, nPixels = data.length, red = this.red(), green = this.green(), blue = this.blue(), alpha = this.alpha();
|
|
18652
|
+
for (let i = 0; i < nPixels; i += 4) {
|
|
18653
|
+
const ia = 1 - alpha;
|
|
18638
18654
|
data[i] = red * alpha + data[i] * ia; // r
|
|
18639
18655
|
data[i + 1] = green * alpha + data[i + 1] * ia; // g
|
|
18640
18656
|
data[i + 2] = blue * alpha + data[i + 2] * ia; // b
|
|
@@ -18721,7 +18737,7 @@
|
|
|
18721
18737
|
* node.filters([Konva.Filters.Sepia]);
|
|
18722
18738
|
*/
|
|
18723
18739
|
const Sepia = function (imageData) {
|
|
18724
|
-
|
|
18740
|
+
let data = imageData.data, nPixels = data.length, i, r, g, b;
|
|
18725
18741
|
for (i = 0; i < nPixels; i += 4) {
|
|
18726
18742
|
r = data[i + 0];
|
|
18727
18743
|
g = data[i + 1];
|
|
@@ -18746,15 +18762,16 @@
|
|
|
18746
18762
|
* node.filters([Konva.Filters.Solarize]);
|
|
18747
18763
|
*/
|
|
18748
18764
|
const Solarize = function (imageData) {
|
|
18749
|
-
|
|
18765
|
+
const data = imageData.data, w = imageData.width, h = imageData.height, w4 = w * 4;
|
|
18766
|
+
let y = h;
|
|
18750
18767
|
do {
|
|
18751
|
-
|
|
18752
|
-
|
|
18768
|
+
const offsetY = (y - 1) * w4;
|
|
18769
|
+
let x = w;
|
|
18753
18770
|
do {
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18771
|
+
const offset = offsetY + (x - 1) * 4;
|
|
18772
|
+
let r = data[offset];
|
|
18773
|
+
let g = data[offset + 1];
|
|
18774
|
+
let b = data[offset + 2];
|
|
18758
18775
|
if (r > 127) {
|
|
18759
18776
|
r = 255 - r;
|
|
18760
18777
|
}
|
|
@@ -18786,8 +18803,8 @@
|
|
|
18786
18803
|
* node.threshold(0.1);
|
|
18787
18804
|
*/
|
|
18788
18805
|
const Threshold = function (imageData) {
|
|
18789
|
-
|
|
18790
|
-
for (i = 0; i < len; i += 1) {
|
|
18806
|
+
const level = this.threshold() * 255, data = imageData.data, len = data.length;
|
|
18807
|
+
for (let i = 0; i < len; i += 1) {
|
|
18791
18808
|
data[i] = data[i] < level ? 0 : 255;
|
|
18792
18809
|
}
|
|
18793
18810
|
};
|