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/lib/Global.js CHANGED
@@ -13,7 +13,7 @@ export const glob = typeof global !== 'undefined'
13
13
  : {};
14
14
  export const Konva = {
15
15
  _global: glob,
16
- version: '8.2.1',
16
+ version: '8.3.0',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/Util.js CHANGED
@@ -733,7 +733,7 @@ export const Util = {
733
733
  },
734
734
  _getFirstPointerId(evt) {
735
735
  if (!evt.touches) {
736
- return 999;
736
+ return evt.pointerId || 999;
737
737
  }
738
738
  else {
739
739
  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;
@@ -46,6 +46,7 @@ export class Arrow extends Line {
46
46
  ctx.lineTo(-length, -width / 2);
47
47
  ctx.closePath();
48
48
  ctx.restore();
49
+ this.__fillStroke(ctx);
49
50
  }
50
51
  if (this.pointerAtBeginning()) {
51
52
  ctx.save();
@@ -65,11 +66,10 @@ export class Arrow extends Line {
65
66
  ctx.lineTo(-length, -width / 2);
66
67
  ctx.closePath();
67
68
  ctx.restore();
69
+ this.__fillStroke(ctx);
68
70
  }
69
- const hasPointer = this.pointerAtEnding() || this.pointerAtBeginning();
70
- if (!hasPointer) {
71
- return;
72
- }
71
+ }
72
+ __fillStroke(ctx) {
73
73
  var isDashEnabled = this.dashEnabled();
74
74
  if (isDashEnabled) {
75
75
  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
  }
@@ -39,9 +39,7 @@ var TRANSFORM_CHANGE_STR = [
39
39
  'offsetYChange',
40
40
  'transformsEnabledChange',
41
41
  'strokeWidthChange',
42
- ]
43
- .map((e) => e + `.${EVENTS_NAME}`)
44
- .join(' ');
42
+ ];
45
43
  var ANGLES = {
46
44
  'top-left': -45,
47
45
  'top-center': 0,
@@ -159,6 +157,9 @@ export class Transformer extends Group {
159
157
  getNode() {
160
158
  return this._nodes && this._nodes[0];
161
159
  }
160
+ _getEventNamespace() {
161
+ return EVENTS_NAME + this._id;
162
+ }
162
163
  setNodes(nodes = []) {
163
164
  if (this._nodes && this._nodes.length) {
164
165
  this.detach();
@@ -171,9 +172,6 @@ export class Transformer extends Group {
171
172
  this.rotation(0);
172
173
  }
173
174
  this._nodes.forEach((node) => {
174
- const additionalEvents = node._attrsAffectingSize
175
- .map((prop) => prop + 'Change.' + EVENTS_NAME)
176
- .join(' ');
177
175
  const onChange = () => {
178
176
  if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
179
177
  this.rotation(this.nodes()[0].getAbsoluteRotation());
@@ -183,10 +181,12 @@ export class Transformer extends Group {
183
181
  this.update();
184
182
  }
185
183
  };
184
+ const additionalEvents = node._attrsAffectingSize
185
+ .map((prop) => prop + 'Change.' + this._getEventNamespace())
186
+ .join(' ');
186
187
  node.on(additionalEvents, onChange);
187
- node.on(TRANSFORM_CHANGE_STR, onChange);
188
- node.on(`absoluteTransformChange.${EVENTS_NAME}`, onChange);
189
- node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
188
+ node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
189
+ node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
190
190
  this._proxyDrag(node);
191
191
  });
192
192
  this._resetTransformCache();
@@ -198,13 +198,13 @@ export class Transformer extends Group {
198
198
  }
199
199
  _proxyDrag(node) {
200
200
  let lastPos;
201
- node.on(`dragstart.${EVENTS_NAME}`, (e) => {
201
+ node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
202
202
  lastPos = node.getAbsolutePosition();
203
203
  if (!this.isDragging() && node !== this.findOne('.back')) {
204
204
  this.startDrag(e, false);
205
205
  }
206
206
  });
207
- node.on(`dragmove.${EVENTS_NAME}`, (e) => {
207
+ node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
208
208
  if (!lastPos) {
209
209
  return;
210
210
  }
@@ -237,7 +237,7 @@ export class Transformer extends Group {
237
237
  detach() {
238
238
  if (this._nodes) {
239
239
  this._nodes.forEach((node) => {
240
- node.off('.' + EVENTS_NAME);
240
+ node.off('.' + this._getEventNamespace());
241
241
  });
242
242
  }
243
243
  this._nodes = [];
@@ -457,11 +457,14 @@ export class Transformer extends Group {
457
457
  var stage = anchorNode.getStage();
458
458
  stage.setPointersPositions(e);
459
459
  const pp = stage.getPointerPosition();
460
- var newNodePos = {
460
+ let newNodePos = {
461
461
  x: pp.x - this._anchorDragOffset.x,
462
462
  y: pp.y - this._anchorDragOffset.y,
463
463
  };
464
464
  const oldAbs = anchorNode.getAbsolutePosition();
465
+ if (this.anchorDragBoundFunc()) {
466
+ newNodePos = this.anchorDragBoundFunc()(oldAbs, newNodePos, e);
467
+ }
465
468
  anchorNode.setAbsolutePosition(newNodePos);
466
469
  const newAbs = anchorNode.getAbsolutePosition();
467
470
  if (oldAbs.x === newAbs.x && oldAbs.y === newAbs.y) {
@@ -935,6 +938,7 @@ Factory.addGetterSetter(Transformer, 'padding', 0, getNumberValidator());
935
938
  Factory.addGetterSetter(Transformer, 'node');
936
939
  Factory.addGetterSetter(Transformer, 'nodes');
937
940
  Factory.addGetterSetter(Transformer, 'boundBoxFunc');
941
+ Factory.addGetterSetter(Transformer, 'anchorDragBoundFunc');
938
942
  Factory.addGetterSetter(Transformer, 'shouldOverdrawWholeArea', false);
939
943
  Factory.addGetterSetter(Transformer, 'useSingleNodeRotation', true);
940
944
  Factory.backCompat(Transformer, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",
@@ -22,7 +22,7 @@
22
22
  "test:build": "parcel build ./test/unit-tests.html --dist-dir test-build --target none --public-url ./ --no-source-maps",
23
23
  "test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
24
24
  "test:node": "env TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha -r ts-node/register test/unit/**/*.ts --exit && npm run test:import",
25
- "test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html",
25
+ "test:watch": "rm -rf ./parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html",
26
26
  "tsc": "tsc --removeComments && tsc --build ./tsconfig-cmj.json",
27
27
  "rollup": "rollup -c",
28
28
  "clean": "rm -rf ./lib && rm -rf ./types && rm -rf ./cmj && rm -rf ./test-build",