konva 4.2.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/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  }(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v4.2.0
8
+ * Konva JavaScript Framework v5.0.1
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Sat Mar 14 2020
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: '4.2.0',
79
+ version: '5.0.1',
80
80
  isBrowser: detectBrowser(),
81
81
  isUnminified: /param/.test(function (param) { }.toString()),
82
82
  dblClickWindow: 400,
@@ -114,12 +114,13 @@
114
114
  inDblClickWindow: false,
115
115
  /**
116
116
  * Global pixel ratio configuration. KonvaJS automatically detect pixel ratio of current device.
117
- * But you may override such property, if you want to use your value.
117
+ * But you may override such property, if you want to use your value. Set this value before any components initializations.
118
118
  * @property pixelRatio
119
119
  * @default undefined
120
120
  * @name pixelRatio
121
121
  * @memberof Konva
122
122
  * @example
123
+ * // before any Konva code:
123
124
  * Konva.pixelRatio = 1;
124
125
  */
125
126
  pixelRatio: undefined,
@@ -469,6 +470,50 @@
469
470
  var m0 = this.m[0], m1 = this.m[1], m2 = this.m[2], m3 = this.m[3], m4 = this.m[4], m5 = this.m[5], yt = (m0 * (y - m5) - m1 * (x - m4)) / (m0 * m3 - m1 * m2), xt = (x - m4 - m2 * yt) / m0;
470
471
  return this.translate(xt, yt);
471
472
  };
473
+ /**
474
+ * convert transformation matrix back into node's attributes
475
+ * @method
476
+ * @name Konva.Transform#decompose
477
+ * @returns {Konva.Transform}
478
+ */
479
+ Transform.prototype.decompose = function () {
480
+ var a = this.m[0];
481
+ var b = this.m[1];
482
+ var c = this.m[2];
483
+ var d = this.m[3];
484
+ var e = this.m[4];
485
+ var f = this.m[5];
486
+ var delta = a * d - b * c;
487
+ var result = {
488
+ x: e,
489
+ y: f,
490
+ rotation: 0,
491
+ scaleX: 0,
492
+ scaleY: 0,
493
+ skewX: 0,
494
+ skewY: 0
495
+ };
496
+ // Apply the QR-like decomposition.
497
+ if (a != 0 || b != 0) {
498
+ var r = Math.sqrt(a * a + b * b);
499
+ result.rotation = b > 0 ? Math.acos(a / r) : -Math.acos(a / r);
500
+ result.scaleX = r;
501
+ result.scaleY = delta / r;
502
+ result.skewX = Math.atan((a * c + b * d) / (r * r));
503
+ result.skewY = 0;
504
+ }
505
+ else if (c != 0 || d != 0) {
506
+ var s = Math.sqrt(c * c + d * d);
507
+ result.rotation =
508
+ Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
509
+ result.scaleX = delta / s;
510
+ result.scaleY = s;
511
+ result.skewX = 0;
512
+ result.skewY = Math.atan((a * c + b * d) / (s * s));
513
+ }
514
+ result.rotation = Util._getRotation(result.rotation);
515
+ return result;
516
+ };
472
517
  return Transform;
473
518
  }());
474
519
  // CONSTANTS
@@ -983,6 +1028,9 @@
983
1028
  _radToDeg: function (rad) {
984
1029
  return rad * DEG180_OVER_PI;
985
1030
  },
1031
+ _getRotation: function (radians) {
1032
+ return Konva.angleDeg ? Util._radToDeg(radians) : radians;
1033
+ },
986
1034
  _capitalize: function (str) {
987
1035
  return str.charAt(0).toUpperCase() + str.slice(1);
988
1036
  },
@@ -1425,6 +1473,17 @@
1425
1473
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1426
1474
  }
1427
1475
 
1476
+ var __assign = function() {
1477
+ __assign = Object.assign || function __assign(t) {
1478
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1479
+ s = arguments[i];
1480
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1481
+ }
1482
+ return t;
1483
+ };
1484
+ return __assign.apply(this, arguments);
1485
+ };
1486
+
1428
1487
  function __spreadArrays() {
1429
1488
  for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1430
1489
  for (var r = Array(s), k = 0, i = 0; i < il; i++)
@@ -2331,10 +2390,10 @@
2331
2390
  * @returns {Number}
2332
2391
  * @example
2333
2392
  * // get
2334
- * var pixelRatio = canvas.pixelRatio();
2393
+ * var pixelRatio = layer.getCanvas.pixelRatio();
2335
2394
  *
2336
2395
  * // set
2337
- * canvas.pixelRatio(100);
2396
+ * layer.getCanvas().pixelRatio(3);
2338
2397
  */
2339
2398
  Factory.addGetterSetter(Canvas, 'pixelRatio', undefined, getNumberValidator());
2340
2399
  var SceneCanvas = /** @class */ (function (_super) {
@@ -2528,7 +2587,7 @@
2528
2587
  'offsetXChange.konva',
2529
2588
  'offsetYChange.konva',
2530
2589
  'transformsEnabledChange.konva'
2531
- ].join(SPACE), SCALE_CHANGE_STR = ['scaleXChange.konva', 'scaleYChange.konva'].join(SPACE);
2590
+ ].join(SPACE);
2532
2591
  // TODO: can we remove children from node?
2533
2592
  var emptyChildren = new Collection();
2534
2593
  var idCounter = 1;
@@ -2569,6 +2628,8 @@
2569
2628
  this.parent = null;
2570
2629
  this._cache = new Map();
2571
2630
  this._lastPos = null;
2631
+ this._batchingTransformChange = false;
2632
+ this._needClearTransformCache = false;
2572
2633
  this._filterUpToDate = false;
2573
2634
  this._isUnderCache = false;
2574
2635
  this.children = emptyChildren;
@@ -2576,12 +2637,13 @@
2576
2637
  this.setAttrs(config);
2577
2638
  // event bindings for cache handling
2578
2639
  this.on(TRANSFORM_CHANGE_STR, function () {
2640
+ if (_this._batchingTransformChange) {
2641
+ _this._needClearTransformCache = true;
2642
+ return;
2643
+ }
2579
2644
  _this._clearCache(TRANSFORM);
2580
2645
  _this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
2581
2646
  });
2582
- this.on(SCALE_CHANGE_STR, function () {
2583
- _this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
2584
- });
2585
2647
  this.on('visibleChange.konva', function () {
2586
2648
  _this._clearSelfAndDescendantCache(VISIBLE);
2587
2649
  });
@@ -2623,8 +2685,12 @@
2623
2685
  * when the logic for a cached result depends on ancestor propagation, use this
2624
2686
  * method to clear self and children cache
2625
2687
  */
2626
- Node.prototype._clearSelfAndDescendantCache = function (attr) {
2688
+ Node.prototype._clearSelfAndDescendantCache = function (attr, forceEvent) {
2627
2689
  this._clearCache(attr);
2690
+ // trigger clear cache, so transformer can use it
2691
+ if (forceEvent && attr === ABSOLUTE_TRANSFORM) {
2692
+ this.fire('_clearTransformCache');
2693
+ }
2628
2694
  // skip clearing if node is cached with canvas
2629
2695
  // for performance reasons !!!
2630
2696
  if (this.isCached()) {
@@ -2632,7 +2698,7 @@
2632
2698
  }
2633
2699
  if (this.children) {
2634
2700
  this.children.each(function (node) {
2635
- node._clearSelfAndDescendantCache(attr);
2701
+ node._clearSelfAndDescendantCache(attr, true);
2636
2702
  });
2637
2703
  }
2638
2704
  };
@@ -2721,8 +2787,8 @@
2721
2787
  height: height
2722
2788
  }), cachedFilterCanvas = new SceneCanvas({
2723
2789
  pixelRatio: pixelRatio,
2724
- width: width,
2725
- height: height
2790
+ width: 0,
2791
+ height: 0
2726
2792
  }), cachedHitCanvas = new HitCanvas({
2727
2793
  pixelRatio: 1,
2728
2794
  width: width,
@@ -2734,7 +2800,6 @@
2734
2800
  if (conf.imageSmoothingEnabled === false) {
2735
2801
  cachedSceneCanvas.getContext()._context.imageSmoothingEnabled = false;
2736
2802
  cachedFilterCanvas.getContext()._context.imageSmoothingEnabled = false;
2737
- cachedHitCanvas.getContext()._context.imageSmoothingEnabled = false;
2738
2803
  }
2739
2804
  sceneContext.save();
2740
2805
  hitContext.save();
@@ -2871,6 +2936,7 @@
2871
2936
  if (filters) {
2872
2937
  if (!this._filterUpToDate) {
2873
2938
  var ratio = sceneCanvas.pixelRatio;
2939
+ filterCanvas.setSize(sceneCanvas.width / sceneCanvas.pixelRatio, sceneCanvas.height / sceneCanvas.pixelRatio);
2874
2940
  try {
2875
2941
  len = filters.length;
2876
2942
  filterContext.clear();
@@ -3366,9 +3432,26 @@
3366
3432
  }
3367
3433
  return depth;
3368
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
+ };
3369
3449
  Node.prototype.setPosition = function (pos) {
3370
- this.x(pos.x);
3371
- this.y(pos.y);
3450
+ var _this = this;
3451
+ this._batchTransformChanges(function () {
3452
+ _this.x(pos.x);
3453
+ _this.y(pos.y);
3454
+ });
3372
3455
  return this;
3373
3456
  };
3374
3457
  Node.prototype.getPosition = function () {
@@ -3405,16 +3488,17 @@
3405
3488
  this.attrs.y = origTrans.y;
3406
3489
  delete origTrans.x;
3407
3490
  delete origTrans.y;
3408
- // unravel transform
3409
- it = this.getAbsoluteTransform();
3491
+ // important, use non cached value
3492
+ this._clearCache(TRANSFORM);
3493
+ it = this._getAbsoluteTransform();
3410
3494
  it.invert();
3411
3495
  it.translate(pos.x, pos.y);
3412
3496
  pos = {
3413
3497
  x: this.attrs.x + it.getTranslation().x,
3414
3498
  y: this.attrs.y + it.getTranslation().y
3415
3499
  };
3416
- this.setPosition({ x: pos.x, y: pos.y });
3417
3500
  this._setTransform(origTrans);
3501
+ this.setPosition({ x: pos.x, y: pos.y });
3418
3502
  return this;
3419
3503
  };
3420
3504
  Node.prototype._setTransform = function (trans) {
@@ -3422,8 +3506,8 @@
3422
3506
  for (key in trans) {
3423
3507
  this.attrs[key] = trans[key];
3424
3508
  }
3425
- this._clearCache(TRANSFORM);
3426
- this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
3509
+ // this._clearCache(TRANSFORM);
3510
+ // this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
3427
3511
  };
3428
3512
  Node.prototype._clearTransform = function () {
3429
3513
  var trans = {
@@ -3446,8 +3530,6 @@
3446
3530
  this.attrs.offsetY = 0;
3447
3531
  this.attrs.skewX = 0;
3448
3532
  this.attrs.skewY = 0;
3449
- this._clearCache(TRANSFORM);
3450
- this._clearSelfAndDescendantCache(ABSOLUTE_TRANSFORM);
3451
3533
  // return original transform
3452
3534
  return trans;
3453
3535
  };
@@ -3822,7 +3904,7 @@
3822
3904
  * node.fire('click', null, true);
3823
3905
  */
3824
3906
  Node.prototype.fire = function (eventType, evt, bubble) {
3825
- evt = evt || {};
3907
+ if (evt === void 0) { evt = {}; }
3826
3908
  evt.target = evt.target || this;
3827
3909
  // bubble
3828
3910
  if (bubble) {
@@ -3898,16 +3980,8 @@
3898
3980
  * var scaleX = node.getAbsoluteScale().x;
3899
3981
  */
3900
3982
  Node.prototype.getAbsoluteScale = function (top) {
3901
- // if using an argument, we can't cache the result.
3902
- if (top) {
3903
- return this._getAbsoluteScale(top);
3904
- }
3905
- else {
3906
- // if no argument, we can cache the result
3907
- return this._getCache(ABSOLUTE_SCALE, this._getAbsoluteScale);
3908
- }
3909
- };
3910
- Node.prototype._getAbsoluteScale = function (top) {
3983
+ // do not cache this calculations,
3984
+ // because it use cache transform
3911
3985
  // this is special logic for caching with some shapes with shadow
3912
3986
  var parent = this;
3913
3987
  while (parent) {
@@ -3916,15 +3990,11 @@
3916
3990
  }
3917
3991
  parent = parent.getParent();
3918
3992
  }
3919
- var scaleX = 1, scaleY = 1;
3920
- // start with stage and traverse downwards to self
3921
- this._eachAncestorReverse(function (node) {
3922
- scaleX *= node.scaleX();
3923
- scaleY *= node.scaleY();
3924
- }, top);
3993
+ var transform = this.getAbsoluteTransform(top);
3994
+ var attrs = transform.decompose();
3925
3995
  return {
3926
- x: scaleX,
3927
- y: scaleY
3996
+ x: attrs.scaleX,
3997
+ y: attrs.scaleY
3928
3998
  };
3929
3999
  };
3930
4000
  /**
@@ -3938,13 +4008,14 @@
3938
4008
  * var rotation = node.getAbsoluteRotation();
3939
4009
  */
3940
4010
  Node.prototype.getAbsoluteRotation = function () {
3941
- var parent = this;
3942
- var rotation = 0;
3943
- while (parent) {
3944
- rotation += parent.rotation();
3945
- parent = parent.getParent();
3946
- }
3947
- return rotation;
4011
+ // var parent: Node = this;
4012
+ // var rotation = 0;
4013
+ // while (parent) {
4014
+ // rotation += parent.rotation();
4015
+ // parent = parent.getParent();
4016
+ // }
4017
+ // return rotation;
4018
+ return this.getAbsoluteTransform().decompose().rotation;
3948
4019
  };
3949
4020
  /**
3950
4021
  * get transform of the node
@@ -4353,7 +4424,7 @@
4353
4424
  this.parent.isListening() &&
4354
4425
  !stopBubble) {
4355
4426
  if (compareShape && compareShape.parent) {
4356
- this._fireAndBubble.call(this.parent, eventType, evt, compareShape.parent);
4427
+ this._fireAndBubble.call(this.parent, eventType, evt, compareShape);
4357
4428
  }
4358
4429
  else {
4359
4430
  this._fireAndBubble.call(this.parent, eventType, evt);
@@ -5370,17 +5441,6 @@
5370
5441
  }
5371
5442
  return obj;
5372
5443
  };
5373
- Container.prototype._getDescendants = function (arr) {
5374
- var retArr = [];
5375
- var len = arr.length;
5376
- for (var n = 0; n < len; n++) {
5377
- var node = arr[n];
5378
- if (this.isAncestorOf(node)) {
5379
- retArr.push(node);
5380
- }
5381
- }
5382
- return retArr;
5383
- };
5384
5444
  /**
5385
5445
  * determine if node is an ancestor
5386
5446
  * of descendant
@@ -5523,10 +5583,10 @@
5523
5583
  var dragSkip = !Konva.hitOnDragEnabled && layerUnderDrag;
5524
5584
  return layer && layer.hitGraphEnabled() && this.isVisible() && !dragSkip;
5525
5585
  };
5526
- Container.prototype.getClientRect = function (attrs) {
5527
- attrs = attrs || {};
5528
- var skipTransform = attrs.skipTransform;
5529
- var relativeTo = attrs.relativeTo;
5586
+ Container.prototype.getClientRect = function (config) {
5587
+ config = config || {};
5588
+ var skipTransform = config.skipTransform;
5589
+ var relativeTo = config.relativeTo;
5530
5590
  var minX, minY, maxX, maxY;
5531
5591
  var selfRect = {
5532
5592
  x: Infinity,
@@ -5542,8 +5602,8 @@
5542
5602
  }
5543
5603
  var rect = child.getClientRect({
5544
5604
  relativeTo: that,
5545
- skipShadow: attrs.skipShadow,
5546
- skipStroke: attrs.skipStroke
5605
+ skipShadow: config.skipShadow,
5606
+ skipStroke: config.skipStroke
5547
5607
  });
5548
5608
  // skip invisible children (like empty groups)
5549
5609
  if (rect.width === 0 && rect.height === 0) {
@@ -6017,7 +6077,7 @@
6017
6077
  length +
6018
6078
  ' layers. Recommended maximum number of layers is 3-5. Adding more layers into the stage may drop the performance. Rethink your tree structure, you can use Konva.Group.');
6019
6079
  }
6020
- layer._setCanvasSize(this.width(), this.height());
6080
+ layer.setSize({ width: this.width(), height: this.height() });
6021
6081
  // draw layer and append canvas to container
6022
6082
  layer.draw();
6023
6083
  if (Konva.isBrowser) {
@@ -6678,8 +6738,8 @@
6678
6738
  _this._waitingForDraw = false;
6679
6739
  _this.on('visibleChange', _this._checkVisibility);
6680
6740
  _this._checkVisibility();
6681
- _this.on('imageSmoothingEnabledChange', _this._checkSmooth);
6682
- _this._checkSmooth();
6741
+ _this.on('imageSmoothingEnabledChange', _this._setSmoothEnabled);
6742
+ _this._setSmoothEnabled();
6683
6743
  return _this;
6684
6744
  }
6685
6745
  // for nodejs?
@@ -6822,6 +6882,7 @@
6822
6882
  BaseLayer.prototype.setSize = function (_a) {
6823
6883
  var width = _a.width, height = _a.height;
6824
6884
  this.canvas.setSize(width, height);
6885
+ this._setSmoothEnabled();
6825
6886
  return this;
6826
6887
  };
6827
6888
  BaseLayer.prototype._toKonvaCanvas = function (config) {
@@ -6841,11 +6902,11 @@
6841
6902
  this.canvas._canvas.style.display = 'none';
6842
6903
  }
6843
6904
  };
6844
- BaseLayer.prototype._checkSmooth = function () {
6905
+ BaseLayer.prototype._setSmoothEnabled = function () {
6845
6906
  this.getContext()._context.imageSmoothingEnabled = this.imageSmoothingEnabled();
6846
6907
  };
6847
6908
  /**
6848
- * get/set width of layer.getter return width of stage. setter doing nothing.
6909
+ * get/set width of layer. getter return width of stage. setter doing nothing.
6849
6910
  * if you want change width use `stage.width(value);`
6850
6911
  * @name Konva.BaseLayer#width
6851
6912
  * @method
@@ -6920,10 +6981,8 @@
6920
6981
  * // get imageSmoothingEnabled flag
6921
6982
  * var imageSmoothingEnabled = layer.imageSmoothingEnabled();
6922
6983
  *
6923
- * // disable clear before draw
6924
6984
  * layer.imageSmoothingEnabled(false);
6925
6985
  *
6926
- * // enable clear before draw
6927
6986
  * layer.imageSmoothingEnabled(true);
6928
6987
  */
6929
6988
  Factory.addGetterSetter(BaseLayer, 'imageSmoothingEnabled', true);
@@ -7035,12 +7094,12 @@
7035
7094
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
7036
7095
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
7037
7096
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
7038
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
7097
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
7039
7098
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
7040
7099
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
7041
7100
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
7042
7101
  * is miter
7043
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
7102
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
7044
7103
  * is butt
7045
7104
  * @param {String} [config.shadowColor]
7046
7105
  * @param {Number} [config.shadowBlur]
@@ -7051,7 +7110,8 @@
7051
7110
  * between 0 and 1
7052
7111
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
7053
7112
  * @param {Array} [config.dash]
7054
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
7113
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
7114
+
7055
7115
  * @param {Number} [config.x]
7056
7116
  * @param {Number} [config.y]
7057
7117
  * @param {Number} [config.width]
@@ -7145,11 +7205,11 @@
7145
7205
  };
7146
7206
  Shape.prototype._hasShadow = function () {
7147
7207
  return (this.shadowEnabled() &&
7148
- (this.shadowOpacity() !== 0 &&
7149
- !!(this.shadowColor() ||
7150
- this.shadowBlur() ||
7151
- this.shadowOffsetX() ||
7152
- this.shadowOffsetY())));
7208
+ this.shadowOpacity() !== 0 &&
7209
+ !!(this.shadowColor() ||
7210
+ this.shadowBlur() ||
7211
+ this.shadowOffsetX() ||
7212
+ this.shadowOffsetY()));
7153
7213
  };
7154
7214
  Shape.prototype._getFillPattern = function () {
7155
7215
  return this._getCache(patternImage, this.__getFillPattern);
@@ -7228,10 +7288,11 @@
7228
7288
  * @returns {Boolean}
7229
7289
  */
7230
7290
  Shape.prototype.hasFill = function () {
7231
- return this.fillEnabled() && !!(this.fill() ||
7232
- this.fillPatternImage() ||
7233
- this.fillLinearGradientColorStops() ||
7234
- this.fillRadialGradientColorStops());
7291
+ return (this.fillEnabled() &&
7292
+ !!(this.fill() ||
7293
+ this.fillPatternImage() ||
7294
+ this.fillLinearGradientColorStops() ||
7295
+ this.fillRadialGradientColorStops()));
7235
7296
  };
7236
7297
  /**
7237
7298
  * returns whether or not the shape will be stroked
@@ -7248,10 +7309,13 @@
7248
7309
  };
7249
7310
  Shape.prototype.hasHitStroke = function () {
7250
7311
  var width = this.hitStrokeWidth();
7251
- // we should enable hit stroke we stroke is enabled
7312
+ // on auto just check by stroke
7313
+ if (width === 'auto') {
7314
+ return this.hasStroke();
7315
+ }
7316
+ // we should enable hit stroke if stroke is enabled
7252
7317
  // and we have some value from width
7253
- return (this.strokeEnabled() &&
7254
- (width || this.strokeWidth() && width === 'auto'));
7318
+ return this.strokeEnabled() && !!width;
7255
7319
  };
7256
7320
  /**
7257
7321
  * determines if point is in the shape, regardless if other shapes are on top of it. Note: because
@@ -7290,6 +7354,7 @@
7290
7354
  this.getStage());
7291
7355
  };
7292
7356
  Shape.prototype.setStrokeHitEnabled = function (val) {
7357
+ Util.warn('strokeHitEnabled property is deprecated. Please use hitStrokeWidth instead.');
7293
7358
  if (val) {
7294
7359
  this.hitStrokeWidth('auto');
7295
7360
  }
@@ -7320,8 +7385,8 @@
7320
7385
  Shape.prototype.getSelfRect = function () {
7321
7386
  var size = this.size();
7322
7387
  return {
7323
- x: this._centroid ? Math.round(-size.width / 2) : 0,
7324
- y: this._centroid ? Math.round(-size.height / 2) : 0,
7388
+ x: this._centroid ? -size.width / 2 : 0,
7389
+ y: this._centroid ? -size.height / 2 : 0,
7325
7390
  width: size.width,
7326
7391
  height: size.height
7327
7392
  };
@@ -7618,7 +7683,7 @@
7618
7683
  // TODO: probably we should deprecate it
7619
7684
  Factory.addGetterSetter(Shape, 'strokeHitEnabled', true, getBooleanValidator());
7620
7685
  /**
7621
- * get/set strokeHitEnabled property. Useful for performance optimization.
7686
+ * **deprecated, use hitStrokeWidth instead!** get/set strokeHitEnabled property. Useful for performance optimization.
7622
7687
  * You may set `shape.strokeHitEnabled(false)`. In this case stroke will be no draw on hit canvas, so hit area
7623
7688
  * of shape will be decreased (by lineWidth / 2). Remember that non closed line with `strokeHitEnabled = false`
7624
7689
  * will be not drawn on hit canvas, that is mean line will no trigger pointer events (like mouseover)
@@ -8610,10 +8675,11 @@
8610
8675
  });
8611
8676
  return _this;
8612
8677
  }
8613
- Layer.prototype._setCanvasSize = function (width, height) {
8614
- this.canvas.setSize(width, height);
8678
+ Layer.prototype.setSize = function (_a) {
8679
+ var width = _a.width, height = _a.height;
8680
+ _super.prototype.setSize.call(this, { width: width, height: height });
8615
8681
  this.hitCanvas.setSize(width, height);
8616
- this._checkSmooth();
8682
+ return this;
8617
8683
  };
8618
8684
  Layer.prototype._validateAdd = function (child) {
8619
8685
  var type = child.getType();
@@ -8772,12 +8838,6 @@
8772
8838
  parent.content.appendChild(this.hitCanvas._canvas);
8773
8839
  }
8774
8840
  };
8775
- Layer.prototype.setSize = function (_a) {
8776
- var width = _a.width, height = _a.height;
8777
- _super.prototype.setSize.call(this, { width: width, height: height });
8778
- this.hitCanvas.setSize(width, height);
8779
- return this;
8780
- };
8781
8841
  return Layer;
8782
8842
  }(BaseLayer));
8783
8843
  Layer.prototype.nodeType = 'Layer';
@@ -8839,10 +8899,6 @@
8839
8899
  Util.throw('You may only add shapes to a fast layer.');
8840
8900
  }
8841
8901
  };
8842
- FastLayer.prototype._setCanvasSize = function (width, height) {
8843
- this.canvas.setSize(width, height);
8844
- this._checkSmooth();
8845
- };
8846
8902
  FastLayer.prototype.hitGraphEnabled = function () {
8847
8903
  return false;
8848
8904
  };
@@ -9898,12 +9954,12 @@
9898
9954
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
9899
9955
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
9900
9956
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
9901
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
9957
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
9902
9958
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
9903
9959
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
9904
9960
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
9905
9961
  * is miter
9906
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
9962
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
9907
9963
  * is butt
9908
9964
  * @param {String} [config.shadowColor]
9909
9965
  * @param {Number} [config.shadowBlur]
@@ -9914,7 +9970,8 @@
9914
9970
  * between 0 and 1
9915
9971
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
9916
9972
  * @param {Array} [config.dash]
9917
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
9973
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
9974
+
9918
9975
  * @param {Number} [config.x]
9919
9976
  * @param {Number} [config.y]
9920
9977
  * @param {Number} [config.width]
@@ -10087,12 +10144,12 @@
10087
10144
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
10088
10145
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
10089
10146
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
10090
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
10147
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
10091
10148
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
10092
10149
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
10093
10150
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
10094
10151
  * is miter
10095
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
10152
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
10096
10153
  * is butt
10097
10154
  * @param {String} [config.shadowColor]
10098
10155
  * @param {Number} [config.shadowBlur]
@@ -10103,7 +10160,8 @@
10103
10160
  * between 0 and 1
10104
10161
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
10105
10162
  * @param {Array} [config.dash]
10106
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10163
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10164
+
10107
10165
  * @param {Number} [config.x]
10108
10166
  * @param {Number} [config.y]
10109
10167
  * @param {Number} [config.width]
@@ -10258,10 +10316,10 @@
10258
10316
  maxY = Math.max(maxY, y);
10259
10317
  }
10260
10318
  return {
10261
- x: Math.round(minX),
10262
- y: Math.round(minY),
10263
- width: Math.round(maxX - minX),
10264
- height: Math.round(maxY - minY)
10319
+ x: minX,
10320
+ y: minY,
10321
+ width: maxX - minX,
10322
+ height: maxY - minY
10265
10323
  };
10266
10324
  };
10267
10325
  return Line;
@@ -10338,7 +10396,7 @@
10338
10396
  * Arrow constructor
10339
10397
  * @constructor
10340
10398
  * @memberof Konva
10341
- * @augments Konva.Shape
10399
+ * @augments Konva.Line
10342
10400
  * @param {Object} config
10343
10401
  * @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
10344
10402
  * @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
@@ -10381,12 +10439,12 @@
10381
10439
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
10382
10440
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
10383
10441
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
10384
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
10442
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
10385
10443
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
10386
10444
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
10387
10445
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
10388
10446
  * is miter
10389
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
10447
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
10390
10448
  * is butt
10391
10449
  * @param {String} [config.shadowColor]
10392
10450
  * @param {Number} [config.shadowBlur]
@@ -10397,7 +10455,8 @@
10397
10455
  * between 0 and 1
10398
10456
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
10399
10457
  * @param {Array} [config.dash]
10400
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10458
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10459
+
10401
10460
  * @param {Number} [config.x]
10402
10461
  * @param {Number} [config.y]
10403
10462
  * @param {Number} [config.width]
@@ -10504,7 +10563,7 @@
10504
10563
  x: lineRect.x - offset,
10505
10564
  y: lineRect.y - offset,
10506
10565
  width: lineRect.width + offset * 2,
10507
- height: lineRect.height + offset * 2,
10566
+ height: lineRect.height + offset * 2
10508
10567
  };
10509
10568
  };
10510
10569
  return Arrow;
@@ -10598,12 +10657,12 @@
10598
10657
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
10599
10658
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
10600
10659
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
10601
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
10660
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
10602
10661
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
10603
10662
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
10604
10663
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
10605
10664
  * is miter
10606
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
10665
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
10607
10666
  * is butt
10608
10667
  * @param {String} [config.shadowColor]
10609
10668
  * @param {Number} [config.shadowBlur]
@@ -10614,7 +10673,8 @@
10614
10673
  * between 0 and 1
10615
10674
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
10616
10675
  * @param {Array} [config.dash]
10617
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10676
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10677
+
10618
10678
  * @param {Number} [config.x]
10619
10679
  * @param {Number} [config.y]
10620
10680
  * @param {Number} [config.width]
@@ -10735,12 +10795,12 @@
10735
10795
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
10736
10796
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
10737
10797
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
10738
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
10798
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
10739
10799
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
10740
10800
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
10741
10801
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
10742
10802
  * is miter
10743
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
10803
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
10744
10804
  * is butt
10745
10805
  * @param {String} [config.shadowColor]
10746
10806
  * @param {Number} [config.shadowBlur]
@@ -10751,7 +10811,8 @@
10751
10811
  * between 0 and 1
10752
10812
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
10753
10813
  * @param {Array} [config.dash]
10754
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10814
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10815
+
10755
10816
  * @param {Number} [config.x]
10756
10817
  * @param {Number} [config.y]
10757
10818
  * @param {Number} [config.width]
@@ -10909,12 +10970,12 @@
10909
10970
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
10910
10971
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
10911
10972
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
10912
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
10973
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
10913
10974
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
10914
10975
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
10915
10976
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
10916
10977
  * is miter
10917
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
10978
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
10918
10979
  * is butt
10919
10980
  * @param {String} [config.shadowColor]
10920
10981
  * @param {Number} [config.shadowBlur]
@@ -10925,7 +10986,8 @@
10925
10986
  * between 0 and 1
10926
10987
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
10927
10988
  * @param {Array} [config.dash]
10928
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10989
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
10990
+
10929
10991
  * @param {Number} [config.x]
10930
10992
  * @param {Number} [config.y]
10931
10993
  * @param {Number} [config.width]
@@ -11488,12 +11550,12 @@
11488
11550
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
11489
11551
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
11490
11552
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
11491
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
11553
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
11492
11554
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
11493
11555
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
11494
11556
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
11495
11557
  * is miter
11496
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
11558
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
11497
11559
  * is butt
11498
11560
  * @param {String} [config.shadowColor]
11499
11561
  * @param {Number} [config.shadowBlur]
@@ -11504,7 +11566,8 @@
11504
11566
  * between 0 and 1
11505
11567
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
11506
11568
  * @param {Array} [config.dash]
11507
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
11569
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
11570
+
11508
11571
  * @param {Number} [config.x]
11509
11572
  * @param {Number} [config.y]
11510
11573
  * @param {Number} [config.width]
@@ -12305,12 +12368,12 @@
12305
12368
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
12306
12369
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
12307
12370
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
12308
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
12371
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
12309
12372
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
12310
12373
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
12311
12374
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
12312
12375
  * is miter
12313
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
12376
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
12314
12377
  * is butt
12315
12378
  * @param {String} [config.shadowColor]
12316
12379
  * @param {Number} [config.shadowBlur]
@@ -12321,7 +12384,8 @@
12321
12384
  * between 0 and 1
12322
12385
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
12323
12386
  * @param {Array} [config.dash]
12324
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12387
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12388
+
12325
12389
  * @param {Number} [config.x]
12326
12390
  * @param {Number} [config.y]
12327
12391
  * @param {Number} [config.width]
@@ -12457,12 +12521,12 @@
12457
12521
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
12458
12522
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
12459
12523
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
12460
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
12524
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
12461
12525
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
12462
12526
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
12463
12527
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
12464
12528
  * is miter
12465
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
12529
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
12466
12530
  * is butt
12467
12531
  * @param {String} [config.shadowColor]
12468
12532
  * @param {Number} [config.shadowBlur]
@@ -12473,7 +12537,8 @@
12473
12537
  * between 0 and 1
12474
12538
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
12475
12539
  * @param {Array} [config.dash]
12476
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12540
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12541
+
12477
12542
  * @param {Number} [config.x]
12478
12543
  * @param {Number} [config.y]
12479
12544
  * @param {Number} [config.width]
@@ -12615,12 +12680,12 @@
12615
12680
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
12616
12681
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
12617
12682
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
12618
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
12683
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
12619
12684
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
12620
12685
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
12621
12686
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
12622
12687
  * is miter
12623
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
12688
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
12624
12689
  * is butt
12625
12690
  * @param {String} [config.shadowColor]
12626
12691
  * @param {Number} [config.shadowBlur]
@@ -12631,7 +12696,8 @@
12631
12696
  * between 0 and 1
12632
12697
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
12633
12698
  * @param {Array} [config.dash]
12634
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12699
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12700
+
12635
12701
  * @param {Number} [config.x]
12636
12702
  * @param {Number} [config.y]
12637
12703
  * @param {Number} [config.width]
@@ -12768,12 +12834,12 @@
12768
12834
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
12769
12835
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
12770
12836
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
12771
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
12837
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
12772
12838
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
12773
12839
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
12774
12840
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
12775
12841
  * is miter
12776
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
12842
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
12777
12843
  * is butt
12778
12844
  * @param {String} [config.shadowColor]
12779
12845
  * @param {Number} [config.shadowBlur]
@@ -12784,7 +12850,8 @@
12784
12850
  * between 0 and 1
12785
12851
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
12786
12852
  * @param {Array} [config.dash]
12787
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12853
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
12854
+
12788
12855
  * @param {Number} [config.x]
12789
12856
  * @param {Number} [config.y]
12790
12857
  * @param {Number} [config.width]
@@ -13135,12 +13202,12 @@
13135
13202
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
13136
13203
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
13137
13204
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
13138
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
13205
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
13139
13206
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
13140
13207
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
13141
13208
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
13142
13209
  * is miter
13143
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
13210
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
13144
13211
  * is butt
13145
13212
  * @param {String} [config.shadowColor]
13146
13213
  * @param {Number} [config.shadowBlur]
@@ -13151,7 +13218,8 @@
13151
13218
  * between 0 and 1
13152
13219
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
13153
13220
  * @param {Array} [config.dash]
13154
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
13221
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
13222
+
13155
13223
  * @param {Number} [config.x]
13156
13224
  * @param {Number} [config.y]
13157
13225
  * @param {Number} [config.width]
@@ -13362,12 +13430,12 @@
13362
13430
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
13363
13431
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
13364
13432
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
13365
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
13433
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
13366
13434
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
13367
13435
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
13368
13436
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
13369
13437
  * is miter
13370
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
13438
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
13371
13439
  * is butt
13372
13440
  * @param {String} [config.shadowColor]
13373
13441
  * @param {Number} [config.shadowBlur]
@@ -13378,7 +13446,8 @@
13378
13446
  * between 0 and 1
13379
13447
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
13380
13448
  * @param {Array} [config.dash]
13381
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
13449
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
13450
+
13382
13451
  * @param {Number} [config.x]
13383
13452
  * @param {Number} [config.y]
13384
13453
  * @param {Number} [config.width]
@@ -13527,7 +13596,11 @@
13527
13596
  context.fillStrokeShape(this);
13528
13597
  };
13529
13598
  Text.prototype.setText = function (text) {
13530
- var str = Util._isString(text) ? text : (text === null || text === undefined) ? '' : text + '';
13599
+ var str = Util._isString(text)
13600
+ ? text
13601
+ : text === null || text === undefined
13602
+ ? ''
13603
+ : text + '';
13531
13604
  this._setAttr(TEXT, str);
13532
13605
  return this;
13533
13606
  };
@@ -14019,12 +14092,12 @@
14019
14092
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
14020
14093
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
14021
14094
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
14022
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
14095
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
14023
14096
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
14024
14097
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
14025
14098
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
14026
14099
  * is miter
14027
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
14100
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
14028
14101
  * is butt
14029
14102
  * @param {String} [config.shadowColor]
14030
14103
  * @param {Number} [config.shadowBlur]
@@ -14035,7 +14108,8 @@
14035
14108
  * between 0 and 1
14036
14109
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
14037
14110
  * @param {Array} [config.dash]
14038
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
14111
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
14112
+
14039
14113
  * @param {Number} [config.x]
14040
14114
  * @param {Number} [config.y]
14041
14115
  * @param {Number} [config.width]
@@ -14427,10 +14501,10 @@
14427
14501
  }
14428
14502
  var fontSize = this.fontSize();
14429
14503
  return {
14430
- x: Math.round(minX) - fontSize / 2,
14431
- y: Math.round(minY) - fontSize / 2,
14432
- width: Math.round(maxX - minX) + fontSize,
14433
- height: Math.round(maxY - minY) + fontSize
14504
+ x: minX - fontSize / 2,
14505
+ y: minY - fontSize / 2,
14506
+ width: maxX - minX + fontSize,
14507
+ height: maxY - minY + fontSize
14434
14508
  };
14435
14509
  };
14436
14510
  return TextPath;
@@ -14625,7 +14699,7 @@
14625
14699
  ]
14626
14700
  .map(function (e) { return e + ("." + EVENTS_NAME); })
14627
14701
  .join(' ');
14628
- var NODE_RECT = 'nodeRect';
14702
+ var NODES_RECT = 'nodesRect';
14629
14703
  var TRANSFORM_CHANGE_STR$1 = [
14630
14704
  'widthChange',
14631
14705
  'heightChange',
@@ -14652,16 +14726,11 @@
14652
14726
  'bottom-right': 135
14653
14727
  };
14654
14728
  var TOUCH_DEVICE = 'ontouchstart' in Konva._global;
14655
- function getCursor(anchorName, rad, isMirrored) {
14729
+ function getCursor(anchorName, rad) {
14656
14730
  if (anchorName === 'rotater') {
14657
14731
  return 'crosshair';
14658
14732
  }
14659
14733
  rad += Util._degToRad(ANGLES[anchorName] || 0);
14660
- // If we are mirrored, we need to mirror the angle (this is not the same as
14661
- // rotate).
14662
- if (isMirrored) {
14663
- rad *= -1;
14664
- }
14665
14734
  var angle = ((Util._radToDeg(rad) % 360) + 360) % 360;
14666
14735
  if (Util._inRange(angle, 315 + 22.5, 360) || Util._inRange(angle, 0, 22.5)) {
14667
14736
  // TOP
@@ -14712,6 +14781,114 @@
14712
14781
  'bottom-right'
14713
14782
  ];
14714
14783
  var MAX_SAFE_INTEGER = 100000000;
14784
+ function getCenter(shape) {
14785
+ return {
14786
+ x: shape.x +
14787
+ (shape.width / 2) * Math.cos(shape.rotation) +
14788
+ (shape.height / 2) * Math.sin(-shape.rotation),
14789
+ y: shape.y +
14790
+ (shape.height / 2) * Math.cos(shape.rotation) +
14791
+ (shape.width / 2) * Math.sin(shape.rotation)
14792
+ };
14793
+ }
14794
+ function rotateAroundPoint(shape, angleRad, point) {
14795
+ var x = point.x +
14796
+ (shape.x - point.x) * Math.cos(angleRad) -
14797
+ (shape.y - point.y) * Math.sin(angleRad);
14798
+ var y = point.y +
14799
+ (shape.x - point.x) * Math.sin(angleRad) +
14800
+ (shape.y - point.y) * Math.cos(angleRad);
14801
+ return __assign(__assign({}, shape), { rotation: shape.rotation + angleRad, x: x,
14802
+ y: y });
14803
+ }
14804
+ function rotateAroundCenter(shape, deltaRad) {
14805
+ var center = getCenter(shape);
14806
+ return rotateAroundPoint(shape, deltaRad, center);
14807
+ }
14808
+ function getShapeRect(shape) {
14809
+ var angleRad = shape.rotation;
14810
+ var x1 = shape.x;
14811
+ var y1 = shape.y;
14812
+ var x2 = x1 + shape.width * Math.cos(angleRad);
14813
+ var y2 = y1 + shape.width * Math.sin(angleRad);
14814
+ var x3 = shape.x +
14815
+ shape.width * Math.cos(angleRad) +
14816
+ shape.height * Math.sin(-angleRad);
14817
+ var y3 = shape.y +
14818
+ shape.height * Math.cos(angleRad) +
14819
+ shape.width * Math.sin(angleRad);
14820
+ var x4 = shape.x + shape.height * Math.sin(-angleRad);
14821
+ var y4 = shape.y + shape.height * Math.cos(angleRad);
14822
+ var leftX = Math.min(x1, x2, x3, x4);
14823
+ var rightX = Math.max(x1, x2, x3, x4);
14824
+ var topY = Math.min(y1, y2, y3, y4);
14825
+ var bottomY = Math.max(y1, y2, y3, y4);
14826
+ return {
14827
+ x: leftX,
14828
+ y: topY,
14829
+ width: rightX - leftX,
14830
+ height: bottomY - topY
14831
+ };
14832
+ }
14833
+ function getShapesRect(shapes) {
14834
+ var x1 = 9999999999;
14835
+ var y1 = 9999999999;
14836
+ var x2 = -999999999;
14837
+ var y2 = -999999999;
14838
+ shapes.forEach(function (shape) {
14839
+ var rect = getShapeRect(shape);
14840
+ x1 = Math.min(x1, rect.x);
14841
+ y1 = Math.min(y1, rect.y);
14842
+ x2 = Math.max(x2, rect.x + rect.width);
14843
+ y2 = Math.max(y2, rect.y + rect.height);
14844
+ });
14845
+ return {
14846
+ x: x1,
14847
+ y: y1,
14848
+ width: x2 - x1,
14849
+ height: y2 - y1,
14850
+ rotation: 0
14851
+ };
14852
+ }
14853
+ function transformShape(shape, oldSelection, newSelection, keepOffset) {
14854
+ if (keepOffset === void 0) { keepOffset = 1; }
14855
+ var offset = rotateAroundPoint(shape, -oldSelection.rotation, {
14856
+ x: oldSelection.x,
14857
+ y: oldSelection.y
14858
+ });
14859
+ var offsetX = offset.x - oldSelection.x;
14860
+ var offsetY = offset.y - oldSelection.y;
14861
+ var angle = oldSelection.rotation;
14862
+ var scaleX = shape.width ? newSelection.width / oldSelection.width : 1;
14863
+ var scaleY = shape.height ? newSelection.height / oldSelection.height : 1;
14864
+ return {
14865
+ x: keepOffset * newSelection.x +
14866
+ offsetX * scaleX * Math.cos(angle) +
14867
+ offsetY * scaleY * Math.sin(-angle),
14868
+ y: keepOffset * newSelection.y +
14869
+ offsetX * scaleX * Math.sin(angle) +
14870
+ offsetY * scaleY * Math.cos(angle),
14871
+ width: shape.width * scaleX,
14872
+ height: shape.height * scaleY,
14873
+ rotation: shape.rotation
14874
+ };
14875
+ }
14876
+ function transformAndRotateShape(shape, oldSelection, newSelection) {
14877
+ var updated = transformShape(shape, oldSelection, newSelection);
14878
+ return rotateAroundPoint(updated, newSelection.rotation - oldSelection.rotation, newSelection);
14879
+ }
14880
+ function getSnap(snaps, newRotationRad, tol) {
14881
+ var snapped = newRotationRad;
14882
+ for (var i = 0; i < snaps.length; i++) {
14883
+ var angle = Konva.getAngle(snaps[i]);
14884
+ var absDiff = Math.abs(angle - newRotationRad) % (Math.PI * 2);
14885
+ var dif = Math.min(absDiff, Math.PI * 2 - absDiff);
14886
+ if (dif < tol) {
14887
+ snapped = angle;
14888
+ }
14889
+ }
14890
+ return snapped;
14891
+ }
14715
14892
  /**
14716
14893
  * Transformer constructor. Transformer is a special type of group that allow you transform Konva
14717
14894
  * primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
@@ -14768,7 +14945,7 @@
14768
14945
  return _this;
14769
14946
  }
14770
14947
  /**
14771
- * alias to `tr.node(shape)`
14948
+ * alias to `tr.nodes([shape])`/ This method is deprecated and will be removed soon.
14772
14949
  * @method
14773
14950
  * @name Konva.Transformer#attachTo
14774
14951
  * @returns {Konva.Transformer}
@@ -14780,26 +14957,42 @@
14780
14957
  return this;
14781
14958
  };
14782
14959
  Transformer.prototype.setNode = function (node) {
14960
+ Util.warn('tr.setNode(shape), tr.node(shape) and tr.attachTo(shape) methods are deprecated. Please use tr.nodes(nodesArray) instead.');
14961
+ return this.setNodes([node]);
14962
+ };
14963
+ Transformer.prototype.getNode = function () {
14964
+ return this._nodes && this._nodes[0];
14965
+ };
14966
+ Transformer.prototype.setNodes = function (nodes) {
14783
14967
  var _this = this;
14784
- if (this._node) {
14968
+ if (nodes === void 0) { nodes = []; }
14969
+ if (this._nodes && this._nodes.length) {
14785
14970
  this.detach();
14786
14971
  }
14787
- this._node = node;
14788
- this._resetTransformCache();
14789
- var additionalEvents = node._attrsAffectingSize
14790
- .map(function (prop) { return prop + 'Change.' + EVENTS_NAME; })
14791
- .join(' ');
14792
- var onChange = function () {
14793
- _this._resetTransformCache();
14794
- if (!_this._transforming) {
14795
- _this.update();
14796
- }
14797
- };
14798
- node.on(additionalEvents, onChange);
14799
- node.on(TRANSFORM_CHANGE_STR$1, onChange);
14800
- node.on("xChange." + EVENTS_NAME + " yChange." + EVENTS_NAME, function () {
14801
- return _this._resetTransformCache();
14972
+ this._nodes = nodes;
14973
+ if (nodes.length === 1) {
14974
+ this.rotation(nodes[0].rotation());
14975
+ }
14976
+ else {
14977
+ this.rotation(0);
14978
+ }
14979
+ this._nodes.forEach(function (node) {
14980
+ var additionalEvents = node._attrsAffectingSize
14981
+ .map(function (prop) { return prop + 'Change.' + EVENTS_NAME; })
14982
+ .join(' ');
14983
+ var onChange = function () {
14984
+ _this._resetTransformCache();
14985
+ if (!_this._transforming) {
14986
+ _this.update();
14987
+ }
14988
+ };
14989
+ node.on(additionalEvents, onChange);
14990
+ node.on(TRANSFORM_CHANGE_STR$1, onChange);
14991
+ node.on("_clearTransformCache." + EVENTS_NAME, onChange);
14992
+ node.on("xChange." + EVENTS_NAME + " yChange." + EVENTS_NAME, onChange);
14993
+ _this._proxyDrag(node);
14802
14994
  });
14995
+ this._resetTransformCache();
14803
14996
  // we may need it if we set node in initial props
14804
14997
  // so elements are not defined yet
14805
14998
  var elementsCreated = !!this.findOne('.top-left');
@@ -14808,16 +15001,46 @@
14808
15001
  }
14809
15002
  return this;
14810
15003
  };
14811
- Transformer.prototype.getNode = function () {
14812
- return this._node;
15004
+ Transformer.prototype._proxyDrag = function (node) {
15005
+ var _this = this;
15006
+ var lastPos;
15007
+ node.on("dragstart." + EVENTS_NAME, function () {
15008
+ lastPos = node.getAbsolutePosition();
15009
+ });
15010
+ node.on("dragmove." + EVENTS_NAME, function () {
15011
+ if (!lastPos) {
15012
+ return;
15013
+ }
15014
+ var abs = node.getAbsolutePosition();
15015
+ var dx = abs.x - lastPos.x;
15016
+ var dy = abs.y - lastPos.y;
15017
+ _this.nodes().forEach(function (otherNode) {
15018
+ if (otherNode === node) {
15019
+ return;
15020
+ }
15021
+ if (otherNode.isDragging()) {
15022
+ return;
15023
+ }
15024
+ var otherAbs = otherNode.getAbsolutePosition();
15025
+ otherNode.setAbsolutePosition({
15026
+ x: otherAbs.x + dx,
15027
+ y: otherAbs.y + dy
15028
+ });
15029
+ otherNode.startDrag();
15030
+ });
15031
+ lastPos = null;
15032
+ });
15033
+ };
15034
+ Transformer.prototype.getNodes = function () {
15035
+ return this._nodes;
14813
15036
  };
14814
15037
  /**
14815
15038
  * return the name of current active anchor
14816
15039
  * @method
14817
- * @name Konva.Transformer#detach
15040
+ * @name Konva.Transformer#getActiveAnchor
14818
15041
  * @returns {String | Null}
14819
15042
  * @example
14820
- * transformer.detach();
15043
+ * transformer.getActiveAnchor();
14821
15044
  */
14822
15045
  Transformer.prototype.getActiveAnchor = function () {
14823
15046
  return this._movingAnchorName;
@@ -14833,19 +15056,46 @@
14833
15056
  Transformer.prototype.detach = function () {
14834
15057
  if (this.getNode()) {
14835
15058
  this.getNode().off('.' + EVENTS_NAME);
14836
- this._node = undefined;
15059
+ this._nodes = [];
14837
15060
  }
14838
15061
  this._resetTransformCache();
14839
15062
  };
14840
15063
  Transformer.prototype._resetTransformCache = function () {
14841
- this._clearCache(NODE_RECT);
15064
+ this._clearCache(NODES_RECT);
14842
15065
  this._clearCache('transform');
14843
15066
  this._clearSelfAndDescendantCache('absoluteTransform');
14844
15067
  };
14845
15068
  Transformer.prototype._getNodeRect = function () {
14846
- return this._getCache(NODE_RECT, this.__getNodeRect);
15069
+ return this._getCache(NODES_RECT, this.__getNodeRect);
15070
+ };
15071
+ Transformer.prototype.__getNodeShape = function (node, rot, relative) {
15072
+ if (rot === void 0) { rot = this.rotation(); }
15073
+ var rect = node.getClientRect({
15074
+ skipTransform: true,
15075
+ skipShadow: true,
15076
+ skipStroke: this.ignoreStroke()
15077
+ });
15078
+ var absScale = node.getAbsoluteScale(relative);
15079
+ var absPos = node.getAbsolutePosition(relative);
15080
+ var dx = rect.x * absScale.x - node.offsetX() * absScale.x;
15081
+ var dy = rect.y * absScale.y - node.offsetY() * absScale.y;
15082
+ var rotation = (Konva.getAngle(node.getAbsoluteRotation()) + Math.PI * 2) %
15083
+ (Math.PI * 2);
15084
+ var box = {
15085
+ x: absPos.x + dx * Math.cos(rotation) + dy * Math.sin(-rotation),
15086
+ y: absPos.y + dy * Math.cos(rotation) + dx * Math.sin(rotation),
15087
+ width: rect.width * absScale.x,
15088
+ height: rect.height * absScale.y,
15089
+ rotation: rotation
15090
+ };
15091
+ return rotateAroundPoint(box, -Konva.getAngle(rot), {
15092
+ x: 0,
15093
+ y: 0
15094
+ });
14847
15095
  };
15096
+ // returns box + rotation of all shapes
14848
15097
  Transformer.prototype.__getNodeRect = function () {
15098
+ var _this = this;
14849
15099
  var node = this.getNode();
14850
15100
  if (!node) {
14851
15101
  return {
@@ -14856,24 +15106,14 @@
14856
15106
  rotation: 0
14857
15107
  };
14858
15108
  }
14859
- if (node.parent && this.parent && node.parent !== this.parent) {
14860
- Util.warn('Transformer and attached node have different parents. Konva does not support such case right now. Please move Transformer to the parent of attaching node.');
14861
- }
14862
- var rect = node.getClientRect({
14863
- skipTransform: true,
14864
- skipShadow: true,
14865
- skipStroke: this.ignoreStroke()
15109
+ var shapes = this.nodes().map(function (node) {
15110
+ return _this.__getNodeShape(node);
15111
+ });
15112
+ var box = getShapesRect(shapes);
15113
+ return rotateAroundPoint(box, Konva.getAngle(this.rotation()), {
15114
+ x: 0,
15115
+ y: 0
14866
15116
  });
14867
- var rotation = Konva.getAngle(node.rotation());
14868
- var dx = rect.x * node.scaleX() - node.offsetX() * node.scaleX();
14869
- var dy = rect.y * node.scaleY() - node.offsetY() * node.scaleY();
14870
- return {
14871
- x: node.x() + dx * Math.cos(rotation) + dy * Math.sin(-rotation),
14872
- y: node.y() + dy * Math.cos(rotation) + dx * Math.sin(rotation),
14873
- width: rect.width * node.scaleX(),
14874
- height: rect.height * node.scaleY(),
14875
- rotation: node.rotation()
14876
- };
14877
15117
  };
14878
15118
  Transformer.prototype.getX = function () {
14879
15119
  return this._getNodeRect().x;
@@ -14881,9 +15121,6 @@
14881
15121
  Transformer.prototype.getY = function () {
14882
15122
  return this._getNodeRect().y;
14883
15123
  };
14884
- Transformer.prototype.getRotation = function () {
14885
- return this._getNodeRect().rotation;
14886
- };
14887
15124
  Transformer.prototype.getWidth = function () {
14888
15125
  return this._getNodeRect().width;
14889
15126
  };
@@ -14905,6 +15142,8 @@
14905
15142
  strokeWidth: 1,
14906
15143
  name: name + ' _anchor',
14907
15144
  dragDistance: 0,
15145
+ // make it draggable,
15146
+ // so activating the anchror will not start drag&drop of any parent
14908
15147
  draggable: true,
14909
15148
  hitStrokeWidth: TOUCH_DEVICE ? 10 : 'auto'
14910
15149
  });
@@ -14913,9 +15152,7 @@
14913
15152
  self._handleMouseDown(e);
14914
15153
  });
14915
15154
  anchor.on('dragstart', function (e) {
14916
- e.cancelBubble = true;
14917
- });
14918
- anchor.on('dragmove', function (e) {
15155
+ anchor.stopDrag();
14919
15156
  e.cancelBubble = true;
14920
15157
  });
14921
15158
  anchor.on('dragend', function (e) {
@@ -14923,11 +15160,8 @@
14923
15160
  });
14924
15161
  // add hover styling
14925
15162
  anchor.on('mouseenter', function () {
14926
- var rad = Konva.getAngle(_this.getAbsoluteRotation());
14927
- var scale = _this.getNode().getAbsoluteScale();
14928
- // If scale.y < 0 xor scale.x < 0 we need to flip (not rotate).
14929
- var isMirrored = scale.y * scale.x < 0;
14930
- var cursor = getCursor(name, rad, isMirrored);
15163
+ var rad = Konva.getAngle(_this.rotation());
15164
+ var cursor = getCursor(name, rad);
14931
15165
  anchor.getStage().content.style.cursor = cursor;
14932
15166
  _this._cursorChange = true;
14933
15167
  });
@@ -14941,11 +15175,12 @@
14941
15175
  this.add(anchor);
14942
15176
  };
14943
15177
  Transformer.prototype._createBack = function () {
15178
+ var _this = this;
14944
15179
  var back = new Shape({
14945
15180
  name: 'back',
14946
15181
  width: 0,
14947
15182
  height: 0,
14948
- listening: false,
15183
+ draggable: true,
14949
15184
  sceneFunc: function (ctx) {
14950
15185
  var tr = this.getParent();
14951
15186
  var padding = tr.padding();
@@ -14956,9 +15191,19 @@
14956
15191
  ctx.lineTo(this.width() / 2, -tr.rotateAnchorOffset() * Util._sign(this.height()) - padding);
14957
15192
  }
14958
15193
  ctx.fillStrokeShape(this);
15194
+ },
15195
+ hitFunc: function (ctx, shape) {
15196
+ if (!_this.shouldOverdrawWholeArea()) {
15197
+ return;
15198
+ }
15199
+ var padding = _this.padding();
15200
+ ctx.beginPath();
15201
+ ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
15202
+ ctx.fillStrokeShape(shape);
14959
15203
  }
14960
15204
  });
14961
15205
  this.add(back);
15206
+ this._proxyDrag(back);
14962
15207
  };
14963
15208
  Transformer.prototype._handleMouseDown = function (e) {
14964
15209
  this._movingAnchorName = e.target.name().split(' ')[0];
@@ -14974,6 +15219,12 @@
14974
15219
  window.addEventListener('mouseup', this._handleMouseUp, true);
14975
15220
  window.addEventListener('touchend', this._handleMouseUp, true);
14976
15221
  this._transforming = true;
15222
+ var ap = e.target.getAbsolutePosition();
15223
+ var pos = e.target.getStage().getPointerPosition();
15224
+ this._anchorDragOffset = {
15225
+ x: pos.x - ap.x,
15226
+ y: pos.y - ap.y
15227
+ };
14977
15228
  this._fire('transformstart', { evt: e, target: this.getNode() });
14978
15229
  this.getNode()._fire('transformstart', { evt: e, target: this.getNode() });
14979
15230
  };
@@ -14982,23 +15233,57 @@
14982
15233
  var anchorNode = this.findOne('.' + this._movingAnchorName);
14983
15234
  var stage = anchorNode.getStage();
14984
15235
  stage.setPointersPositions(e);
14985
- anchorNode.setAbsolutePosition(stage.getPointerPosition());
15236
+ var pp = stage.getPointerPosition();
15237
+ var newNodePos = {
15238
+ x: pp.x - this._anchorDragOffset.x,
15239
+ y: pp.y - this._anchorDragOffset.y
15240
+ };
15241
+ var oldAbs = anchorNode.getAbsolutePosition();
15242
+ anchorNode.setAbsolutePosition(newNodePos);
15243
+ var newAbs = anchorNode.getAbsolutePosition();
15244
+ if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
15245
+ return;
15246
+ }
15247
+ // rotater is working very differently, so do it first
15248
+ if (this._movingAnchorName === 'rotater') {
15249
+ var attrs = this._getNodeRect();
15250
+ x = anchorNode.x() - attrs.width / 2;
15251
+ y = -anchorNode.y() + attrs.height / 2;
15252
+ // hor angle is changed?
15253
+ var delta = Math.atan2(-y, x) + Math.PI / 2;
15254
+ if (attrs.height < 0) {
15255
+ delta -= Math.PI;
15256
+ }
15257
+ var oldRotation = Konva.getAngle(this.rotation());
15258
+ var newRotation = oldRotation + delta;
15259
+ var tol = Konva.getAngle(this.rotationSnapTolerance());
15260
+ var snappedRot = getSnap(this.rotationSnaps(), newRotation, tol);
15261
+ var diff = snappedRot - attrs.rotation;
15262
+ var shape = rotateAroundCenter(attrs, diff);
15263
+ this._fitNodesInto(shape, e);
15264
+ return;
15265
+ }
14986
15266
  var keepProportion = this.keepRatio() || e.shiftKey;
14987
- var padding = this.padding();
15267
+ var centeredScaling = this.centeredScaling() || e.altKey;
14988
15268
  if (this._movingAnchorName === 'top-left') {
14989
15269
  if (keepProportion) {
14990
- newHypotenuse = Math.sqrt(Math.pow(this.findOne('.bottom-right').x() - anchorNode.x() - padding * 2, 2) +
14991
- Math.pow(this.findOne('.bottom-right').y() - anchorNode.y() - padding * 2, 2));
14992
- var reverseX = this.findOne('.top-left').x() > this.findOne('.bottom-right').x()
14993
- ? -1
14994
- : 1;
14995
- var reverseY = this.findOne('.top-left').y() > this.findOne('.bottom-right').y()
14996
- ? -1
14997
- : 1;
15270
+ var comparePoint = centeredScaling
15271
+ ? {
15272
+ x: this.width() / 2,
15273
+ y: this.height() / 2
15274
+ }
15275
+ : {
15276
+ x: this.findOne('.bottom-right').x(),
15277
+ y: this.findOne('.bottom-right').y()
15278
+ };
15279
+ newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
15280
+ Math.pow(comparePoint.y - anchorNode.y(), 2));
15281
+ var reverseX = this.findOne('.top-left').x() > comparePoint.x ? -1 : 1;
15282
+ var reverseY = this.findOne('.top-left').y() > comparePoint.y ? -1 : 1;
14998
15283
  x = newHypotenuse * this.cos * reverseX;
14999
15284
  y = newHypotenuse * this.sin * reverseY;
15000
- this.findOne('.top-left').x(this.findOne('.bottom-right').x() - x - padding * 2);
15001
- this.findOne('.top-left').y(this.findOne('.bottom-right').y() - y - padding * 2);
15285
+ this.findOne('.top-left').x(comparePoint.x - x);
15286
+ this.findOne('.top-left').y(comparePoint.y - y);
15002
15287
  }
15003
15288
  }
15004
15289
  else if (this._movingAnchorName === 'top-center') {
@@ -15006,18 +15291,23 @@
15006
15291
  }
15007
15292
  else if (this._movingAnchorName === 'top-right') {
15008
15293
  if (keepProportion) {
15009
- newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - this.findOne('.bottom-left').x() - padding * 2, 2) +
15010
- Math.pow(this.findOne('.bottom-left').y() - anchorNode.y() - padding * 2, 2));
15011
- var reverseX = this.findOne('.top-right').x() < this.findOne('.top-left').x()
15012
- ? -1
15013
- : 1;
15014
- var reverseY = this.findOne('.top-right').y() > this.findOne('.bottom-left').y()
15015
- ? -1
15016
- : 1;
15294
+ var comparePoint = centeredScaling
15295
+ ? {
15296
+ x: this.width() / 2,
15297
+ y: this.height() / 2
15298
+ }
15299
+ : {
15300
+ x: this.findOne('.bottom-left').x(),
15301
+ y: this.findOne('.bottom-left').y()
15302
+ };
15303
+ newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
15304
+ Math.pow(comparePoint.y - anchorNode.y(), 2));
15305
+ var reverseX = this.findOne('.top-right').x() < comparePoint.x ? -1 : 1;
15306
+ var reverseY = this.findOne('.top-right').y() > comparePoint.y ? -1 : 1;
15017
15307
  x = newHypotenuse * this.cos * reverseX;
15018
15308
  y = newHypotenuse * this.sin * reverseY;
15019
- this.findOne('.top-right').x(x + padding);
15020
- this.findOne('.top-right').y(this.findOne('.bottom-left').y() - y - padding * 2);
15309
+ this.findOne('.top-right').x(comparePoint.x + x);
15310
+ this.findOne('.top-right').y(comparePoint.y - y);
15021
15311
  }
15022
15312
  var pos = anchorNode.position();
15023
15313
  this.findOne('.top-left').y(pos.y);
@@ -15031,18 +15321,23 @@
15031
15321
  }
15032
15322
  else if (this._movingAnchorName === 'bottom-left') {
15033
15323
  if (keepProportion) {
15034
- newHypotenuse = Math.sqrt(Math.pow(this.findOne('.top-right').x() - anchorNode.x() - padding * 2, 2) +
15035
- Math.pow(anchorNode.y() - this.findOne('.top-right').y() - padding * 2, 2));
15036
- var reverseX = this.findOne('.top-right').x() < this.findOne('.bottom-left').x()
15037
- ? -1
15038
- : 1;
15039
- var reverseY = this.findOne('.bottom-right').y() < this.findOne('.top-left').y()
15040
- ? -1
15041
- : 1;
15324
+ var comparePoint = centeredScaling
15325
+ ? {
15326
+ x: this.width() / 2,
15327
+ y: this.height() / 2
15328
+ }
15329
+ : {
15330
+ x: this.findOne('.top-right').x(),
15331
+ y: this.findOne('.top-right').y()
15332
+ };
15333
+ newHypotenuse = Math.sqrt(Math.pow(comparePoint.x - anchorNode.x(), 2) +
15334
+ Math.pow(anchorNode.y() - comparePoint.y, 2));
15335
+ var reverseX = comparePoint.x < anchorNode.x() ? -1 : 1;
15336
+ var reverseY = anchorNode.y() < comparePoint.y ? -1 : 1;
15042
15337
  x = newHypotenuse * this.cos * reverseX;
15043
15338
  y = newHypotenuse * this.sin * reverseY;
15044
- this.findOne('.bottom-left').x(this.findOne('.top-right').x() - x - padding * 2);
15045
- this.findOne('.bottom-left').y(y + padding);
15339
+ anchorNode.x(comparePoint.x - x);
15340
+ anchorNode.y(comparePoint.y + y);
15046
15341
  }
15047
15342
  pos = anchorNode.position();
15048
15343
  this.findOne('.top-left').x(pos.x);
@@ -15053,77 +15348,37 @@
15053
15348
  }
15054
15349
  else if (this._movingAnchorName === 'bottom-right') {
15055
15350
  if (keepProportion) {
15056
- newHypotenuse = Math.sqrt(Math.pow(this.findOne('.bottom-right').x() - padding, 2) +
15057
- Math.pow(this.findOne('.bottom-right').y() - padding, 2));
15058
- var reverseX = this.findOne('.top-left').x() > this.findOne('.bottom-right').x()
15059
- ? -1
15060
- : 1;
15061
- var reverseY = this.findOne('.top-left').y() > this.findOne('.bottom-right').y()
15062
- ? -1
15063
- : 1;
15351
+ var comparePoint = centeredScaling
15352
+ ? {
15353
+ x: this.width() / 2,
15354
+ y: this.height() / 2
15355
+ }
15356
+ : {
15357
+ x: this.findOne('.top-left').x(),
15358
+ y: this.findOne('.top-left').y()
15359
+ };
15360
+ newHypotenuse = Math.sqrt(Math.pow(anchorNode.x() - comparePoint.x, 2) +
15361
+ Math.pow(anchorNode.y() - comparePoint.y, 2));
15362
+ var reverseX = this.findOne('.bottom-right').x() < comparePoint.x ? -1 : 1;
15363
+ var reverseY = this.findOne('.bottom-right').y() < comparePoint.y ? -1 : 1;
15064
15364
  x = newHypotenuse * this.cos * reverseX;
15065
15365
  y = newHypotenuse * this.sin * reverseY;
15066
- this.findOne('.bottom-right').x(x + padding);
15067
- this.findOne('.bottom-right').y(y + padding);
15068
- }
15069
- }
15070
- else if (this._movingAnchorName === 'rotater') {
15071
- var attrs = this._getNodeRect();
15072
- x = anchorNode.x() - attrs.width / 2;
15073
- y = -anchorNode.y() + attrs.height / 2;
15074
- var dAlpha = Math.atan2(-y, x) + Math.PI / 2;
15075
- if (attrs.height < 0) {
15076
- dAlpha -= Math.PI;
15077
- }
15078
- var rot = Konva.getAngle(this.rotation());
15079
- var newRotation = Util._radToDeg(rot) + Util._radToDeg(dAlpha);
15080
- var alpha = Konva.getAngle(this.getNode().rotation());
15081
- var newAlpha = Util._degToRad(newRotation);
15082
- var snaps = this.rotationSnaps();
15083
- var offset = Konva.getAngle(this.rotationSnapTolerance());
15084
- for (var i = 0; i < snaps.length; i++) {
15085
- var angle = Konva.getAngle(snaps[i]);
15086
- var dif = Math.abs(angle - Util._degToRad(newRotation)) % (Math.PI * 2);
15087
- if (dif < offset) {
15088
- newRotation = Util._radToDeg(angle);
15089
- newAlpha = Util._degToRad(newRotation);
15090
- }
15366
+ this.findOne('.bottom-right').x(comparePoint.x + x);
15367
+ this.findOne('.bottom-right').y(comparePoint.y + y);
15091
15368
  }
15092
- var dx = padding;
15093
- var dy = padding;
15094
- this._fitNodeInto({
15095
- rotation: Konva.angleDeg ? newRotation : Util._degToRad(newRotation),
15096
- x: attrs.x +
15097
- (attrs.width / 2 + padding) *
15098
- (Math.cos(alpha) - Math.cos(newAlpha)) +
15099
- (attrs.height / 2 + padding) *
15100
- (Math.sin(-alpha) - Math.sin(-newAlpha)) -
15101
- (dx * Math.cos(rot) + dy * Math.sin(-rot)),
15102
- y: attrs.y +
15103
- (attrs.height / 2 + padding) *
15104
- (Math.cos(alpha) - Math.cos(newAlpha)) +
15105
- (attrs.width / 2 + padding) *
15106
- (Math.sin(alpha) - Math.sin(newAlpha)) -
15107
- (dy * Math.cos(rot) + dx * Math.sin(rot)),
15108
- width: attrs.width + padding * 2,
15109
- height: attrs.height + padding * 2
15110
- }, e);
15111
15369
  }
15112
15370
  else {
15113
15371
  console.error(new Error('Wrong position argument of selection resizer: ' +
15114
15372
  this._movingAnchorName));
15115
15373
  }
15116
- if (this._movingAnchorName === 'rotater') {
15117
- return;
15118
- }
15119
15374
  var centeredScaling = this.centeredScaling() || e.altKey;
15120
15375
  if (centeredScaling) {
15121
15376
  var topLeft = this.findOne('.top-left');
15122
15377
  var bottomRight = this.findOne('.bottom-right');
15123
- var topOffsetX = topLeft.x() + padding;
15124
- var topOffsetY = topLeft.y() + padding;
15125
- var bottomOffsetX = this.getWidth() - bottomRight.x() + padding;
15126
- var bottomOffsetY = this.getHeight() - bottomRight.y() + padding;
15378
+ var topOffsetX = topLeft.x();
15379
+ var topOffsetY = topLeft.y();
15380
+ var bottomOffsetX = this.getWidth() - bottomRight.x();
15381
+ var bottomOffsetY = this.getHeight() - bottomRight.y();
15127
15382
  bottomRight.move({
15128
15383
  x: -topOffsetX,
15129
15384
  y: -topOffsetY
@@ -15133,21 +15388,25 @@
15133
15388
  y: bottomOffsetY
15134
15389
  });
15135
15390
  }
15136
- var absPos = this.findOne('.top-left').getAbsolutePosition(this.getParent());
15391
+ var absPos = this.findOne('.top-left').getAbsolutePosition();
15137
15392
  x = absPos.x;
15138
15393
  y = absPos.y;
15139
15394
  var width = this.findOne('.bottom-right').x() - this.findOne('.top-left').x();
15140
15395
  var height = this.findOne('.bottom-right').y() - this.findOne('.top-left').y();
15141
- this._fitNodeInto({
15142
- x: x + this.offsetX(),
15143
- y: y + this.offsetY(),
15396
+ this._fitNodesInto({
15397
+ x: x,
15398
+ y: y,
15144
15399
  width: width,
15145
- height: height
15400
+ height: height,
15401
+ rotation: Konva.getAngle(this.rotation())
15146
15402
  }, e);
15147
15403
  };
15148
15404
  Transformer.prototype._handleMouseUp = function (e) {
15149
15405
  this._removeEvents(e);
15150
15406
  };
15407
+ Transformer.prototype.getAbsoluteTransform = function () {
15408
+ return this.getTransform();
15409
+ };
15151
15410
  Transformer.prototype._removeEvents = function (e) {
15152
15411
  if (this._transforming) {
15153
15412
  this._transforming = false;
@@ -15163,40 +15422,127 @@
15163
15422
  this._movingAnchorName = null;
15164
15423
  }
15165
15424
  };
15166
- Transformer.prototype._fitNodeInto = function (newAttrs, evt) {
15167
- // waring! in this attrs padding is included
15168
- var boundBoxFunc = this.boundBoxFunc();
15169
- if (boundBoxFunc) {
15170
- var oldAttrs = this._getNodeRect();
15171
- newAttrs = boundBoxFunc.call(this, oldAttrs, newAttrs);
15425
+ Transformer.prototype._fitNodesInto = function (newAttrs, evt) {
15426
+ var _this = this;
15427
+ var oldAttrs = this._getNodeRect();
15428
+ var minSize = 1;
15429
+ if (Util._inRange(newAttrs.width, -this.padding() * 2 - minSize, minSize)) {
15430
+ this.update();
15431
+ return;
15172
15432
  }
15173
- var node = this.getNode();
15174
- if (newAttrs.rotation !== undefined) {
15175
- this.getNode().rotation(newAttrs.rotation);
15433
+ if (Util._inRange(newAttrs.height, -this.padding() * 2 - minSize, minSize)) {
15434
+ this.update();
15435
+ return;
15176
15436
  }
15437
+ var t = new Transform();
15438
+ t.rotate(Konva.getAngle(this.rotation()));
15439
+ if (this._movingAnchorName &&
15440
+ newAttrs.width < 0 &&
15441
+ this._movingAnchorName.indexOf('left') >= 0) {
15442
+ var offset = t.point({
15443
+ x: -this.padding() * 2,
15444
+ y: 0
15445
+ });
15446
+ newAttrs.x += offset.x;
15447
+ newAttrs.y += offset.y;
15448
+ newAttrs.width += this.padding() * 2;
15449
+ this._movingAnchorName = this._movingAnchorName.replace('left', 'right');
15450
+ this._anchorDragOffset.x -= offset.x;
15451
+ this._anchorDragOffset.y -= offset.y;
15452
+ }
15453
+ else if (this._movingAnchorName &&
15454
+ newAttrs.width < 0 &&
15455
+ this._movingAnchorName.indexOf('right') >= 0) {
15456
+ var offset = t.point({
15457
+ x: this.padding() * 2,
15458
+ y: 0
15459
+ });
15460
+ this._movingAnchorName = this._movingAnchorName.replace('right', 'left');
15461
+ this._anchorDragOffset.x -= offset.x;
15462
+ this._anchorDragOffset.y -= offset.y;
15463
+ newAttrs.width += this.padding() * 2;
15464
+ }
15465
+ if (this._movingAnchorName &&
15466
+ newAttrs.height < 0 &&
15467
+ this._movingAnchorName.indexOf('top') >= 0) {
15468
+ var offset = t.point({
15469
+ x: 0,
15470
+ y: -this.padding() * 2
15471
+ });
15472
+ newAttrs.x += offset.x;
15473
+ newAttrs.y += offset.y;
15474
+ this._movingAnchorName = this._movingAnchorName.replace('top', 'bottom');
15475
+ this._anchorDragOffset.x -= offset.x;
15476
+ this._anchorDragOffset.y -= offset.y;
15477
+ newAttrs.height += this.padding() * 2;
15478
+ }
15479
+ else if (this._movingAnchorName &&
15480
+ newAttrs.height < 0 &&
15481
+ this._movingAnchorName.indexOf('bottom') >= 0) {
15482
+ var offset = t.point({
15483
+ x: 0,
15484
+ y: this.padding() * 2
15485
+ });
15486
+ this._movingAnchorName = this._movingAnchorName.replace('bottom', 'top');
15487
+ this._anchorDragOffset.x -= offset.x;
15488
+ this._anchorDragOffset.y -= offset.y;
15489
+ newAttrs.height += this.padding() * 2;
15490
+ }
15491
+ this._nodes.forEach(function (node) {
15492
+ var oldRect = _this.__getNodeShape(node, 0);
15493
+ var newRect = transformAndRotateShape(oldRect, oldAttrs, newAttrs);
15494
+ _this._fitNodeInto(node, newRect, evt);
15495
+ });
15496
+ this.rotation(Util._getRotation(newAttrs.rotation));
15497
+ this._resetTransformCache();
15498
+ this.update();
15499
+ this.getLayer().batchDraw();
15500
+ };
15501
+ Transformer.prototype._fitNodeInto = function (node, newAttrs, evt) {
15502
+ if (this.boundBoxFunc()) {
15503
+ var oldAttrs = this.__getNodeShape(node, node.rotation(), node.getParent());
15504
+ var bounded = this.boundBoxFunc()(oldAttrs, newAttrs, node);
15505
+ if (bounded) {
15506
+ newAttrs = bounded;
15507
+ }
15508
+ else {
15509
+ Util.warn('boundBoxFunc returned falsy. You should return new bound rect from it!');
15510
+ }
15511
+ }
15512
+ var parentRot = Konva.getAngle(node.getParent().getAbsoluteRotation());
15513
+ node.rotation(Util._getRotation(newAttrs.rotation - parentRot));
15177
15514
  var pure = node.getClientRect({
15178
15515
  skipTransform: true,
15179
15516
  skipShadow: true,
15180
15517
  skipStroke: this.ignoreStroke()
15181
15518
  });
15182
- var padding = this.padding();
15183
- var scaleX = pure.width ? (newAttrs.width - padding * 2) / pure.width : 1;
15184
- var scaleY = pure.height
15185
- ? (newAttrs.height - padding * 2) / pure.height
15186
- : 1;
15519
+ var parentTransform = node
15520
+ .getParent()
15521
+ .getAbsoluteTransform()
15522
+ .copy();
15523
+ parentTransform.invert();
15524
+ var invertedPoint = parentTransform.point({
15525
+ x: newAttrs.x,
15526
+ y: newAttrs.y
15527
+ });
15528
+ newAttrs.x = invertedPoint.x;
15529
+ newAttrs.y = invertedPoint.y;
15530
+ var absScale = node.getParent().getAbsoluteScale();
15531
+ pure.width *= absScale.x;
15532
+ pure.height *= absScale.y;
15533
+ var scaleX = pure.width ? newAttrs.width / pure.width : 1;
15534
+ var scaleY = pure.height ? newAttrs.height / pure.height : 1;
15187
15535
  var rotation = Konva.getAngle(node.rotation());
15188
- var dx = pure.x * scaleX - padding - node.offsetX() * scaleX;
15189
- var dy = pure.y * scaleY - padding - node.offsetY() * scaleY;
15190
- this.getNode().setAttrs({
15536
+ var dx = pure.x * scaleX - node.offsetX() * scaleX;
15537
+ var dy = pure.y * scaleY - node.offsetY() * scaleY;
15538
+ node.setAttrs({
15191
15539
  scaleX: scaleX,
15192
15540
  scaleY: scaleY,
15193
15541
  x: newAttrs.x - (dx * Math.cos(rotation) + dy * Math.sin(-rotation)),
15194
15542
  y: newAttrs.y - (dy * Math.cos(rotation) + dx * Math.sin(rotation))
15195
15543
  });
15196
- this._fire('transform', { evt: evt, target: this.getNode() });
15197
- this.getNode()._fire('transform', { evt: evt, target: this.getNode() });
15198
- this.update();
15199
- this.getLayer().batchDraw();
15544
+ this._fire('transform', { evt: evt, target: node });
15545
+ node._fire('transform', { evt: evt, target: node });
15200
15546
  };
15201
15547
  /**
15202
15548
  * force update of Konva.Transformer.
@@ -15211,15 +15557,7 @@
15211
15557
  Transformer.prototype.update = function () {
15212
15558
  var _this = this;
15213
15559
  var attrs = this._getNodeRect();
15214
- var node = this.getNode();
15215
- var scale = { x: 1, y: 1 };
15216
- if (node && node.getParent()) {
15217
- scale = node.getParent().getAbsoluteScale();
15218
- }
15219
- var invertedScale = {
15220
- x: 1 / scale.x,
15221
- y: 1 / scale.y
15222
- };
15560
+ this.rotation(Util._getRotation(attrs.rotation));
15223
15561
  var width = attrs.width;
15224
15562
  var height = attrs.height;
15225
15563
  var enabledAnchors = this.enabledAnchors();
@@ -15239,68 +15577,71 @@
15239
15577
  });
15240
15578
  });
15241
15579
  this.findOne('.top-left').setAttrs({
15242
- x: -padding,
15243
- y: -padding,
15244
- scale: invertedScale,
15580
+ x: 0,
15581
+ y: 0,
15582
+ offsetX: anchorSize / 2 + padding,
15583
+ offsetY: anchorSize / 2 + padding,
15245
15584
  visible: resizeEnabled && enabledAnchors.indexOf('top-left') >= 0
15246
15585
  });
15247
15586
  this.findOne('.top-center').setAttrs({
15248
15587
  x: width / 2,
15249
- y: -padding,
15250
- scale: invertedScale,
15588
+ y: 0,
15589
+ offsetY: anchorSize / 2 + padding,
15251
15590
  visible: resizeEnabled && enabledAnchors.indexOf('top-center') >= 0
15252
15591
  });
15253
15592
  this.findOne('.top-right').setAttrs({
15254
- x: width + padding,
15255
- y: -padding,
15256
- scale: invertedScale,
15593
+ x: width,
15594
+ y: 0,
15595
+ offsetX: anchorSize / 2 - padding,
15596
+ offsetY: anchorSize / 2 + padding,
15257
15597
  visible: resizeEnabled && enabledAnchors.indexOf('top-right') >= 0
15258
15598
  });
15259
15599
  this.findOne('.middle-left').setAttrs({
15260
- x: -padding,
15600
+ x: 0,
15261
15601
  y: height / 2,
15262
- scale: invertedScale,
15602
+ offsetX: anchorSize / 2 + padding,
15263
15603
  visible: resizeEnabled && enabledAnchors.indexOf('middle-left') >= 0
15264
15604
  });
15265
15605
  this.findOne('.middle-right').setAttrs({
15266
- x: width + padding,
15606
+ x: width,
15267
15607
  y: height / 2,
15268
- scale: invertedScale,
15608
+ offsetX: anchorSize / 2 - padding,
15269
15609
  visible: resizeEnabled && enabledAnchors.indexOf('middle-right') >= 0
15270
15610
  });
15271
15611
  this.findOne('.bottom-left').setAttrs({
15272
- x: -padding,
15273
- y: height + padding,
15274
- scale: invertedScale,
15612
+ x: 0,
15613
+ y: height,
15614
+ offsetX: anchorSize / 2 + padding,
15615
+ offsetY: anchorSize / 2 - padding,
15275
15616
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-left') >= 0
15276
15617
  });
15277
15618
  this.findOne('.bottom-center').setAttrs({
15278
15619
  x: width / 2,
15279
- y: height + padding,
15280
- scale: invertedScale,
15620
+ y: height,
15621
+ offsetY: anchorSize / 2 - padding,
15281
15622
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-center') >= 0
15282
15623
  });
15283
15624
  this.findOne('.bottom-right').setAttrs({
15284
- x: width + padding,
15285
- y: height + padding,
15286
- scale: invertedScale,
15625
+ x: width,
15626
+ y: height,
15627
+ offsetX: anchorSize / 2 - padding,
15628
+ offsetY: anchorSize / 2 - padding,
15287
15629
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0
15288
15630
  });
15289
- var scaledRotateAnchorOffset = -this.rotateAnchorOffset() * Math.abs(invertedScale.y);
15290
15631
  this.findOne('.rotater').setAttrs({
15291
15632
  x: width / 2,
15292
- y: scaledRotateAnchorOffset * Util._sign(height) - padding,
15293
- scale: invertedScale,
15633
+ y: -this.rotateAnchorOffset() * Util._sign(height) - padding,
15294
15634
  visible: this.rotateEnabled()
15295
15635
  });
15296
15636
  this.findOne('.back').setAttrs({
15297
- width: width * scale.x,
15298
- height: height * scale.y,
15299
- scale: invertedScale,
15637
+ width: width,
15638
+ height: height,
15300
15639
  visible: this.borderEnabled(),
15301
15640
  stroke: this.borderStroke(),
15302
15641
  strokeWidth: this.borderStrokeWidth(),
15303
- dash: this.borderDash()
15642
+ dash: this.borderDash(),
15643
+ x: 0,
15644
+ y: 0
15304
15645
  });
15305
15646
  };
15306
15647
  /**
@@ -15629,7 +15970,8 @@
15629
15970
  */
15630
15971
  Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
15631
15972
  /**
15632
- * 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
15633
15975
  * @method
15634
15976
  * @name Konva.Transformer#Konva.Transformer#node
15635
15977
  * @returns {Konva.Node}
@@ -15642,7 +15984,25 @@
15642
15984
  */
15643
15985
  Factory.addGetterSetter(Transformer, 'node');
15644
15986
  /**
15645
- * get/set bounding box function
15987
+ * get/set attached nodes of the Transformer. Transformer will adapt to their size and listen to their events
15988
+ * @method
15989
+ * @name Konva.Transformer#Konva.Transformer#node
15990
+ * @returns {Konva.Node}
15991
+ * @example
15992
+ * // get
15993
+ * const nodes = transformer.nodes();
15994
+ *
15995
+ * // set
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);
16002
+ */
16003
+ Factory.addGetterSetter(Transformer, 'nodes');
16004
+ /**
16005
+ * get/set bounding box function. boundBondFunc operates is local coordinates of nodes parent
15646
16006
  * @name Konva.Transformer#boundBoxFunc
15647
16007
  * @method
15648
16008
  * @param {Function} func
@@ -15652,7 +16012,9 @@
15652
16012
  * var boundBoxFunc = transformer.boundBoxFunc();
15653
16013
  *
15654
16014
  * // set
15655
- * transformer.boundBoxFunc(function(oldBox, newBox) {
16015
+ * transformer.boundBoxFunc(function(oldBox, newBox, node) {
16016
+ * // width and height of the boxes are corresponding to total width and height of a node
16017
+ * // so it includes scale of the node.
15656
16018
  * if (newBox.width > 200) {
15657
16019
  * return oldBox;
15658
16020
  * }
@@ -15660,6 +16022,7 @@
15660
16022
  * });
15661
16023
  */
15662
16024
  Factory.addGetterSetter(Transformer, 'boundBoxFunc');
16025
+ Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
15663
16026
  Factory.backCompat(Transformer, {
15664
16027
  lineEnabled: 'borderEnabled',
15665
16028
  rotateHandlerOffset: 'rotateAnchorOffset',
@@ -15711,12 +16074,12 @@
15711
16074
  * @param {Number} [config.hitStrokeWidth] size of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
15712
16075
  * @param {Boolean} [config.strokeHitEnabled] flag which enables or disables stroke hit region. The default is true
15713
16076
  * @param {Boolean} [config.perfectDrawEnabled] flag which enables or disables using buffer canvas. The default is true
15714
- * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shasow for stroke. The default is true
16077
+ * @param {Boolean} [config.shadowForStrokeEnabled] flag which enables or disables shadow for stroke. The default is true
15715
16078
  * @param {Boolean} [config.strokeScaleEnabled] flag which enables or disables stroke scale. The default is true
15716
16079
  * @param {Boolean} [config.strokeEnabled] flag which enables or disables the stroke. The default value is true
15717
16080
  * @param {String} [config.lineJoin] can be miter, round, or bevel. The default
15718
16081
  * is miter
15719
- * @param {String} [config.lineCap] can be butt, round, or sqare. The default
16082
+ * @param {String} [config.lineCap] can be butt, round, or square. The default
15720
16083
  * is butt
15721
16084
  * @param {String} [config.shadowColor]
15722
16085
  * @param {Number} [config.shadowBlur]
@@ -15727,7 +16090,8 @@
15727
16090
  * between 0 and 1
15728
16091
  * @param {Boolean} [config.shadowEnabled] flag which enables or disables the shadow. The default value is true
15729
16092
  * @param {Array} [config.dash]
15730
- * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
16093
+ * @param {Boolean} [config.dashEnabled] flag which enables or disables the dashArray. The default value is true
16094
+
15731
16095
  * @param {Number} [config.x]
15732
16096
  * @param {Number} [config.y]
15733
16097
  * @param {Number} [config.width]