konva 8.2.3 → 8.3.2
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 +12 -0
- package/cmj/Node.js +8 -5
- package/cmj/Stage.js +1 -3
- package/cmj/Util.js +6 -1
- package/cmj/index-types.d.ts +1 -0
- package/cmj/shapes/Arc.d.ts +6 -0
- package/cmj/shapes/Arc.js +20 -0
- package/cmj/shapes/Image.d.ts +1 -1
- package/cmj/shapes/Image.js +2 -1
- package/cmj/shapes/Transformer.d.ts +2 -0
- package/cmj/shapes/Transformer.js +17 -13
- package/konva.js +77 -26
- package/konva.min.js +3 -3
- package/lib/Global.js +1 -1
- package/lib/Node.js +8 -5
- package/lib/Stage.js +1 -3
- package/lib/Util.js +6 -1
- package/lib/index-types.d.ts +1 -0
- package/lib/shapes/Arc.d.ts +6 -0
- package/lib/shapes/Arc.js +20 -0
- package/lib/shapes/Image.d.ts +1 -1
- package/lib/shapes/Image.js +2 -1
- package/lib/shapes/Transformer.d.ts +2 -0
- package/lib/shapes/Transformer.js +17 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,6 +128,18 @@ In order to run `konva` in nodejs environment you also need to install `canvas`
|
|
|
128
128
|
npm install konva canvas
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
+
Then you can use the same Konva API and all Konva demos will work just fine. You just don't need to use `container` attribute in your stage.
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import Konva from 'konva';
|
|
135
|
+
|
|
136
|
+
const stage = new Konva.Stage({
|
|
137
|
+
width: 500,
|
|
138
|
+
height: 500,
|
|
139
|
+
});
|
|
140
|
+
// then all regular Konva code will work
|
|
141
|
+
```
|
|
142
|
+
|
|
131
143
|
### CommonJS modules
|
|
132
144
|
|
|
133
145
|
By default `Konva` is delivered as ES modules. Some environments may automatically take CommonJS version of `Konva`. If it doesn't work for you, try to use `cmj` version explicitly:
|
package/cmj/Node.js
CHANGED
|
@@ -626,11 +626,14 @@ class Node {
|
|
|
626
626
|
Util_1.Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
627
627
|
return false;
|
|
628
628
|
}
|
|
629
|
-
var index = this.index;
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
629
|
+
var index = this.index, len = this.parent.getChildren().length;
|
|
630
|
+
if (index < len - 1) {
|
|
631
|
+
this.parent.children.splice(index, 1);
|
|
632
|
+
this.parent.children.push(this);
|
|
633
|
+
this.parent._setChildrenIndices();
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
return false;
|
|
634
637
|
}
|
|
635
638
|
moveUp() {
|
|
636
639
|
if (!this.parent) {
|
package/cmj/Stage.js
CHANGED
|
@@ -493,14 +493,12 @@ class Stage extends Container_1.Container {
|
|
|
493
493
|
const pointerId = pos.id;
|
|
494
494
|
const event = { evt: evt, pointerId };
|
|
495
495
|
let fireDblClick = false;
|
|
496
|
-
if (Global_1.Konva['_' + eventType + 'InDblClickWindow']
|
|
497
|
-
Global_1.Konva['_' + eventType + 'InDblClickWindowId'] === pointerId) {
|
|
496
|
+
if (Global_1.Konva['_' + eventType + 'InDblClickWindow']) {
|
|
498
497
|
fireDblClick = true;
|
|
499
498
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
500
499
|
}
|
|
501
500
|
else if (!DragAndDrop_1.DD.justDragged) {
|
|
502
501
|
Global_1.Konva['_' + eventType + 'InDblClickWindow'] = true;
|
|
503
|
-
Global_1.Konva['_' + eventType + 'InDblClickWindowId'] = pointerId;
|
|
504
502
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
505
503
|
}
|
|
506
504
|
this[eventType + 'DblTimeout'] = setTimeout(function () {
|
package/cmj/Util.js
CHANGED
|
@@ -478,7 +478,12 @@ exports.Util = {
|
|
|
478
478
|
_rgbaColorToRGBA(str) {
|
|
479
479
|
if (str.indexOf('rgba(') === 0) {
|
|
480
480
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
481
|
-
var parts = str.split(/ *, */).map(
|
|
481
|
+
var parts = str.split(/ *, */).map((n, index) => {
|
|
482
|
+
if (n.slice(-1) === '%') {
|
|
483
|
+
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
484
|
+
}
|
|
485
|
+
return Number(n);
|
|
486
|
+
});
|
|
482
487
|
return {
|
|
483
488
|
r: parts[0],
|
|
484
489
|
g: parts[1],
|
package/cmj/index-types.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ declare namespace Konva {
|
|
|
71
71
|
|
|
72
72
|
export const Stage: typeof import('./Stage').Stage;
|
|
73
73
|
export type Stage = import('./Stage').Stage;
|
|
74
|
+
export type StageConfig = import('./Stage').StageConfig;
|
|
74
75
|
export const stages: typeof import('./Stage').stages;
|
|
75
76
|
|
|
76
77
|
export const Layer: typeof import('./Layer').Layer;
|
package/cmj/shapes/Arc.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ export declare class Arc extends Shape<ArcConfig> {
|
|
|
12
12
|
getHeight(): number;
|
|
13
13
|
setWidth(width: any): void;
|
|
14
14
|
setHeight(height: any): void;
|
|
15
|
+
getSelfRect(): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
15
21
|
innerRadius: GetSet<number, this>;
|
|
16
22
|
outerRadius: GetSet<number, this>;
|
|
17
23
|
angle: GetSet<number, this>;
|
package/cmj/shapes/Arc.js
CHANGED
|
@@ -27,6 +27,26 @@ class Arc extends Shape_1.Shape {
|
|
|
27
27
|
setHeight(height) {
|
|
28
28
|
this.outerRadius(height / 2);
|
|
29
29
|
}
|
|
30
|
+
getSelfRect() {
|
|
31
|
+
const innerRadius = this.innerRadius();
|
|
32
|
+
const outerRadius = this.outerRadius();
|
|
33
|
+
const clockwise = this.clockwise();
|
|
34
|
+
const angle = Global_1.Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
35
|
+
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
36
|
+
const boundRightRatio = 1;
|
|
37
|
+
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
|
|
38
|
+
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
|
39
|
+
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
|
40
|
+
const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
|
|
41
|
+
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
|
42
|
+
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
|
43
|
+
return {
|
|
44
|
+
x: Math.round(boundLeft),
|
|
45
|
+
y: Math.round(clockwise ? -1 * boundBottom : boundTop),
|
|
46
|
+
width: Math.round(boundRight - boundLeft),
|
|
47
|
+
height: Math.round(boundBottom - boundTop)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
30
50
|
}
|
|
31
51
|
exports.Arc = Arc;
|
|
32
52
|
Arc.prototype._centroid = true;
|
package/cmj/shapes/Image.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Image extends Shape<ImageConfig> {
|
|
|
13
13
|
_hitFunc(context: any): void;
|
|
14
14
|
getWidth(): any;
|
|
15
15
|
getHeight(): any;
|
|
16
|
-
static fromURL(url: any, callback: any): void;
|
|
16
|
+
static fromURL(url: any, callback: any, onError?: any): void;
|
|
17
17
|
image: GetSet<CanvasImageSource | undefined, this>;
|
|
18
18
|
crop: GetSet<IRect, this>;
|
|
19
19
|
cropX: GetSet<number, this>;
|
package/cmj/shapes/Image.js
CHANGED
|
@@ -81,7 +81,7 @@ class Image extends Shape_1.Shape {
|
|
|
81
81
|
var _a, _b;
|
|
82
82
|
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
83
83
|
}
|
|
84
|
-
static fromURL(url, callback) {
|
|
84
|
+
static fromURL(url, callback, onError = null) {
|
|
85
85
|
var img = Util_1.Util.createImageElement();
|
|
86
86
|
img.onload = function () {
|
|
87
87
|
var image = new Image({
|
|
@@ -89,6 +89,7 @@ class Image extends Shape_1.Shape {
|
|
|
89
89
|
});
|
|
90
90
|
callback(image);
|
|
91
91
|
};
|
|
92
|
+
img.onerror = onError;
|
|
92
93
|
img.crossOrigin = 'Anonymous';
|
|
93
94
|
img.src = url;
|
|
94
95
|
}
|
|
@@ -44,6 +44,7 @@ export declare class Transformer extends Group {
|
|
|
44
44
|
attachTo(node: any): this;
|
|
45
45
|
setNode(node: any): this;
|
|
46
46
|
getNode(): Node<import("../Node").NodeConfig>;
|
|
47
|
+
_getEventNamespace(): string;
|
|
47
48
|
setNodes(nodes?: Array<Node>): this;
|
|
48
49
|
_proxyDrag(node: Node): void;
|
|
49
50
|
getNodes(): Node<import("../Node").NodeConfig>[];
|
|
@@ -107,6 +108,7 @@ export declare class Transformer extends Group {
|
|
|
107
108
|
flipEnabled: GetSet<boolean, this>;
|
|
108
109
|
ignoreStroke: GetSet<boolean, this>;
|
|
109
110
|
boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
|
|
111
|
+
anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
|
|
110
112
|
shouldOverdrawWholeArea: GetSet<boolean, this>;
|
|
111
113
|
useSingleNodeRotation: GetSet<boolean, this>;
|
|
112
114
|
}
|
|
@@ -42,9 +42,7 @@ var TRANSFORM_CHANGE_STR = [
|
|
|
42
42
|
'offsetYChange',
|
|
43
43
|
'transformsEnabledChange',
|
|
44
44
|
'strokeWidthChange',
|
|
45
|
-
]
|
|
46
|
-
.map((e) => e + `.${EVENTS_NAME}`)
|
|
47
|
-
.join(' ');
|
|
45
|
+
];
|
|
48
46
|
var ANGLES = {
|
|
49
47
|
'top-left': -45,
|
|
50
48
|
'top-center': 0,
|
|
@@ -162,6 +160,9 @@ class Transformer extends Group_1.Group {
|
|
|
162
160
|
getNode() {
|
|
163
161
|
return this._nodes && this._nodes[0];
|
|
164
162
|
}
|
|
163
|
+
_getEventNamespace() {
|
|
164
|
+
return EVENTS_NAME + this._id;
|
|
165
|
+
}
|
|
165
166
|
setNodes(nodes = []) {
|
|
166
167
|
if (this._nodes && this._nodes.length) {
|
|
167
168
|
this.detach();
|
|
@@ -174,9 +175,6 @@ class Transformer extends Group_1.Group {
|
|
|
174
175
|
this.rotation(0);
|
|
175
176
|
}
|
|
176
177
|
this._nodes.forEach((node) => {
|
|
177
|
-
const additionalEvents = node._attrsAffectingSize
|
|
178
|
-
.map((prop) => prop + 'Change.' + EVENTS_NAME)
|
|
179
|
-
.join(' ');
|
|
180
178
|
const onChange = () => {
|
|
181
179
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
182
180
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
@@ -186,10 +184,12 @@ class Transformer extends Group_1.Group {
|
|
|
186
184
|
this.update();
|
|
187
185
|
}
|
|
188
186
|
};
|
|
187
|
+
const additionalEvents = node._attrsAffectingSize
|
|
188
|
+
.map((prop) => prop + 'Change.' + this._getEventNamespace())
|
|
189
|
+
.join(' ');
|
|
189
190
|
node.on(additionalEvents, onChange);
|
|
190
|
-
node.on(TRANSFORM_CHANGE_STR, onChange);
|
|
191
|
-
node.on(`absoluteTransformChange.${
|
|
192
|
-
node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
|
|
191
|
+
node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
|
|
192
|
+
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
|
|
193
193
|
this._proxyDrag(node);
|
|
194
194
|
});
|
|
195
195
|
this._resetTransformCache();
|
|
@@ -201,13 +201,13 @@ class Transformer extends Group_1.Group {
|
|
|
201
201
|
}
|
|
202
202
|
_proxyDrag(node) {
|
|
203
203
|
let lastPos;
|
|
204
|
-
node.on(`dragstart.${
|
|
204
|
+
node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
|
|
205
205
|
lastPos = node.getAbsolutePosition();
|
|
206
206
|
if (!this.isDragging() && node !== this.findOne('.back')) {
|
|
207
207
|
this.startDrag(e, false);
|
|
208
208
|
}
|
|
209
209
|
});
|
|
210
|
-
node.on(`dragmove.${
|
|
210
|
+
node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
|
|
211
211
|
if (!lastPos) {
|
|
212
212
|
return;
|
|
213
213
|
}
|
|
@@ -240,7 +240,7 @@ class Transformer extends Group_1.Group {
|
|
|
240
240
|
detach() {
|
|
241
241
|
if (this._nodes) {
|
|
242
242
|
this._nodes.forEach((node) => {
|
|
243
|
-
node.off('.' +
|
|
243
|
+
node.off('.' + this._getEventNamespace());
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
246
|
this._nodes = [];
|
|
@@ -460,11 +460,14 @@ class Transformer extends Group_1.Group {
|
|
|
460
460
|
var stage = anchorNode.getStage();
|
|
461
461
|
stage.setPointersPositions(e);
|
|
462
462
|
const pp = stage.getPointerPosition();
|
|
463
|
-
|
|
463
|
+
let newNodePos = {
|
|
464
464
|
x: pp.x - this._anchorDragOffset.x,
|
|
465
465
|
y: pp.y - this._anchorDragOffset.y,
|
|
466
466
|
};
|
|
467
467
|
const oldAbs = anchorNode.getAbsolutePosition();
|
|
468
|
+
if (this.anchorDragBoundFunc()) {
|
|
469
|
+
newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
|
|
470
|
+
}
|
|
468
471
|
anchorNode.setAbsolutePosition(newNodePos);
|
|
469
472
|
const newAbs = anchorNode.getAbsolutePosition();
|
|
470
473
|
if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
|
|
@@ -939,6 +942,7 @@ Factory_1.Factory.addGetterSetter(Transformer, 'padding', 0, (0, Validators_1.ge
|
|
|
939
942
|
Factory_1.Factory.addGetterSetter(Transformer, 'node');
|
|
940
943
|
Factory_1.Factory.addGetterSetter(Transformer, 'nodes');
|
|
941
944
|
Factory_1.Factory.addGetterSetter(Transformer, 'boundBoxFunc');
|
|
945
|
+
Factory_1.Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
|
|
942
946
|
Factory_1.Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
|
|
943
947
|
Factory_1.Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
|
|
944
948
|
Factory_1.Factory.backCompat(Transformer, {
|
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v8.2
|
|
8
|
+
* Konva JavaScript Framework v8.3.2
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Tue Jan 04 2022
|
|
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.2
|
|
38
|
+
version: '8.3.2',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -794,7 +794,12 @@
|
|
|
794
794
|
_rgbaColorToRGBA(str) {
|
|
795
795
|
if (str.indexOf('rgba(') === 0) {
|
|
796
796
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
797
|
-
var parts = str.split(/ *, */).map(
|
|
797
|
+
var parts = str.split(/ *, */).map((n, index) => {
|
|
798
|
+
if (n.slice(-1) === '%') {
|
|
799
|
+
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
800
|
+
}
|
|
801
|
+
return Number(n);
|
|
802
|
+
});
|
|
798
803
|
return {
|
|
799
804
|
r: parts[0],
|
|
800
805
|
g: parts[1],
|
|
@@ -3449,11 +3454,14 @@
|
|
|
3449
3454
|
Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
3450
3455
|
return false;
|
|
3451
3456
|
}
|
|
3452
|
-
var index = this.index;
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
+
var index = this.index, len = this.parent.getChildren().length;
|
|
3458
|
+
if (index < len - 1) {
|
|
3459
|
+
this.parent.children.splice(index, 1);
|
|
3460
|
+
this.parent.children.push(this);
|
|
3461
|
+
this.parent._setChildrenIndices();
|
|
3462
|
+
return true;
|
|
3463
|
+
}
|
|
3464
|
+
return false;
|
|
3457
3465
|
}
|
|
3458
3466
|
/**
|
|
3459
3467
|
* move node up
|
|
@@ -6251,15 +6259,13 @@
|
|
|
6251
6259
|
const pointerId = pos.id;
|
|
6252
6260
|
const event = { evt: evt, pointerId };
|
|
6253
6261
|
let fireDblClick = false;
|
|
6254
|
-
if (Konva$2['_' + eventType + 'InDblClickWindow']
|
|
6255
|
-
Konva$2['_' + eventType + 'InDblClickWindowId'] === pointerId) {
|
|
6262
|
+
if (Konva$2['_' + eventType + 'InDblClickWindow']) {
|
|
6256
6263
|
fireDblClick = true;
|
|
6257
6264
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
6258
6265
|
}
|
|
6259
6266
|
else if (!DD.justDragged) {
|
|
6260
6267
|
// don't set inDblClickWindow after dragging
|
|
6261
6268
|
Konva$2['_' + eventType + 'InDblClickWindow'] = true;
|
|
6262
|
-
Konva$2['_' + eventType + 'InDblClickWindowId'] = pointerId;
|
|
6263
6269
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
6264
6270
|
}
|
|
6265
6271
|
this[eventType + 'DblTimeout'] = setTimeout(function () {
|
|
@@ -9719,6 +9725,26 @@
|
|
|
9719
9725
|
setHeight(height) {
|
|
9720
9726
|
this.outerRadius(height / 2);
|
|
9721
9727
|
}
|
|
9728
|
+
getSelfRect() {
|
|
9729
|
+
const innerRadius = this.innerRadius();
|
|
9730
|
+
const outerRadius = this.outerRadius();
|
|
9731
|
+
const clockwise = this.clockwise();
|
|
9732
|
+
const angle = Konva$2.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
9733
|
+
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
9734
|
+
const boundRightRatio = 1;
|
|
9735
|
+
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
|
|
9736
|
+
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
|
9737
|
+
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
|
9738
|
+
const boundRight = boundRightRatio * (outerRadius );
|
|
9739
|
+
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
|
9740
|
+
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
|
9741
|
+
return {
|
|
9742
|
+
x: Math.round(boundLeft),
|
|
9743
|
+
y: Math.round(clockwise ? -1 * boundBottom : boundTop),
|
|
9744
|
+
width: Math.round(boundRight - boundLeft),
|
|
9745
|
+
height: Math.round(boundBottom - boundTop)
|
|
9746
|
+
};
|
|
9747
|
+
}
|
|
9722
9748
|
}
|
|
9723
9749
|
Arc.prototype._centroid = true;
|
|
9724
9750
|
Arc.prototype.className = 'Arc';
|
|
@@ -11651,6 +11677,7 @@
|
|
|
11651
11677
|
* @memberof Konva.Image
|
|
11652
11678
|
* @param {String} url image source
|
|
11653
11679
|
* @param {Function} callback with Konva.Image instance as first argument
|
|
11680
|
+
* @param {Function} onError optional error handler
|
|
11654
11681
|
* @example
|
|
11655
11682
|
* Konva.Image.fromURL(imageURL, function(image){
|
|
11656
11683
|
* // image is Konva.Image instance
|
|
@@ -11658,7 +11685,7 @@
|
|
|
11658
11685
|
* layer.draw();
|
|
11659
11686
|
* });
|
|
11660
11687
|
*/
|
|
11661
|
-
static fromURL(url, callback) {
|
|
11688
|
+
static fromURL(url, callback, onError = null) {
|
|
11662
11689
|
var img = Util.createImageElement();
|
|
11663
11690
|
img.onload = function () {
|
|
11664
11691
|
var image = new Image({
|
|
@@ -11666,6 +11693,7 @@
|
|
|
11666
11693
|
});
|
|
11667
11694
|
callback(image);
|
|
11668
11695
|
};
|
|
11696
|
+
img.onerror = onError;
|
|
11669
11697
|
img.crossOrigin = 'Anonymous';
|
|
11670
11698
|
img.src = url;
|
|
11671
11699
|
}
|
|
@@ -14463,9 +14491,7 @@
|
|
|
14463
14491
|
'offsetYChange',
|
|
14464
14492
|
'transformsEnabledChange',
|
|
14465
14493
|
'strokeWidthChange',
|
|
14466
|
-
]
|
|
14467
|
-
.map((e) => e + `.${EVENTS_NAME}`)
|
|
14468
|
-
.join(' ');
|
|
14494
|
+
];
|
|
14469
14495
|
var ANGLES = {
|
|
14470
14496
|
'top-left': -45,
|
|
14471
14497
|
'top-center': 0,
|
|
@@ -14641,6 +14667,9 @@
|
|
|
14641
14667
|
getNode() {
|
|
14642
14668
|
return this._nodes && this._nodes[0];
|
|
14643
14669
|
}
|
|
14670
|
+
_getEventNamespace() {
|
|
14671
|
+
return EVENTS_NAME + this._id;
|
|
14672
|
+
}
|
|
14644
14673
|
setNodes(nodes = []) {
|
|
14645
14674
|
if (this._nodes && this._nodes.length) {
|
|
14646
14675
|
this.detach();
|
|
@@ -14653,9 +14682,6 @@
|
|
|
14653
14682
|
this.rotation(0);
|
|
14654
14683
|
}
|
|
14655
14684
|
this._nodes.forEach((node) => {
|
|
14656
|
-
const additionalEvents = node._attrsAffectingSize
|
|
14657
|
-
.map((prop) => prop + 'Change.' + EVENTS_NAME)
|
|
14658
|
-
.join(' ');
|
|
14659
14685
|
const onChange = () => {
|
|
14660
14686
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
14661
14687
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
@@ -14665,10 +14691,12 @@
|
|
|
14665
14691
|
this.update();
|
|
14666
14692
|
}
|
|
14667
14693
|
};
|
|
14694
|
+
const additionalEvents = node._attrsAffectingSize
|
|
14695
|
+
.map((prop) => prop + 'Change.' + this._getEventNamespace())
|
|
14696
|
+
.join(' ');
|
|
14668
14697
|
node.on(additionalEvents, onChange);
|
|
14669
|
-
node.on(TRANSFORM_CHANGE_STR, onChange);
|
|
14670
|
-
node.on(`absoluteTransformChange.${
|
|
14671
|
-
node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
|
|
14698
|
+
node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
|
|
14699
|
+
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
|
|
14672
14700
|
this._proxyDrag(node);
|
|
14673
14701
|
});
|
|
14674
14702
|
this._resetTransformCache();
|
|
@@ -14682,7 +14710,7 @@
|
|
|
14682
14710
|
}
|
|
14683
14711
|
_proxyDrag(node) {
|
|
14684
14712
|
let lastPos;
|
|
14685
|
-
node.on(`dragstart.${
|
|
14713
|
+
node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
|
|
14686
14714
|
lastPos = node.getAbsolutePosition();
|
|
14687
14715
|
// actual dragging of Transformer doesn't make sense
|
|
14688
14716
|
// but we need to make sure it also has all drag events
|
|
@@ -14690,7 +14718,7 @@
|
|
|
14690
14718
|
this.startDrag(e, false);
|
|
14691
14719
|
}
|
|
14692
14720
|
});
|
|
14693
|
-
node.on(`dragmove.${
|
|
14721
|
+
node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
|
|
14694
14722
|
if (!lastPos) {
|
|
14695
14723
|
return;
|
|
14696
14724
|
}
|
|
@@ -14740,7 +14768,7 @@
|
|
|
14740
14768
|
// remove events
|
|
14741
14769
|
if (this._nodes) {
|
|
14742
14770
|
this._nodes.forEach((node) => {
|
|
14743
|
-
node.off('.' +
|
|
14771
|
+
node.off('.' + this._getEventNamespace());
|
|
14744
14772
|
});
|
|
14745
14773
|
}
|
|
14746
14774
|
this._nodes = [];
|
|
@@ -14977,13 +15005,17 @@
|
|
|
14977
15005
|
var stage = anchorNode.getStage();
|
|
14978
15006
|
stage.setPointersPositions(e);
|
|
14979
15007
|
const pp = stage.getPointerPosition();
|
|
14980
|
-
|
|
15008
|
+
let newNodePos = {
|
|
14981
15009
|
x: pp.x - this._anchorDragOffset.x,
|
|
14982
15010
|
y: pp.y - this._anchorDragOffset.y,
|
|
14983
15011
|
};
|
|
14984
15012
|
const oldAbs = anchorNode.getAbsolutePosition();
|
|
15013
|
+
if (this.anchorDragBoundFunc()) {
|
|
15014
|
+
newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
|
|
15015
|
+
}
|
|
14985
15016
|
anchorNode.setAbsolutePosition(newNodePos);
|
|
14986
15017
|
const newAbs = anchorNode.getAbsolutePosition();
|
|
15018
|
+
// console.log(oldAbs, newNodePos, newAbs);
|
|
14987
15019
|
if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
|
|
14988
15020
|
return;
|
|
14989
15021
|
}
|
|
@@ -15792,6 +15824,25 @@
|
|
|
15792
15824
|
* });
|
|
15793
15825
|
*/
|
|
15794
15826
|
Factory.addGetterSetter(Transformer, 'boundBoxFunc');
|
|
15827
|
+
/**
|
|
15828
|
+
* get/set dragging func for transformer anchors
|
|
15829
|
+
* @name Konva.Transformer#anchorDragBoundFunc
|
|
15830
|
+
* @method
|
|
15831
|
+
* @param {Function} func
|
|
15832
|
+
* @returns {Function}
|
|
15833
|
+
* @example
|
|
15834
|
+
* // get
|
|
15835
|
+
* var anchorDragBoundFunc = transformer.anchorDragBoundFunc();
|
|
15836
|
+
*
|
|
15837
|
+
* // set
|
|
15838
|
+
* transformer.anchorDragBoundFunc(function(oldAbsPos, newAbsPos, event) {
|
|
15839
|
+
* return {
|
|
15840
|
+
* x: 0,
|
|
15841
|
+
* y: newAbsolutePosition.y
|
|
15842
|
+
* }
|
|
15843
|
+
* });
|
|
15844
|
+
*/
|
|
15845
|
+
Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
|
|
15795
15846
|
/**
|
|
15796
15847
|
* using this setting you can drag transformer group by dragging empty space between attached nodes
|
|
15797
15848
|
* shouldOverdrawWholeArea = true may temporary disable all events on attached nodes
|