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/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
5
5
|
|
|
6
6
|
## Not released:
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
## 5.0.1 - 2020-04-22
|
|
10
|
+
|
|
11
|
+
* Fixes for `Konva.Transformer` when parent scale is changed
|
|
12
|
+
* Fixes for `Konva.Transformer` when parent is draggable
|
|
13
|
+
* Performance optimizations
|
|
14
|
+
|
|
15
|
+
## 5.0.0 - 2020-04-21
|
|
9
16
|
|
|
10
17
|
* **New `Konva.Transformer` implementation!**. Old API should work. But I mark this release is `major` (breaking) just for smooth updates. Changes:
|
|
11
18
|
* Support of transforming multiple nodes at once: `tr.nodes([shape1, shape2])`.
|
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
}(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v5.0.
|
|
8
|
+
* Konva JavaScript Framework v5.0.1
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Wed Apr 22 2020
|
|
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)
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
: {};
|
|
77
77
|
var Konva = {
|
|
78
78
|
_global: glob,
|
|
79
|
-
version: '5.0.
|
|
79
|
+
version: '5.0.1',
|
|
80
80
|
isBrowser: detectBrowser(),
|
|
81
81
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
82
82
|
dblClickWindow: 400,
|
|
@@ -2587,7 +2587,7 @@
|
|
|
2587
2587
|
'offsetXChange.konva',
|
|
2588
2588
|
'offsetYChange.konva',
|
|
2589
2589
|
'transformsEnabledChange.konva'
|
|
2590
|
-
].join(SPACE)
|
|
2590
|
+
].join(SPACE);
|
|
2591
2591
|
// TODO: can we remove children from node?
|
|
2592
2592
|
var emptyChildren = new Collection();
|
|
2593
2593
|
var idCounter = 1;
|
|
@@ -2628,6 +2628,8 @@
|
|
|
2628
2628
|
this.parent = null;
|
|
2629
2629
|
this._cache = new Map();
|
|
2630
2630
|
this._lastPos = null;
|
|
2631
|
+
this._batchingTransformChange = false;
|
|
2632
|
+
this._needClearTransformCache = false;
|
|
2631
2633
|
this._filterUpToDate = false;
|
|
2632
2634
|
this._isUnderCache = false;
|
|
2633
2635
|
this.children = emptyChildren;
|
|
@@ -2635,12 +2637,13 @@
|
|
|
2635
2637
|
this.setAttrs(config);
|
|
2636
2638
|
// event bindings for cache handling
|
|
2637
2639
|
this.on(TRANSFORM_CHANGE_STR, function () {
|
|
2640
|
+
if (_this._batchingTransformChange) {
|
|
2641
|
+
_this._needClearTransformCache = true;
|
|
2642
|
+
return;
|
|
2643
|
+
}
|
|
2638
2644
|
_this._clearCache(TRANSFORM);
|
|
2639
2645
|
_this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
2640
2646
|
});
|
|
2641
|
-
this.on(SCALE_CHANGE_STR, function () {
|
|
2642
|
-
_this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
|
2643
|
-
});
|
|
2644
2647
|
this.on('visibleChange.konva', function () {
|
|
2645
2648
|
_this._clearSelfAndDescendantCache(VISIBLE);
|
|
2646
2649
|
});
|
|
@@ -2685,8 +2688,8 @@
|
|
|
2685
2688
|
Node.prototype._clearSelfAndDescendantCache = function (attr, forceEvent) {
|
|
2686
2689
|
this._clearCache(attr);
|
|
2687
2690
|
// trigger clear cache, so transformer can use it
|
|
2688
|
-
if (forceEvent) {
|
|
2689
|
-
this.fire('
|
|
2691
|
+
if (forceEvent && attr === ABSOLUTE_TRANSFORM) {
|
|
2692
|
+
this.fire('_clearTransformCache');
|
|
2690
2693
|
}
|
|
2691
2694
|
// skip clearing if node is cached with canvas
|
|
2692
2695
|
// for performance reasons !!!
|
|
@@ -3429,9 +3432,26 @@
|
|
|
3429
3432
|
}
|
|
3430
3433
|
return depth;
|
|
3431
3434
|
};
|
|
3435
|
+
// sometimes we do several attributes changes
|
|
3436
|
+
// like node.position(pos)
|
|
3437
|
+
// for performance reasons, lets batch transform reset
|
|
3438
|
+
// so it work faster
|
|
3439
|
+
Node.prototype._batchTransformChanges = function (func) {
|
|
3440
|
+
this._batchingTransformChange = true;
|
|
3441
|
+
func();
|
|
3442
|
+
this._batchingTransformChange = false;
|
|
3443
|
+
if (this._needClearTransformCache) {
|
|
3444
|
+
this._clearCache(TRANSFORM);
|
|
3445
|
+
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM, true);
|
|
3446
|
+
}
|
|
3447
|
+
this._needClearTransformCache = false;
|
|
3448
|
+
};
|
|
3432
3449
|
Node.prototype.setPosition = function (pos) {
|
|
3433
|
-
this
|
|
3434
|
-
this.
|
|
3450
|
+
var _this = this;
|
|
3451
|
+
this._batchTransformChanges(function () {
|
|
3452
|
+
_this.x(pos.x);
|
|
3453
|
+
_this.y(pos.y);
|
|
3454
|
+
});
|
|
3435
3455
|
return this;
|
|
3436
3456
|
};
|
|
3437
3457
|
Node.prototype.getPosition = function () {
|
|
@@ -3468,8 +3488,9 @@
|
|
|
3468
3488
|
this.attrs.y = origTrans.y;
|
|
3469
3489
|
delete origTrans.x;
|
|
3470
3490
|
delete origTrans.y;
|
|
3471
|
-
//
|
|
3472
|
-
|
|
3491
|
+
// important, use non cached value
|
|
3492
|
+
this._clearCache(TRANSFORM);
|
|
3493
|
+
it = this._getAbsoluteTransform();
|
|
3473
3494
|
it.invert();
|
|
3474
3495
|
it.translate(pos.x, pos.y);
|
|
3475
3496
|
pos = {
|
|
@@ -3485,8 +3506,8 @@
|
|
|
3485
3506
|
for (key in trans) {
|
|
3486
3507
|
this.attrs[key] = trans[key];
|
|
3487
3508
|
}
|
|
3488
|
-
this._clearCache(TRANSFORM);
|
|
3489
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
3509
|
+
// this._clearCache(TRANSFORM);
|
|
3510
|
+
// this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
3490
3511
|
};
|
|
3491
3512
|
Node.prototype._clearTransform = function () {
|
|
3492
3513
|
var trans = {
|
|
@@ -3509,8 +3530,6 @@
|
|
|
3509
3530
|
this.attrs.offsetY = 0;
|
|
3510
3531
|
this.attrs.skewX = 0;
|
|
3511
3532
|
this.attrs.skewY = 0;
|
|
3512
|
-
this._clearCache(TRANSFORM);
|
|
3513
|
-
this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
|
|
3514
3533
|
// return original transform
|
|
3515
3534
|
return trans;
|
|
3516
3535
|
};
|
|
@@ -3961,16 +3980,8 @@
|
|
|
3961
3980
|
* var scaleX = node.getAbsoluteScale().x;
|
|
3962
3981
|
*/
|
|
3963
3982
|
Node.prototype.getAbsoluteScale = function (top) {
|
|
3964
|
-
//
|
|
3965
|
-
|
|
3966
|
-
return this._getAbsoluteScale(top);
|
|
3967
|
-
}
|
|
3968
|
-
else {
|
|
3969
|
-
// if no argument, we can cache the result
|
|
3970
|
-
return this._getCache(ABSOLUTE_SCALE, this._getAbsoluteScale);
|
|
3971
|
-
}
|
|
3972
|
-
};
|
|
3973
|
-
Node.prototype._getAbsoluteScale = function (top) {
|
|
3983
|
+
// do not cache this calculations,
|
|
3984
|
+
// because it use cache transform
|
|
3974
3985
|
// this is special logic for caching with some shapes with shadow
|
|
3975
3986
|
var parent = this;
|
|
3976
3987
|
while (parent) {
|
|
@@ -14934,7 +14945,7 @@
|
|
|
14934
14945
|
return _this;
|
|
14935
14946
|
}
|
|
14936
14947
|
/**
|
|
14937
|
-
* alias to `tr.
|
|
14948
|
+
* alias to `tr.nodes([shape])`/ This method is deprecated and will be removed soon.
|
|
14938
14949
|
* @method
|
|
14939
14950
|
* @name Konva.Transformer#attachTo
|
|
14940
14951
|
* @returns {Konva.Transformer}
|
|
@@ -14977,9 +14988,7 @@
|
|
|
14977
14988
|
};
|
|
14978
14989
|
node.on(additionalEvents, onChange);
|
|
14979
14990
|
node.on(TRANSFORM_CHANGE_STR$1, onChange);
|
|
14980
|
-
node.on("
|
|
14981
|
-
_this._resetTransformCache();
|
|
14982
|
-
});
|
|
14991
|
+
node.on("_clearTransformCache." + EVENTS_NAME, onChange);
|
|
14983
14992
|
node.on("xChange." + EVENTS_NAME + " yChange." + EVENTS_NAME, onChange);
|
|
14984
14993
|
_this._proxyDrag(node);
|
|
14985
14994
|
});
|
|
@@ -15133,13 +15142,22 @@
|
|
|
15133
15142
|
strokeWidth: 1,
|
|
15134
15143
|
name: name + ' _anchor',
|
|
15135
15144
|
dragDistance: 0,
|
|
15136
|
-
draggable
|
|
15145
|
+
// make it draggable,
|
|
15146
|
+
// so activating the anchror will not start drag&drop of any parent
|
|
15147
|
+
draggable: true,
|
|
15137
15148
|
hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto'
|
|
15138
15149
|
});
|
|
15139
15150
|
var self = this;
|
|
15140
15151
|
anchor.on('mousedown touchstart', function (e) {
|
|
15141
15152
|
self._handleMouseDown(e);
|
|
15142
15153
|
});
|
|
15154
|
+
anchor.on('dragstart', function (e) {
|
|
15155
|
+
anchor.stopDrag();
|
|
15156
|
+
e.cancelBubble = true;
|
|
15157
|
+
});
|
|
15158
|
+
anchor.on('dragend', function (e) {
|
|
15159
|
+
e.cancelBubble = true;
|
|
15160
|
+
});
|
|
15143
15161
|
// add hover styling
|
|
15144
15162
|
anchor.on('mouseenter', function () {
|
|
15145
15163
|
var rad = Konva.getAngle(_this.rotation());
|
|
@@ -15952,7 +15970,8 @@
|
|
|
15952
15970
|
*/
|
|
15953
15971
|
Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
|
|
15954
15972
|
/**
|
|
15955
|
-
* get/set attached node of the Transformer. Transformer will adapt to its size and listen to its events
|
|
15973
|
+
* get/set attached node of the Transformer. Transformer will adapt to its size and listen to its events.
|
|
15974
|
+
* **This method is deprecated and will be removed soon.** Please use `tr.nodes([shape1, shape2]);` instead
|
|
15956
15975
|
* @method
|
|
15957
15976
|
* @name Konva.Transformer#Konva.Transformer#node
|
|
15958
15977
|
* @returns {Konva.Node}
|
|
@@ -15975,6 +15994,11 @@
|
|
|
15975
15994
|
*
|
|
15976
15995
|
* // set
|
|
15977
15996
|
* transformer.nodes([rect, circle]);
|
|
15997
|
+
* // push new item:
|
|
15998
|
+
*
|
|
15999
|
+
* const oldNodes = transformer.nodes();
|
|
16000
|
+
* const newNodes = oldNodes.concat([newShape]);
|
|
16001
|
+
* transformer.nodes(newNodes);
|
|
15978
16002
|
*/
|
|
15979
16003
|
Factory.addGetterSetter(Transformer, 'nodes');
|
|
15980
16004
|
/**
|