konva 5.0.0 → 5.0.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/CHANGELOG.md +8 -1
- package/konva.js +57 -33
- package/konva.min.js +3 -3
- package/lib/Global.js +1 -1
- package/lib/Node.js +25 -20
- package/lib/shapes/Transformer.js +9 -4
- package/package.json +1 -1
- package/types/Node.d.ts +4 -2
package/lib/Global.js
CHANGED
|
@@ -47,7 +47,7 @@ exports.glob = typeof global !== 'undefined'
|
|
|
47
47
|
: {};
|
|
48
48
|
exports.Konva = {
|
|
49
49
|
_global: exports.glob,
|
|
50
|
-
version: '5.0.
|
|
50
|
+
version: '5.0.1',
|
|
51
51
|
isBrowser: detectBrowser(),
|
|
52
52
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
53
53
|
dblClickWindow: 400,
|
package/lib/Node.js
CHANGED
|
@@ -73,18 +73,21 @@ var Node = (function () {
|
|
|
73
73
|
this.parent = null;
|
|
74
74
|
this._cache = new Map();
|
|
75
75
|
this._lastPos = null;
|
|
76
|
+
this._batchingTransformChange = false;
|
|
77
|
+
this._needClearTransformCache = false;
|
|
76
78
|
this._filterUpToDate = false;
|
|
77
79
|
this._isUnderCache = false;
|
|
78
80
|
this.children = emptyChildren;
|
|
79
81
|
this._dragEventId = null;
|
|
80
82
|
this.setAttrs(config);
|
|
81
83
|
this.on(TRANSFORM_CHANGE_STR, function () {
|
|
84
|
+
if (_this._batchingTransformChange) {
|
|
85
|
+
_this._needClearTransformCache = true;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
82
88
|
_this._clearCache(TRANSFORM);
|
|
83
89
|
_this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
84
90
|
});
|
|
85
|
-
this.on(SCALE_CHANGE_STR, function () {
|
|
86
|
-
_this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
|
87
|
-
});
|
|
88
91
|
this.on('visibleChange.konva', function () {
|
|
89
92
|
_this._clearSelfAndDescendantCache(VISIBLE);
|
|
90
93
|
});
|
|
@@ -122,8 +125,8 @@ var Node = (function () {
|
|
|
122
125
|
};
|
|
123
126
|
Node.prototype._clearSelfAndDescendantCache = function (attr, forceEvent) {
|
|
124
127
|
this._clearCache(attr);
|
|
125
|
-
if (forceEvent) {
|
|
126
|
-
this.fire('
|
|
128
|
+
if (forceEvent && attr === ABSOLUTE_TRANSFORM) {
|
|
129
|
+
this.fire('_clearTransformCache');
|
|
127
130
|
}
|
|
128
131
|
if (this.isCached()) {
|
|
129
132
|
return;
|
|
@@ -531,9 +534,22 @@ var Node = (function () {
|
|
|
531
534
|
}
|
|
532
535
|
return depth;
|
|
533
536
|
};
|
|
537
|
+
Node.prototype._batchTransformChanges = function (func) {
|
|
538
|
+
this._batchingTransformChange = true;
|
|
539
|
+
func();
|
|
540
|
+
this._batchingTransformChange = false;
|
|
541
|
+
if (this._needClearTransformCache) {
|
|
542
|
+
this._clearCache(TRANSFORM);
|
|
543
|
+
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM, true);
|
|
544
|
+
}
|
|
545
|
+
this._needClearTransformCache = false;
|
|
546
|
+
};
|
|
534
547
|
Node.prototype.setPosition = function (pos) {
|
|
535
|
-
this
|
|
536
|
-
this.
|
|
548
|
+
var _this = this;
|
|
549
|
+
this._batchTransformChanges(function () {
|
|
550
|
+
_this.x(pos.x);
|
|
551
|
+
_this.y(pos.y);
|
|
552
|
+
});
|
|
537
553
|
return this;
|
|
538
554
|
};
|
|
539
555
|
Node.prototype.getPosition = function () {
|
|
@@ -566,7 +582,8 @@ var Node = (function () {
|
|
|
566
582
|
this.attrs.y = origTrans.y;
|
|
567
583
|
delete origTrans.x;
|
|
568
584
|
delete origTrans.y;
|
|
569
|
-
|
|
585
|
+
this._clearCache(TRANSFORM);
|
|
586
|
+
it = this._getAbsoluteTransform();
|
|
570
587
|
it.invert();
|
|
571
588
|
it.translate(pos.x, pos.y);
|
|
572
589
|
pos = {
|
|
@@ -582,8 +599,6 @@ var Node = (function () {
|
|
|
582
599
|
for (key in trans) {
|
|
583
600
|
this.attrs[key] = trans[key];
|
|
584
601
|
}
|
|
585
|
-
this._clearCache(TRANSFORM);
|
|
586
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
587
602
|
};
|
|
588
603
|
Node.prototype._clearTransform = function () {
|
|
589
604
|
var trans = {
|
|
@@ -606,8 +621,6 @@ var Node = (function () {
|
|
|
606
621
|
this.attrs.offsetY = 0;
|
|
607
622
|
this.attrs.skewX = 0;
|
|
608
623
|
this.attrs.skewY = 0;
|
|
609
|
-
this._clearCache(TRANSFORM);
|
|
610
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
611
624
|
return trans;
|
|
612
625
|
};
|
|
613
626
|
Node.prototype.move = function (change) {
|
|
@@ -881,14 +894,6 @@ var Node = (function () {
|
|
|
881
894
|
}
|
|
882
895
|
};
|
|
883
896
|
Node.prototype.getAbsoluteScale = function (top) {
|
|
884
|
-
if (top) {
|
|
885
|
-
return this._getAbsoluteScale(top);
|
|
886
|
-
}
|
|
887
|
-
else {
|
|
888
|
-
return this._getCache(ABSOLUTE_SCALE, this._getAbsoluteScale);
|
|
889
|
-
}
|
|
890
|
-
};
|
|
891
|
-
Node.prototype._getAbsoluteScale = function (top) {
|
|
892
897
|
var parent = this;
|
|
893
898
|
while (parent) {
|
|
894
899
|
if (parent._isUnderCache) {
|
|
@@ -284,9 +284,7 @@ var Transformer = (function (_super) {
|
|
|
284
284
|
};
|
|
285
285
|
node.on(additionalEvents, onChange);
|
|
286
286
|
node.on(TRANSFORM_CHANGE_STR, onChange);
|
|
287
|
-
node.on("
|
|
288
|
-
_this._resetTransformCache();
|
|
289
|
-
});
|
|
287
|
+
node.on("_clearTransformCache." + EVENTS_NAME, onChange);
|
|
290
288
|
node.on("xChange." + EVENTS_NAME + " yChange." + EVENTS_NAME, onChange);
|
|
291
289
|
_this._proxyDrag(node);
|
|
292
290
|
});
|
|
@@ -421,13 +419,20 @@ var Transformer = (function (_super) {
|
|
|
421
419
|
strokeWidth: 1,
|
|
422
420
|
name: name + ' _anchor',
|
|
423
421
|
dragDistance: 0,
|
|
424
|
-
draggable:
|
|
422
|
+
draggable: true,
|
|
425
423
|
hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto'
|
|
426
424
|
});
|
|
427
425
|
var self = this;
|
|
428
426
|
anchor.on('mousedown touchstart', function (e) {
|
|
429
427
|
self._handleMouseDown(e);
|
|
430
428
|
});
|
|
429
|
+
anchor.on('dragstart', function (e) {
|
|
430
|
+
anchor.stopDrag();
|
|
431
|
+
e.cancelBubble = true;
|
|
432
|
+
});
|
|
433
|
+
anchor.on('dragend', function (e) {
|
|
434
|
+
e.cancelBubble = true;
|
|
435
|
+
});
|
|
431
436
|
anchor.on('mouseenter', function () {
|
|
432
437
|
var rad = Global_1.Konva.getAngle(_this.rotation());
|
|
433
438
|
var cursor = getCursor(name, rad);
|
package/package.json
CHANGED
package/types/Node.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
64
64
|
_cache: Map<string, any>;
|
|
65
65
|
_lastPos: Vector2d;
|
|
66
66
|
_attrsAffectingSize: string[];
|
|
67
|
+
_batchingTransformChange: boolean;
|
|
68
|
+
_needClearTransformCache: boolean;
|
|
67
69
|
_filterUpToDate: boolean;
|
|
68
70
|
_isUnderCache: boolean;
|
|
69
71
|
children: Collection<any>;
|
|
@@ -135,6 +137,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
135
137
|
getZIndex(): number;
|
|
136
138
|
getAbsoluteZIndex(): number;
|
|
137
139
|
getDepth(): number;
|
|
140
|
+
_batchTransformChanges(func: any): void;
|
|
138
141
|
setPosition(pos: any): this;
|
|
139
142
|
getPosition(): {
|
|
140
143
|
x: number;
|
|
@@ -181,8 +184,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
181
184
|
fire(eventType: any, evt?: any, bubble?: any): this;
|
|
182
185
|
getAbsoluteTransform(top?: Node): Transform;
|
|
183
186
|
_getAbsoluteTransform(top?: Node): Transform;
|
|
184
|
-
getAbsoluteScale(top?: any):
|
|
185
|
-
_getAbsoluteScale(top: any): {
|
|
187
|
+
getAbsoluteScale(top?: any): {
|
|
186
188
|
x: number;
|
|
187
189
|
y: number;
|
|
188
190
|
};
|