konva 8.3.14 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmj/Context.d.ts +29 -28
- package/cmj/Context.js +5 -2
- 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/Transformer.d.ts +1 -0
- package/cmj/shapes/Transformer.js +4 -0
- package/cmj/types.d.ts +1 -1
- package/konva.js +111 -46
- package/konva.min.js +3 -3
- package/lib/Context.d.ts +29 -28
- package/lib/Context.js +5 -2
- 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/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.0
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Thu Jan 05 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.0',
|
|
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.
|
|
@@ -11740,6 +11791,7 @@
|
|
|
11740
11791
|
_sceneFunc(context) {
|
|
11741
11792
|
const width = this.getWidth();
|
|
11742
11793
|
const height = this.getHeight();
|
|
11794
|
+
const cornerRadius = this.cornerRadius();
|
|
11743
11795
|
const image = this.attrs.image;
|
|
11744
11796
|
let params;
|
|
11745
11797
|
if (image) {
|
|
@@ -11762,20 +11814,31 @@
|
|
|
11762
11814
|
params = [image, 0, 0, width, height];
|
|
11763
11815
|
}
|
|
11764
11816
|
}
|
|
11765
|
-
if (this.hasFill() || this.hasStroke()) {
|
|
11817
|
+
if (this.hasFill() || this.hasStroke() || cornerRadius) {
|
|
11766
11818
|
context.beginPath();
|
|
11767
|
-
|
|
11819
|
+
cornerRadius
|
|
11820
|
+
? Util.drawRoundedRectPath(context, width, height, cornerRadius)
|
|
11821
|
+
: context.rect(0, 0, width, height);
|
|
11768
11822
|
context.closePath();
|
|
11769
11823
|
context.fillStrokeShape(this);
|
|
11770
11824
|
}
|
|
11771
11825
|
if (image) {
|
|
11826
|
+
if (cornerRadius) {
|
|
11827
|
+
context.clip();
|
|
11828
|
+
}
|
|
11772
11829
|
context.drawImage.apply(context, params);
|
|
11773
11830
|
}
|
|
11831
|
+
// If you need to draw later, you need to execute save/restore
|
|
11774
11832
|
}
|
|
11775
11833
|
_hitFunc(context) {
|
|
11776
|
-
var width = this.width(), height = this.height();
|
|
11834
|
+
var width = this.width(), height = this.height(), cornerRadius = this.cornerRadius();
|
|
11777
11835
|
context.beginPath();
|
|
11778
|
-
|
|
11836
|
+
if (!cornerRadius) {
|
|
11837
|
+
context.rect(0, 0, width, height);
|
|
11838
|
+
}
|
|
11839
|
+
else {
|
|
11840
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
11841
|
+
}
|
|
11779
11842
|
context.closePath();
|
|
11780
11843
|
context.fillStrokeShape(this);
|
|
11781
11844
|
}
|
|
@@ -11816,6 +11879,24 @@
|
|
|
11816
11879
|
}
|
|
11817
11880
|
Image.prototype.className = 'Image';
|
|
11818
11881
|
_registerNode(Image);
|
|
11882
|
+
/**
|
|
11883
|
+
* get/set corner radius
|
|
11884
|
+
* @method
|
|
11885
|
+
* @name Konva.Image#cornerRadius
|
|
11886
|
+
* @param {Number} cornerRadius
|
|
11887
|
+
* @returns {Number}
|
|
11888
|
+
* @example
|
|
11889
|
+
* // get corner radius
|
|
11890
|
+
* var cornerRadius = image.cornerRadius();
|
|
11891
|
+
*
|
|
11892
|
+
* // set corner radius
|
|
11893
|
+
* image.cornerRadius(10);
|
|
11894
|
+
*
|
|
11895
|
+
* // set different corner radius values
|
|
11896
|
+
* // top-left, top-right, bottom-right, bottom-left
|
|
11897
|
+
* image.cornerRadius([0, 10, 20, 30]);
|
|
11898
|
+
*/
|
|
11899
|
+
Factory.addGetterSetter(Image, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
|
|
11819
11900
|
/**
|
|
11820
11901
|
* get/set image source. It can be image, canvas or video element
|
|
11821
11902
|
* @name Konva.Image#image
|
|
@@ -12306,28 +12387,7 @@
|
|
|
12306
12387
|
context.rect(0, 0, width, height);
|
|
12307
12388
|
}
|
|
12308
12389
|
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);
|
|
12390
|
+
Util.drawRoundedRectPath(context, width, height, cornerRadius);
|
|
12331
12391
|
}
|
|
12332
12392
|
context.closePath();
|
|
12333
12393
|
context.fillStrokeShape(this);
|
|
@@ -15636,6 +15696,11 @@
|
|
|
15636
15696
|
toObject() {
|
|
15637
15697
|
return Node.prototype.toObject.call(this);
|
|
15638
15698
|
}
|
|
15699
|
+
// overwrite clone to NOT use method from Container
|
|
15700
|
+
clone(obj) {
|
|
15701
|
+
var node = Node.prototype.clone.call(this, obj);
|
|
15702
|
+
return node;
|
|
15703
|
+
}
|
|
15639
15704
|
getClientRect() {
|
|
15640
15705
|
if (this.nodes().length > 0) {
|
|
15641
15706
|
return super.getClientRect();
|
|
@@ -15697,8 +15762,8 @@
|
|
|
15697
15762
|
* get/set resize ability. If false it will automatically hide resizing handlers
|
|
15698
15763
|
* @name Konva.Transformer#resizeEnabled
|
|
15699
15764
|
* @method
|
|
15700
|
-
* @param {
|
|
15701
|
-
* @returns {
|
|
15765
|
+
* @param {Boolean} enabled
|
|
15766
|
+
* @returns {Boolean}
|
|
15702
15767
|
* @example
|
|
15703
15768
|
* // get
|
|
15704
15769
|
* var resizeEnabled = transformer.resizeEnabled();
|
|
@@ -15709,9 +15774,9 @@
|
|
|
15709
15774
|
Factory.addGetterSetter(Transformer, 'resizeEnabled', true);
|
|
15710
15775
|
/**
|
|
15711
15776
|
* get/set anchor size. Default is 10
|
|
15712
|
-
* @name Konva.Transformer#
|
|
15777
|
+
* @name Konva.Transformer#anchorSize
|
|
15713
15778
|
* @method
|
|
15714
|
-
* @param {Number}
|
|
15779
|
+
* @param {Number} size
|
|
15715
15780
|
* @returns {Number}
|
|
15716
15781
|
* @example
|
|
15717
15782
|
* // get
|
|
@@ -15795,8 +15860,8 @@
|
|
|
15795
15860
|
* get/set anchor stroke color
|
|
15796
15861
|
* @name Konva.Transformer#anchorStroke
|
|
15797
15862
|
* @method
|
|
15798
|
-
* @param {
|
|
15799
|
-
* @returns {
|
|
15863
|
+
* @param {String} strokeColor
|
|
15864
|
+
* @returns {String}
|
|
15800
15865
|
* @example
|
|
15801
15866
|
* // get
|
|
15802
15867
|
* var anchorStroke = transformer.anchorStroke();
|
|
@@ -15809,8 +15874,8 @@
|
|
|
15809
15874
|
* get/set anchor stroke width
|
|
15810
15875
|
* @name Konva.Transformer#anchorStrokeWidth
|
|
15811
15876
|
* @method
|
|
15812
|
-
* @param {
|
|
15813
|
-
* @returns {
|
|
15877
|
+
* @param {Number} anchorStrokeWidth
|
|
15878
|
+
* @returns {Number}
|
|
15814
15879
|
* @example
|
|
15815
15880
|
* // get
|
|
15816
15881
|
* var anchorStrokeWidth = transformer.anchorStrokeWidth();
|
|
@@ -15823,8 +15888,8 @@
|
|
|
15823
15888
|
* get/set anchor fill color
|
|
15824
15889
|
* @name Konva.Transformer#anchorFill
|
|
15825
15890
|
* @method
|
|
15826
|
-
* @param {
|
|
15827
|
-
* @returns {
|
|
15891
|
+
* @param {String} anchorFill
|
|
15892
|
+
* @returns {String}
|
|
15828
15893
|
* @example
|
|
15829
15894
|
* // get
|
|
15830
15895
|
* var anchorFill = transformer.anchorFill();
|
|
@@ -15837,7 +15902,7 @@
|
|
|
15837
15902
|
* get/set anchor corner radius
|
|
15838
15903
|
* @name Konva.Transformer#anchorCornerRadius
|
|
15839
15904
|
* @method
|
|
15840
|
-
* @param {Number}
|
|
15905
|
+
* @param {Number} radius
|
|
15841
15906
|
* @returns {Number}
|
|
15842
15907
|
* @example
|
|
15843
15908
|
* // get
|
|
@@ -15865,8 +15930,8 @@
|
|
|
15865
15930
|
* get/set border stroke width
|
|
15866
15931
|
* @name Konva.Transformer#borderStrokeWidth
|
|
15867
15932
|
* @method
|
|
15868
|
-
* @param {
|
|
15869
|
-
* @returns {
|
|
15933
|
+
* @param {Number} strokeWidth
|
|
15934
|
+
* @returns {Number}
|
|
15870
15935
|
* @example
|
|
15871
15936
|
* // get
|
|
15872
15937
|
* var borderStrokeWidth = transformer.borderStrokeWidth();
|
|
@@ -15879,8 +15944,8 @@
|
|
|
15879
15944
|
* get/set border dash array
|
|
15880
15945
|
* @name Konva.Transformer#borderDash
|
|
15881
15946
|
* @method
|
|
15882
|
-
* @param {
|
|
15883
|
-
* @returns {
|
|
15947
|
+
* @param {Array} dash array
|
|
15948
|
+
* @returns {Array}
|
|
15884
15949
|
* @example
|
|
15885
15950
|
* // get
|
|
15886
15951
|
* var borderDash = transformer.borderDash();
|