konva 8.3.14 → 8.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cmj/Container.js +7 -4
- package/cmj/Context.d.ts +29 -28
- package/cmj/Context.js +5 -3
- package/cmj/Global.js +1 -1
- package/cmj/Node.d.ts +5 -5
- package/cmj/PointerEvents.d.ts +1 -1
- package/cmj/Shape.d.ts +3 -3
- package/cmj/Util.d.ts +4 -0
- package/cmj/Util.js +46 -0
- package/cmj/_CoreInternals.d.ts +3 -0
- package/cmj/_FullInternals.d.ts +3 -0
- package/cmj/shapes/Image.d.ts +2 -0
- package/cmj/shapes/Image.js +17 -5
- package/cmj/shapes/Rect.d.ts +2 -1
- package/cmj/shapes/Rect.js +2 -22
- package/cmj/shapes/Text.js +7 -6
- package/cmj/shapes/Transformer.d.ts +1 -0
- package/cmj/shapes/Transformer.js +4 -0
- package/cmj/types.d.ts +1 -1
- package/konva.js +128 -57
- package/konva.min.js +3 -3
- package/lib/Container.js +7 -4
- package/lib/Context.d.ts +29 -28
- package/lib/Context.js +5 -3
- package/lib/Global.js +1 -1
- package/lib/Node.d.ts +5 -5
- package/lib/PointerEvents.d.ts +1 -1
- package/lib/Shape.d.ts +3 -3
- package/lib/Util.d.ts +4 -0
- package/lib/Util.js +46 -0
- package/lib/_CoreInternals.d.ts +3 -0
- package/lib/_FullInternals.d.ts +3 -0
- package/lib/shapes/Image.d.ts +2 -0
- package/lib/shapes/Image.js +17 -5
- package/lib/shapes/Rect.d.ts +2 -1
- package/lib/shapes/Rect.js +2 -22
- package/lib/shapes/Text.js +7 -6
- package/lib/shapes/Transformer.d.ts +1 -0
- package/lib/shapes/Transformer.js +4 -0
- package/lib/types.d.ts +1 -1
- package/package.json +13 -13
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v8.
|
|
8
|
+
* Konva JavaScript Framework v8.4.1
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Thu Jan 19 2023
|
|
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: '8.
|
|
38
|
+
version: '8.4.1',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -759,7 +759,9 @@
|
|
|
759
759
|
str = str || 'black';
|
|
760
760
|
return (Util._namedColorToRBA(str) ||
|
|
761
761
|
Util._hex3ColorToRGBA(str) ||
|
|
762
|
+
Util._hex4ColorToRGBA(str) ||
|
|
762
763
|
Util._hex6ColorToRGBA(str) ||
|
|
764
|
+
Util._hex8ColorToRGBA(str) ||
|
|
763
765
|
Util._rgbColorToRGBA(str) ||
|
|
764
766
|
Util._rgbaColorToRGBA(str) ||
|
|
765
767
|
Util._hslColorToRGBA(str));
|
|
@@ -808,6 +810,17 @@
|
|
|
808
810
|
};
|
|
809
811
|
}
|
|
810
812
|
},
|
|
813
|
+
// Parse #nnnnnnnn
|
|
814
|
+
_hex8ColorToRGBA(str) {
|
|
815
|
+
if (str[0] === '#' && str.length === 9) {
|
|
816
|
+
return {
|
|
817
|
+
r: parseInt(str.slice(1, 3), 16),
|
|
818
|
+
g: parseInt(str.slice(3, 5), 16),
|
|
819
|
+
b: parseInt(str.slice(5, 7), 16),
|
|
820
|
+
a: parseInt(str.slice(7, 9), 16) / 0xff,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
},
|
|
811
824
|
// Parse #nnnnnn
|
|
812
825
|
_hex6ColorToRGBA(str) {
|
|
813
826
|
if (str[0] === '#' && str.length === 7) {
|
|
@@ -819,6 +832,17 @@
|
|
|
819
832
|
};
|
|
820
833
|
}
|
|
821
834
|
},
|
|
835
|
+
// Parse #nnnn
|
|
836
|
+
_hex4ColorToRGBA(str) {
|
|
837
|
+
if (str[0] === '#' && str.length === 5) {
|
|
838
|
+
return {
|
|
839
|
+
r: parseInt(str[1] + str[1], 16),
|
|
840
|
+
g: parseInt(str[2] + str[2], 16),
|
|
841
|
+
b: parseInt(str[3] + str[3], 16),
|
|
842
|
+
a: parseInt(str[4] + str[4], 16) / 0xff,
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
},
|
|
822
846
|
// Parse #nnn
|
|
823
847
|
_hex3ColorToRGBA(str) {
|
|
824
848
|
if (str[0] === '#' && str.length === 4) {
|
|
@@ -1089,6 +1113,30 @@
|
|
|
1089
1113
|
c.width = 0;
|
|
1090
1114
|
c.height = 0;
|
|
1091
1115
|
});
|
|
1116
|
+
},
|
|
1117
|
+
drawRoundedRectPath(context, width, height, cornerRadius) {
|
|
1118
|
+
let topLeft = 0;
|
|
1119
|
+
let topRight = 0;
|
|
1120
|
+
let bottomLeft = 0;
|
|
1121
|
+
let bottomRight = 0;
|
|
1122
|
+
if (typeof cornerRadius === 'number') {
|
|
1123
|
+
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
1127
|
+
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
1128
|
+
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
1129
|
+
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
1130
|
+
}
|
|
1131
|
+
context.moveTo(topLeft, 0);
|
|
1132
|
+
context.lineTo(width - topRight, 0);
|
|
1133
|
+
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
1134
|
+
context.lineTo(width, height - bottomRight);
|
|
1135
|
+
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
1136
|
+
context.lineTo(bottomLeft, height);
|
|
1137
|
+
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
1138
|
+
context.lineTo(0, topLeft);
|
|
1139
|
+
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
1092
1140
|
}
|
|
1093
1141
|
};
|
|
1094
1142
|
|
|
@@ -1749,8 +1797,11 @@
|
|
|
1749
1797
|
* @method
|
|
1750
1798
|
* @name Konva.Context#isPointInPath
|
|
1751
1799
|
*/
|
|
1752
|
-
isPointInPath(x, y) {
|
|
1753
|
-
|
|
1800
|
+
isPointInPath(x, y, path, fillRule) {
|
|
1801
|
+
if (path) {
|
|
1802
|
+
return this._context.isPointInPath(path, x, y, fillRule);
|
|
1803
|
+
}
|
|
1804
|
+
return this._context.isPointInPath(x, y, fillRule);
|
|
1754
1805
|
}
|
|
1755
1806
|
/**
|
|
1756
1807
|
* fill function.
|
|
@@ -5304,22 +5355,27 @@
|
|
|
5304
5355
|
* add a child and children into container
|
|
5305
5356
|
* @name Konva.Container#add
|
|
5306
5357
|
* @method
|
|
5307
|
-
* @param {...Konva.Node}
|
|
5358
|
+
* @param {...Konva.Node} children
|
|
5308
5359
|
* @returns {Container}
|
|
5309
5360
|
* @example
|
|
5310
5361
|
* layer.add(rect);
|
|
5311
5362
|
* layer.add(shape1, shape2, shape3);
|
|
5363
|
+
* // empty arrays are accepted, though each individual child must be defined
|
|
5364
|
+
* layer.add(...shapes);
|
|
5312
5365
|
* // remember to redraw layer if you changed something
|
|
5313
5366
|
* layer.draw();
|
|
5314
5367
|
*/
|
|
5315
5368
|
add(...children) {
|
|
5316
|
-
if (
|
|
5317
|
-
|
|
5318
|
-
|
|
5369
|
+
if (children.length === 0) {
|
|
5370
|
+
return this;
|
|
5371
|
+
}
|
|
5372
|
+
if (children.length > 1) {
|
|
5373
|
+
for (var i = 0; i < children.length; i++) {
|
|
5374
|
+
this.add(children[i]);
|
|
5319
5375
|
}
|
|
5320
5376
|
return this;
|
|
5321
5377
|
}
|
|
5322
|
-
|
|
5378
|
+
const child = children[0];
|
|
5323
5379
|
if (child.getParent()) {
|
|
5324
5380
|
child.moveTo(this);
|
|
5325
5381
|
return this;
|
|
@@ -11740,6 +11796,7 @@
|
|
|
11740
11796
|
_sceneFunc(context) {
|
|
11741
11797
|
const width = this.getWidth();
|
|
11742
11798
|
const height = this.getHeight();
|
|
11799
|
+
const cornerRadius = this.cornerRadius();
|
|
11743
11800
|
const image = this.attrs.image;
|
|
11744
11801
|
let params;
|
|
11745
11802
|
if (image) {
|
|
@@ -11762,20 +11819,31 @@
|
|
|
11762
11819
|
params = [image, 0, 0, width, height];
|
|
11763
11820
|
}
|
|
11764
11821
|
}
|
|
11765
|
-
if (this.hasFill() || this.hasStroke()) {
|
|
11822
|
+
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
11766
11823
|
context.beginPath();
|
|
11767
|
-
|
|
11824
|
+
cornerRadius
|
|
11825
|
+
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
11826
|
+
: context.rect(0, 0, width, height);
|
|
11768
11827
|
context.closePath();
|
|
11769
11828
|
context.fillStrokeShape(this);
|
|
11770
11829
|
}
|
|
11771
11830
|
if (image) {
|
|
11831
|
+
if (cornerRadius) {
|
|
11832
|
+
context.clip();
|
|
11833
|
+
}
|
|
11772
11834
|
context.drawImage.apply(context, params);
|
|
11773
11835
|
}
|
|
11836
|
+
// If you need to draw later, you need to execute save/restore
|
|
11774
11837
|
}
|
|
11775
11838
|
_hitFunc(context) {
|
|
11776
|
-
var width = this.width(), height = this.height();
|
|
11839
|
+
var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
11777
11840
|
context.beginPath();
|
|
11778
|
-
|
|
11841
|
+
if (!cornerRadius) {
|
|
11842
|
+
context.rect(0, 0, width, height);
|
|
11843
|
+
}
|
|
11844
|
+
else {
|
|
11845
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
11846
|
+
}
|
|
11779
11847
|
context.closePath();
|
|
11780
11848
|
context.fillStrokeShape(this);
|
|
11781
11849
|
}
|
|
@@ -11816,6 +11884,24 @@
|
|
|
11816
11884
|
}
|
|
11817
11885
|
Image.prototype.className = 'Image';
|
|
11818
11886
|
_registerNode(Image);
|
|
11887
|
+
/**
|
|
11888
|
+
* get/set corner radius
|
|
11889
|
+
* @method
|
|
11890
|
+
* @name Konva.Image#cornerRadius
|
|
11891
|
+
* @param {Number} cornerRadius
|
|
11892
|
+
* @returns {Number}
|
|
11893
|
+
* @example
|
|
11894
|
+
* // get corner radius
|
|
11895
|
+
* var cornerRadius = image.cornerRadius();
|
|
11896
|
+
*
|
|
11897
|
+
* // set corner radius
|
|
11898
|
+
* image.cornerRadius(10);
|
|
11899
|
+
*
|
|
11900
|
+
* // set different corner radius values
|
|
11901
|
+
* // top-left, top-right, bottom-right, bottom-left
|
|
11902
|
+
* image.cornerRadius([0, 10, 20, 30]);
|
|
11903
|
+
*/
|
|
11904
|
+
Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
11819
11905
|
/**
|
|
11820
11906
|
* get/set image source. It can be image, canvas or video element
|
|
11821
11907
|
* @name Konva.Image#image
|
|
@@ -12306,28 +12392,7 @@
|
|
|
12306
12392
|
context.rect(0, 0, width, height);
|
|
12307
12393
|
}
|
|
12308
12394
|
else {
|
|
12309
|
-
|
|
12310
|
-
let topRight = 0;
|
|
12311
|
-
let bottomLeft = 0;
|
|
12312
|
-
let bottomRight = 0;
|
|
12313
|
-
if (typeof cornerRadius === 'number') {
|
|
12314
|
-
topLeft = topRight = bottomLeft = bottomRight = Math.min(cornerRadius, width / 2, height / 2);
|
|
12315
|
-
}
|
|
12316
|
-
else {
|
|
12317
|
-
topLeft = Math.min(cornerRadius[0] || 0, width / 2, height / 2);
|
|
12318
|
-
topRight = Math.min(cornerRadius[1] || 0, width / 2, height / 2);
|
|
12319
|
-
bottomRight = Math.min(cornerRadius[2] || 0, width / 2, height / 2);
|
|
12320
|
-
bottomLeft = Math.min(cornerRadius[3] || 0, width / 2, height / 2);
|
|
12321
|
-
}
|
|
12322
|
-
context.moveTo(topLeft, 0);
|
|
12323
|
-
context.lineTo(width - topRight, 0);
|
|
12324
|
-
context.arc(width - topRight, topRight, topRight, (Math.PI * 3) / 2, 0, false);
|
|
12325
|
-
context.lineTo(width, height - bottomRight);
|
|
12326
|
-
context.arc(width - bottomRight, height - bottomRight, bottomRight, 0, Math.PI / 2, false);
|
|
12327
|
-
context.lineTo(bottomLeft, height);
|
|
12328
|
-
context.arc(bottomLeft, height - bottomLeft, bottomLeft, Math.PI / 2, Math.PI, false);
|
|
12329
|
-
context.lineTo(0, topLeft);
|
|
12330
|
-
context.arc(topLeft, topLeft, topLeft, Math.PI, (Math.PI * 3) / 2, false);
|
|
12395
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
12331
12396
|
}
|
|
12332
12397
|
context.closePath();
|
|
12333
12398
|
context.fillStrokeShape(this);
|
|
@@ -13438,14 +13503,13 @@
|
|
|
13438
13503
|
spacesNumber = text.split(' ').length - 1;
|
|
13439
13504
|
oneWord = spacesNumber === 0;
|
|
13440
13505
|
lineWidth =
|
|
13441
|
-
align === JUSTIFY && lastLine
|
|
13442
|
-
? totalWidth - padding * 2
|
|
13443
|
-
: width;
|
|
13506
|
+
align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
13444
13507
|
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + Math.round(fontSize / 2));
|
|
13445
13508
|
// I have no idea what is real ratio
|
|
13446
13509
|
// just /15 looks good enough
|
|
13447
13510
|
context.lineWidth = fontSize / 15;
|
|
13448
|
-
|
|
13511
|
+
const gradient = this._getLinearGradient();
|
|
13512
|
+
context.strokeStyle = gradient || fill;
|
|
13449
13513
|
context.stroke();
|
|
13450
13514
|
context.restore();
|
|
13451
13515
|
}
|
|
@@ -13461,7 +13525,8 @@
|
|
|
13461
13525
|
: width;
|
|
13462
13526
|
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY);
|
|
13463
13527
|
context.lineWidth = fontSize / 15;
|
|
13464
|
-
|
|
13528
|
+
const gradient = this._getLinearGradient();
|
|
13529
|
+
context.strokeStyle = gradient || fill;
|
|
13465
13530
|
context.stroke();
|
|
13466
13531
|
context.restore();
|
|
13467
13532
|
}
|
|
@@ -13567,7 +13632,8 @@
|
|
|
13567
13632
|
normalizeFontFamily(this.fontFamily()));
|
|
13568
13633
|
}
|
|
13569
13634
|
_addTextLine(line) {
|
|
13570
|
-
|
|
13635
|
+
const align = this.align();
|
|
13636
|
+
if (align === JUSTIFY) {
|
|
13571
13637
|
line = line.trim();
|
|
13572
13638
|
}
|
|
13573
13639
|
var width = this._getTextWidth(line);
|
|
@@ -15636,6 +15702,11 @@
|
|
|
15636
15702
|
toObject() {
|
|
15637
15703
|
return Node.prototype.toObject.call(this);
|
|
15638
15704
|
}
|
|
15705
|
+
// overwrite clone to NOT use method from Container
|
|
15706
|
+
clone(obj) {
|
|
15707
|
+
var node = Node.prototype.clone.call(this, obj);
|
|
15708
|
+
return node;
|
|
15709
|
+
}
|
|
15639
15710
|
getClientRect() {
|
|
15640
15711
|
if (this.nodes().length > 0) {
|
|
15641
15712
|
return super.getClientRect();
|
|
@@ -15697,8 +15768,8 @@
|
|
|
15697
15768
|
* get/set resize ability. If false it will automatically hide resizing handlers
|
|
15698
15769
|
* @name Konva.Transformer#resizeEnabled
|
|
15699
15770
|
* @method
|
|
15700
|
-
* @param {
|
|
15701
|
-
* @returns {
|
|
15771
|
+
* @param {Boolean} enabled
|
|
15772
|
+
* @returns {Boolean}
|
|
15702
15773
|
* @example
|
|
15703
15774
|
* // get
|
|
15704
15775
|
* var resizeEnabled = transformer.resizeEnabled();
|
|
@@ -15709,9 +15780,9 @@
|
|
|
15709
15780
|
Factory.addGetterSetter(Transformer, 'resizeEnabled', true);
|
|
15710
15781
|
/**
|
|
15711
15782
|
* get/set anchor size. Default is 10
|
|
15712
|
-
* @name Konva.Transformer#
|
|
15783
|
+
* @name Konva.Transformer#anchorSize
|
|
15713
15784
|
* @method
|
|
15714
|
-
* @param {Number}
|
|
15785
|
+
* @param {Number} size
|
|
15715
15786
|
* @returns {Number}
|
|
15716
15787
|
* @example
|
|
15717
15788
|
* // get
|
|
@@ -15795,8 +15866,8 @@
|
|
|
15795
15866
|
* get/set anchor stroke color
|
|
15796
15867
|
* @name Konva.Transformer#anchorStroke
|
|
15797
15868
|
* @method
|
|
15798
|
-
* @param {
|
|
15799
|
-
* @returns {
|
|
15869
|
+
* @param {String} strokeColor
|
|
15870
|
+
* @returns {String}
|
|
15800
15871
|
* @example
|
|
15801
15872
|
* // get
|
|
15802
15873
|
* var anchorStroke = transformer.anchorStroke();
|
|
@@ -15809,8 +15880,8 @@
|
|
|
15809
15880
|
* get/set anchor stroke width
|
|
15810
15881
|
* @name Konva.Transformer#anchorStrokeWidth
|
|
15811
15882
|
* @method
|
|
15812
|
-
* @param {
|
|
15813
|
-
* @returns {
|
|
15883
|
+
* @param {Number} anchorStrokeWidth
|
|
15884
|
+
* @returns {Number}
|
|
15814
15885
|
* @example
|
|
15815
15886
|
* // get
|
|
15816
15887
|
* var anchorStrokeWidth = transformer.anchorStrokeWidth();
|
|
@@ -15823,8 +15894,8 @@
|
|
|
15823
15894
|
* get/set anchor fill color
|
|
15824
15895
|
* @name Konva.Transformer#anchorFill
|
|
15825
15896
|
* @method
|
|
15826
|
-
* @param {
|
|
15827
|
-
* @returns {
|
|
15897
|
+
* @param {String} anchorFill
|
|
15898
|
+
* @returns {String}
|
|
15828
15899
|
* @example
|
|
15829
15900
|
* // get
|
|
15830
15901
|
* var anchorFill = transformer.anchorFill();
|
|
@@ -15837,7 +15908,7 @@
|
|
|
15837
15908
|
* get/set anchor corner radius
|
|
15838
15909
|
* @name Konva.Transformer#anchorCornerRadius
|
|
15839
15910
|
* @method
|
|
15840
|
-
* @param {Number}
|
|
15911
|
+
* @param {Number} radius
|
|
15841
15912
|
* @returns {Number}
|
|
15842
15913
|
* @example
|
|
15843
15914
|
* // get
|
|
@@ -15865,8 +15936,8 @@
|
|
|
15865
15936
|
* get/set border stroke width
|
|
15866
15937
|
* @name Konva.Transformer#borderStrokeWidth
|
|
15867
15938
|
* @method
|
|
15868
|
-
* @param {
|
|
15869
|
-
* @returns {
|
|
15939
|
+
* @param {Number} strokeWidth
|
|
15940
|
+
* @returns {Number}
|
|
15870
15941
|
* @example
|
|
15871
15942
|
* // get
|
|
15872
15943
|
* var borderStrokeWidth = transformer.borderStrokeWidth();
|
|
@@ -15879,8 +15950,8 @@
|
|
|
15879
15950
|
* get/set border dash array
|
|
15880
15951
|
* @name Konva.Transformer#borderDash
|
|
15881
15952
|
* @method
|
|
15882
|
-
* @param {
|
|
15883
|
-
* @returns {
|
|
15953
|
+
* @param {Array} dash array
|
|
15954
|
+
* @returns {Array}
|
|
15884
15955
|
* @example
|
|
15885
15956
|
* // get
|
|
15886
15957
|
* var borderDash = transformer.borderDash();
|