konva 8.2.1 → 8.3.0

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/cmj/Util.js CHANGED
@@ -737,7 +737,7 @@ exports.Util = {
737
737
  },
738
738
  _getFirstPointerId(evt) {
739
739
  if (!evt.touches) {
740
- return 999;
740
+ return evt.pointerId || 999;
741
741
  }
742
742
  else {
743
743
  return evt.changedTouches[0].identifier;
@@ -11,6 +11,7 @@ export interface ArrowConfig extends LineConfig {
11
11
  }
12
12
  export declare class Arrow extends Line<ArrowConfig> {
13
13
  _sceneFunc(ctx: any): void;
14
+ __fillStroke(ctx: any): void;
14
15
  getSelfRect(): {
15
16
  x: number;
16
17
  y: number;
@@ -49,6 +49,7 @@ class Arrow extends Line_1.Line {
49
49
  ctx.lineTo(-length, -width / 2);
50
50
  ctx.closePath();
51
51
  ctx.restore();
52
+ this.__fillStroke(ctx);
52
53
  }
53
54
  if (this.pointerAtBeginning()) {
54
55
  ctx.save();
@@ -68,11 +69,10 @@ class Arrow extends Line_1.Line {
68
69
  ctx.lineTo(-length, -width / 2);
69
70
  ctx.closePath();
70
71
  ctx.restore();
72
+ this.__fillStroke(ctx);
71
73
  }
72
- const hasPointer = this.pointerAtEnding() || this.pointerAtBeginning();
73
- if (!hasPointer) {
74
- return;
75
- }
74
+ }
75
+ __fillStroke(ctx) {
76
76
  var isDashEnabled = this.dashEnabled();
77
77
  if (isDashEnabled) {
78
78
  this.attrs.dashEnabled = false;
@@ -44,6 +44,7 @@ export declare class Transformer extends Group {
44
44
  attachTo(node: any): this;
45
45
  setNode(node: any): this;
46
46
  getNode(): Node<import("../Node").NodeConfig>;
47
+ _getEventNamespace(): string;
47
48
  setNodes(nodes?: Array<Node>): this;
48
49
  _proxyDrag(node: Node): void;
49
50
  getNodes(): Node<import("../Node").NodeConfig>[];
@@ -107,6 +108,7 @@ export declare class Transformer extends Group {
107
108
  flipEnabled: GetSet<boolean, this>;
108
109
  ignoreStroke: GetSet<boolean, this>;
109
110
  boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
111
+ anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Box, this>;
110
112
  shouldOverdrawWholeArea: GetSet<boolean, this>;
111
113
  useSingleNodeRotation: GetSet<boolean, this>;
112
114
  }
@@ -42,9 +42,7 @@ var TRANSFORM_CHANGE_STR = [
42
42
  'offsetYChange',
43
43
  'transformsEnabledChange',
44
44
  'strokeWidthChange',
45
- ]
46
- .map((e) => e + `.${EVENTS_NAME}`)
47
- .join(' ');
45
+ ];
48
46
  var ANGLES = {
49
47
  'top-left': -45,
50
48
  'top-center': 0,
@@ -162,6 +160,9 @@ class Transformer extends Group_1.Group {
162
160
  getNode() {
163
161
  return this._nodes && this._nodes[0];
164
162
  }
163
+ _getEventNamespace() {
164
+ return EVENTS_NAME + this._id;
165
+ }
165
166
  setNodes(nodes = []) {
166
167
  if (this._nodes && this._nodes.length) {
167
168
  this.detach();
@@ -174,9 +175,6 @@ class Transformer extends Group_1.Group {
174
175
  this.rotation(0);
175
176
  }
176
177
  this._nodes.forEach((node) => {
177
- const additionalEvents = node._attrsAffectingSize
178
- .map((prop) => prop + 'Change.' + EVENTS_NAME)
179
- .join(' ');
180
178
  const onChange = () => {
181
179
  if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
182
180
  this.rotation(this.nodes()[0].getAbsoluteRotation());
@@ -186,10 +184,12 @@ class Transformer extends Group_1.Group {
186
184
  this.update();
187
185
  }
188
186
  };
187
+ const additionalEvents = node._attrsAffectingSize
188
+ .map((prop) => prop + 'Change.' + this._getEventNamespace())
189
+ .join(' ');
189
190
  node.on(additionalEvents, onChange);
190
- node.on(TRANSFORM_CHANGE_STR, onChange);
191
- node.on(`absoluteTransformChange.${EVENTS_NAME}`, onChange);
192
- node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
191
+ node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
192
+ node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
193
193
  this._proxyDrag(node);
194
194
  });
195
195
  this._resetTransformCache();
@@ -201,13 +201,13 @@ class Transformer extends Group_1.Group {
201
201
  }
202
202
  _proxyDrag(node) {
203
203
  let lastPos;
204
- node.on(`dragstart.${EVENTS_NAME}`, (e) => {
204
+ node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
205
205
  lastPos = node.getAbsolutePosition();
206
206
  if (!this.isDragging() && node !== this.findOne('.back')) {
207
207
  this.startDrag(e, false);
208
208
  }
209
209
  });
210
- node.on(`dragmove.${EVENTS_NAME}`, (e) => {
210
+ node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
211
211
  if (!lastPos) {
212
212
  return;
213
213
  }
@@ -240,7 +240,7 @@ class Transformer extends Group_1.Group {
240
240
  detach() {
241
241
  if (this._nodes) {
242
242
  this._nodes.forEach((node) => {
243
- node.off('.' + EVENTS_NAME);
243
+ node.off('.' + this._getEventNamespace());
244
244
  });
245
245
  }
246
246
  this._nodes = [];
@@ -460,11 +460,14 @@ class Transformer extends Group_1.Group {
460
460
  var stage = anchorNode.getStage();
461
461
  stage.setPointersPositions(e);
462
462
  const pp = stage.getPointerPosition();
463
- var newNodePos = {
463
+ let newNodePos = {
464
464
  x: pp.x - this._anchorDragOffset.x,
465
465
  y: pp.y - this._anchorDragOffset.y,
466
466
  };
467
467
  const oldAbs = anchorNode.getAbsolutePosition();
468
+ if (this.anchorDragBoundFunc()) {
469
+ newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
470
+ }
468
471
  anchorNode.setAbsolutePosition(newNodePos);
469
472
  const newAbs = anchorNode.getAbsolutePosition();
470
473
  if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
@@ -939,6 +942,7 @@ Factory_1.Factory.addGetterSetter(Transformer, 'padding', 0, (0, Validators_1.ge
939
942
  Factory_1.Factory.addGetterSetter(Transformer, 'node');
940
943
  Factory_1.Factory.addGetterSetter(Transformer, 'nodes');
941
944
  Factory_1.Factory.addGetterSetter(Transformer, 'boundBoxFunc');
945
+ Factory_1.Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
942
946
  Factory_1.Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
943
947
  Factory_1.Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
944
948
  Factory_1.Factory.backCompat(Transformer, {
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.2.1
8
+ * Konva JavaScript Framework v8.3.0
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Fri Sep 24 2021
11
+ * Date: Mon Nov 15 2021
12
12
  *
13
13
  * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
14
14
  * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
@@ -35,7 +35,7 @@
35
35
  : {};
36
36
  const Konva$2 = {
37
37
  _global: glob,
38
- version: '8.2.1',
38
+ version: '8.3.0',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -1070,8 +1070,8 @@
1070
1070
  },
1071
1071
  _getFirstPointerId(evt) {
1072
1072
  if (!evt.touches) {
1073
- // fake id for mouse
1074
- return 999;
1073
+ // try to use pointer id or fake id
1074
+ return evt.pointerId || 999;
1075
1075
  }
1076
1076
  else {
1077
1077
  return evt.changedTouches[0].identifier;
@@ -11060,6 +11060,7 @@
11060
11060
  ctx.lineTo(-length, -width / 2);
11061
11061
  ctx.closePath();
11062
11062
  ctx.restore();
11063
+ this.__fillStroke(ctx);
11063
11064
  }
11064
11065
  if (this.pointerAtBeginning()) {
11065
11066
  ctx.save();
@@ -11079,11 +11080,10 @@
11079
11080
  ctx.lineTo(-length, -width / 2);
11080
11081
  ctx.closePath();
11081
11082
  ctx.restore();
11083
+ this.__fillStroke(ctx);
11082
11084
  }
11083
- const hasPointer = this.pointerAtEnding() || this.pointerAtBeginning();
11084
- if (!hasPointer) {
11085
- return;
11086
- }
11085
+ }
11086
+ __fillStroke(ctx) {
11087
11087
  // here is a tricky part
11088
11088
  // we need to disable dash for arrow pointers
11089
11089
  var isDashEnabled = this.dashEnabled();
@@ -14463,9 +14463,7 @@
14463
14463
  'offsetYChange',
14464
14464
  'transformsEnabledChange',
14465
14465
  'strokeWidthChange',
14466
- ]
14467
- .map((e) => e + `.${EVENTS_NAME}`)
14468
- .join(' ');
14466
+ ];
14469
14467
  var ANGLES = {
14470
14468
  'top-left': -45,
14471
14469
  'top-center': 0,
@@ -14641,6 +14639,9 @@
14641
14639
  getNode() {
14642
14640
  return this._nodes && this._nodes[0];
14643
14641
  }
14642
+ _getEventNamespace() {
14643
+ return EVENTS_NAME + this._id;
14644
+ }
14644
14645
  setNodes(nodes = []) {
14645
14646
  if (this._nodes && this._nodes.length) {
14646
14647
  this.detach();
@@ -14653,9 +14654,6 @@
14653
14654
  this.rotation(0);
14654
14655
  }
14655
14656
  this._nodes.forEach((node) => {
14656
- const additionalEvents = node._attrsAffectingSize
14657
- .map((prop) => prop + 'Change.' + EVENTS_NAME)
14658
- .join(' ');
14659
14657
  const onChange = () => {
14660
14658
  if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
14661
14659
  this.rotation(this.nodes()[0].getAbsoluteRotation());
@@ -14665,10 +14663,12 @@
14665
14663
  this.update();
14666
14664
  }
14667
14665
  };
14666
+ const additionalEvents = node._attrsAffectingSize
14667
+ .map((prop) => prop + 'Change.' + this._getEventNamespace())
14668
+ .join(' ');
14668
14669
  node.on(additionalEvents, onChange);
14669
- node.on(TRANSFORM_CHANGE_STR, onChange);
14670
- node.on(`absoluteTransformChange.${EVENTS_NAME}`, onChange);
14671
- node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
14670
+ node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
14671
+ node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
14672
14672
  this._proxyDrag(node);
14673
14673
  });
14674
14674
  this._resetTransformCache();
@@ -14682,7 +14682,7 @@
14682
14682
  }
14683
14683
  _proxyDrag(node) {
14684
14684
  let lastPos;
14685
- node.on(`dragstart.${EVENTS_NAME}`, (e) => {
14685
+ node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
14686
14686
  lastPos = node.getAbsolutePosition();
14687
14687
  // actual dragging of Transformer doesn't make sense
14688
14688
  // but we need to make sure it also has all drag events
@@ -14690,7 +14690,7 @@
14690
14690
  this.startDrag(e, false);
14691
14691
  }
14692
14692
  });
14693
- node.on(`dragmove.${EVENTS_NAME}`, (e) => {
14693
+ node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
14694
14694
  if (!lastPos) {
14695
14695
  return;
14696
14696
  }
@@ -14740,7 +14740,7 @@
14740
14740
  // remove events
14741
14741
  if (this._nodes) {
14742
14742
  this._nodes.forEach((node) => {
14743
- node.off('.' + EVENTS_NAME);
14743
+ node.off('.' + this._getEventNamespace());
14744
14744
  });
14745
14745
  }
14746
14746
  this._nodes = [];
@@ -14977,13 +14977,17 @@
14977
14977
  var stage = anchorNode.getStage();
14978
14978
  stage.setPointersPositions(e);
14979
14979
  const pp = stage.getPointerPosition();
14980
- var newNodePos = {
14980
+ let newNodePos = {
14981
14981
  x: pp.x - this._anchorDragOffset.x,
14982
14982
  y: pp.y - this._anchorDragOffset.y,
14983
14983
  };
14984
14984
  const oldAbs = anchorNode.getAbsolutePosition();
14985
+ if (this.anchorDragBoundFunc()) {
14986
+ newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
14987
+ }
14985
14988
  anchorNode.setAbsolutePosition(newNodePos);
14986
14989
  const newAbs = anchorNode.getAbsolutePosition();
14990
+ // console.log(oldAbs, newNodePos, newAbs);
14987
14991
  if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
14988
14992
  return;
14989
14993
  }
@@ -15792,6 +15796,25 @@
15792
15796
  * });
15793
15797
  */
15794
15798
  Factory.addGetterSetter(Transformer, 'boundBoxFunc');
15799
+ /**
15800
+ * get/set dragging func for transformer anchors
15801
+ * @name Konva.Transformer#anchorDragBoundFunc
15802
+ * @method
15803
+ * @param {Function} func
15804
+ * @returns {Function}
15805
+ * @example
15806
+ * // get
15807
+ * var anchorDragBoundFunc = transformer.anchorDragBoundFunc();
15808
+ *
15809
+ * // set
15810
+ * transformer.anchorDragBoundFunc(function(oldAbsPos, newAbsPos, event) {
15811
+ * return {
15812
+ * x: 0,
15813
+ * y: newAbsolutePosition.y
15814
+ * }
15815
+ * });
15816
+ */
15817
+ Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
15795
15818
  /**
15796
15819
  * using this setting you can drag transformer group by dragging empty space between attached nodes
15797
15820
  * shouldOverdrawWholeArea = true may temporary disable all events on attached nodes