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/lib/Global.js
CHANGED
|
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
|
|
|
13
13
|
: {};
|
|
14
14
|
export const Konva = {
|
|
15
15
|
_global: glob,
|
|
16
|
-
version: '8.2
|
|
16
|
+
version: '8.3.2',
|
|
17
17
|
isBrowser: detectBrowser(),
|
|
18
18
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
19
19
|
dblClickWindow: 400,
|
package/lib/Node.js
CHANGED
|
@@ -623,11 +623,14 @@ export class Node {
|
|
|
623
623
|
Util.warn('Node has no parent. moveToTop function is ignored.');
|
|
624
624
|
return false;
|
|
625
625
|
}
|
|
626
|
-
var index = this.index;
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
626
|
+
var index = this.index, len = this.parent.getChildren().length;
|
|
627
|
+
if (index < len - 1) {
|
|
628
|
+
this.parent.children.splice(index, 1);
|
|
629
|
+
this.parent.children.push(this);
|
|
630
|
+
this.parent._setChildrenIndices();
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
return false;
|
|
631
634
|
}
|
|
632
635
|
moveUp() {
|
|
633
636
|
if (!this.parent) {
|
package/lib/Stage.js
CHANGED
|
@@ -490,14 +490,12 @@ export class Stage extends Container {
|
|
|
490
490
|
const pointerId = pos.id;
|
|
491
491
|
const event = { evt: evt, pointerId };
|
|
492
492
|
let fireDblClick = false;
|
|
493
|
-
if (Konva['_' + eventType + 'InDblClickWindow']
|
|
494
|
-
Konva['_' + eventType + 'InDblClickWindowId'] === pointerId) {
|
|
493
|
+
if (Konva['_' + eventType + 'InDblClickWindow']) {
|
|
495
494
|
fireDblClick = true;
|
|
496
495
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
497
496
|
}
|
|
498
497
|
else if (!DD.justDragged) {
|
|
499
498
|
Konva['_' + eventType + 'InDblClickWindow'] = true;
|
|
500
|
-
Konva['_' + eventType + 'InDblClickWindowId'] = pointerId;
|
|
501
499
|
clearTimeout(this[eventType + 'DblTimeout']);
|
|
502
500
|
}
|
|
503
501
|
this[eventType + 'DblTimeout'] = setTimeout(function () {
|
package/lib/Util.js
CHANGED
|
@@ -474,7 +474,12 @@ export const Util = {
|
|
|
474
474
|
_rgbaColorToRGBA(str) {
|
|
475
475
|
if (str.indexOf('rgba(') === 0) {
|
|
476
476
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
477
|
-
var parts = str.split(/ *, */).map(
|
|
477
|
+
var parts = str.split(/ *, */).map((n, index) => {
|
|
478
|
+
if (n.slice(-1) === '%') {
|
|
479
|
+
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
480
|
+
}
|
|
481
|
+
return Number(n);
|
|
482
|
+
});
|
|
478
483
|
return {
|
|
479
484
|
r: parts[0],
|
|
480
485
|
g: parts[1],
|
package/lib/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/lib/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/lib/shapes/Arc.js
CHANGED
|
@@ -24,6 +24,26 @@ export class Arc extends Shape {
|
|
|
24
24
|
setHeight(height) {
|
|
25
25
|
this.outerRadius(height / 2);
|
|
26
26
|
}
|
|
27
|
+
getSelfRect() {
|
|
28
|
+
const innerRadius = this.innerRadius();
|
|
29
|
+
const outerRadius = this.outerRadius();
|
|
30
|
+
const clockwise = this.clockwise();
|
|
31
|
+
const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
32
|
+
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
33
|
+
const boundRightRatio = 1;
|
|
34
|
+
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
|
|
35
|
+
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
|
36
|
+
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
|
37
|
+
const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
|
|
38
|
+
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
|
39
|
+
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
|
40
|
+
return {
|
|
41
|
+
x: Math.round(boundLeft),
|
|
42
|
+
y: Math.round(clockwise ? -1 * boundBottom : boundTop),
|
|
43
|
+
width: Math.round(boundRight - boundLeft),
|
|
44
|
+
height: Math.round(boundBottom - boundTop)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
27
47
|
}
|
|
28
48
|
Arc.prototype._centroid = true;
|
|
29
49
|
Arc.prototype.className = 'Arc';
|
package/lib/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/lib/shapes/Image.js
CHANGED
|
@@ -78,7 +78,7 @@ export class Image extends Shape {
|
|
|
78
78
|
var _a, _b;
|
|
79
79
|
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
80
80
|
}
|
|
81
|
-
static fromURL(url, callback) {
|
|
81
|
+
static fromURL(url, callback, onError = null) {
|
|
82
82
|
var img = Util.createImageElement();
|
|
83
83
|
img.onload = function () {
|
|
84
84
|
var image = new Image({
|
|
@@ -86,6 +86,7 @@ export class Image extends Shape {
|
|
|
86
86
|
});
|
|
87
87
|
callback(image);
|
|
88
88
|
};
|
|
89
|
+
img.onerror = onError;
|
|
89
90
|
img.crossOrigin = 'Anonymous';
|
|
90
91
|
img.src = url;
|
|
91
92
|
}
|
|
@@ -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
|
}
|
|
@@ -39,9 +39,7 @@ var TRANSFORM_CHANGE_STR = [
|
|
|
39
39
|
'offsetYChange',
|
|
40
40
|
'transformsEnabledChange',
|
|
41
41
|
'strokeWidthChange',
|
|
42
|
-
]
|
|
43
|
-
.map((e) => e + `.${EVENTS_NAME}`)
|
|
44
|
-
.join(' ');
|
|
42
|
+
];
|
|
45
43
|
var ANGLES = {
|
|
46
44
|
'top-left': -45,
|
|
47
45
|
'top-center': 0,
|
|
@@ -159,6 +157,9 @@ export class Transformer extends Group {
|
|
|
159
157
|
getNode() {
|
|
160
158
|
return this._nodes && this._nodes[0];
|
|
161
159
|
}
|
|
160
|
+
_getEventNamespace() {
|
|
161
|
+
return EVENTS_NAME + this._id;
|
|
162
|
+
}
|
|
162
163
|
setNodes(nodes = []) {
|
|
163
164
|
if (this._nodes && this._nodes.length) {
|
|
164
165
|
this.detach();
|
|
@@ -171,9 +172,6 @@ export class Transformer extends Group {
|
|
|
171
172
|
this.rotation(0);
|
|
172
173
|
}
|
|
173
174
|
this._nodes.forEach((node) => {
|
|
174
|
-
const additionalEvents = node._attrsAffectingSize
|
|
175
|
-
.map((prop) => prop + 'Change.' + EVENTS_NAME)
|
|
176
|
-
.join(' ');
|
|
177
175
|
const onChange = () => {
|
|
178
176
|
if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
|
|
179
177
|
this.rotation(this.nodes()[0].getAbsoluteRotation());
|
|
@@ -183,10 +181,12 @@ export class Transformer extends Group {
|
|
|
183
181
|
this.update();
|
|
184
182
|
}
|
|
185
183
|
};
|
|
184
|
+
const additionalEvents = node._attrsAffectingSize
|
|
185
|
+
.map((prop) => prop + 'Change.' + this._getEventNamespace())
|
|
186
|
+
.join(' ');
|
|
186
187
|
node.on(additionalEvents, onChange);
|
|
187
|
-
node.on(TRANSFORM_CHANGE_STR, onChange);
|
|
188
|
-
node.on(`absoluteTransformChange.${
|
|
189
|
-
node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
|
|
188
|
+
node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
|
|
189
|
+
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
|
|
190
190
|
this._proxyDrag(node);
|
|
191
191
|
});
|
|
192
192
|
this._resetTransformCache();
|
|
@@ -198,13 +198,13 @@ export class Transformer extends Group {
|
|
|
198
198
|
}
|
|
199
199
|
_proxyDrag(node) {
|
|
200
200
|
let lastPos;
|
|
201
|
-
node.on(`dragstart.${
|
|
201
|
+
node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
|
|
202
202
|
lastPos = node.getAbsolutePosition();
|
|
203
203
|
if (!this.isDragging() && node !== this.findOne('.back')) {
|
|
204
204
|
this.startDrag(e, false);
|
|
205
205
|
}
|
|
206
206
|
});
|
|
207
|
-
node.on(`dragmove.${
|
|
207
|
+
node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
|
|
208
208
|
if (!lastPos) {
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
@@ -237,7 +237,7 @@ export class Transformer extends Group {
|
|
|
237
237
|
detach() {
|
|
238
238
|
if (this._nodes) {
|
|
239
239
|
this._nodes.forEach((node) => {
|
|
240
|
-
node.off('.' +
|
|
240
|
+
node.off('.' + this._getEventNamespace());
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
243
|
this._nodes = [];
|
|
@@ -457,11 +457,14 @@ export class Transformer extends Group {
|
|
|
457
457
|
var stage = anchorNode.getStage();
|
|
458
458
|
stage.setPointersPositions(e);
|
|
459
459
|
const pp = stage.getPointerPosition();
|
|
460
|
-
|
|
460
|
+
let newNodePos = {
|
|
461
461
|
x: pp.x - this._anchorDragOffset.x,
|
|
462
462
|
y: pp.y - this._anchorDragOffset.y,
|
|
463
463
|
};
|
|
464
464
|
const oldAbs = anchorNode.getAbsolutePosition();
|
|
465
|
+
if (this.anchorDragBoundFunc()) {
|
|
466
|
+
newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
|
|
467
|
+
}
|
|
465
468
|
anchorNode.setAbsolutePosition(newNodePos);
|
|
466
469
|
const newAbs = anchorNode.getAbsolutePosition();
|
|
467
470
|
if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
|
|
@@ -935,6 +938,7 @@ Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
|
|
|
935
938
|
Factory.addGetterSetter(Transformer, 'node');
|
|
936
939
|
Factory.addGetterSetter(Transformer, 'nodes');
|
|
937
940
|
Factory.addGetterSetter(Transformer, 'boundBoxFunc');
|
|
941
|
+
Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
|
|
938
942
|
Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
|
|
939
943
|
Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
|
|
940
944
|
Factory.backCompat(Transformer, {
|