konva 8.3.0 → 8.3.3

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.3.0',
16
+ version: '8.3.3',
17
17
  isBrowser: detectBrowser(),
18
18
  isUnminified: /param/.test(function (param) { }.toString()),
19
19
  dblClickWindow: 400,
package/lib/Node.js CHANGED
@@ -623,11 +623,14 @@ export class Node {
623
623
  Util.warn('Node has no parent. moveToTop function is ignored.');
624
624
  return false;
625
625
  }
626
- var index = this.index;
627
- this.parent.children.splice(index, 1);
628
- this.parent.children.push(this);
629
- this.parent._setChildrenIndices();
630
- return true;
626
+ var index = this.index, len = this.parent.getChildren().length;
627
+ if (index < len - 1) {
628
+ this.parent.children.splice(index, 1);
629
+ this.parent.children.push(this);
630
+ this.parent._setChildrenIndices();
631
+ return true;
632
+ }
633
+ return false;
631
634
  }
632
635
  moveUp() {
633
636
  if (!this.parent) {
@@ -1287,8 +1290,8 @@ export class Node {
1287
1290
  const screenRect = {
1288
1291
  x: -margin.x,
1289
1292
  y: -margin.y,
1290
- width: stage.width() + margin.x,
1291
- height: stage.height() + margin.y,
1293
+ width: stage.width() + 2 * margin.x,
1294
+ height: stage.height() + 2 * margin.y,
1292
1295
  };
1293
1296
  return Util.haveIntersection(screenRect, this.getClientRect());
1294
1297
  }
package/lib/Stage.js CHANGED
@@ -490,14 +490,12 @@ export class Stage extends Container {
490
490
  const pointerId = pos.id;
491
491
  const event = { evt: evt, pointerId };
492
492
  let fireDblClick = false;
493
- if (Konva['_' + eventType + 'InDblClickWindow'] &&
494
- Konva['_' + eventType + 'InDblClickWindowId'] === pointerId) {
493
+ if (Konva['_' + eventType + 'InDblClickWindow']) {
495
494
  fireDblClick = true;
496
495
  clearTimeout(this[eventType + 'DblTimeout']);
497
496
  }
498
497
  else if (!DD.justDragged) {
499
498
  Konva['_' + eventType + 'InDblClickWindow'] = true;
500
- Konva['_' + eventType + 'InDblClickWindowId'] = pointerId;
501
499
  clearTimeout(this[eventType + 'DblTimeout']);
502
500
  }
503
501
  this[eventType + 'DblTimeout'] = setTimeout(function () {
package/lib/Util.js CHANGED
@@ -474,7 +474,12 @@ export const Util = {
474
474
  _rgbaColorToRGBA(str) {
475
475
  if (str.indexOf('rgba(') === 0) {
476
476
  str = str.match(/rgba\(([^)]+)\)/)[1];
477
- var parts = str.split(/ *, */).map(Number);
477
+ var parts = str.split(/ *, */).map((n, index) => {
478
+ if (n.slice(-1) === '%') {
479
+ return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
480
+ }
481
+ return Number(n);
482
+ });
478
483
  return {
479
484
  r: parts[0],
480
485
  g: parts[1],
@@ -71,6 +71,7 @@ declare namespace Konva {
71
71
 
72
72
  export const Stage: typeof import('./Stage').Stage;
73
73
  export type Stage = import('./Stage').Stage;
74
+ export type StageConfig = import('./Stage').StageConfig;
74
75
  export const stages: typeof import('./Stage').stages;
75
76
 
76
77
  export const Layer: typeof import('./Layer').Layer;
@@ -12,6 +12,12 @@ export declare class Arc extends Shape<ArcConfig> {
12
12
  getHeight(): number;
13
13
  setWidth(width: any): void;
14
14
  setHeight(height: any): void;
15
+ getSelfRect(): {
16
+ x: number;
17
+ y: number;
18
+ width: number;
19
+ height: number;
20
+ };
15
21
  innerRadius: GetSet<number, this>;
16
22
  outerRadius: GetSet<number, this>;
17
23
  angle: GetSet<number, this>;
package/lib/shapes/Arc.js CHANGED
@@ -24,6 +24,26 @@ export class Arc extends Shape {
24
24
  setHeight(height) {
25
25
  this.outerRadius(height / 2);
26
26
  }
27
+ getSelfRect() {
28
+ const innerRadius = this.innerRadius();
29
+ const outerRadius = this.outerRadius();
30
+ const clockwise = this.clockwise();
31
+ const angle = Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
32
+ const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
33
+ const boundRightRatio = 1;
34
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
35
+ const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
36
+ const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
37
+ const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
38
+ const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
39
+ const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
40
+ return {
41
+ x: Math.round(boundLeft),
42
+ y: Math.round(clockwise ? -1 * boundBottom : boundTop),
43
+ width: Math.round(boundRight - boundLeft),
44
+ height: Math.round(boundBottom - boundTop)
45
+ };
46
+ }
27
47
  }
28
48
  Arc.prototype._centroid = true;
29
49
  Arc.prototype.className = 'Arc';
@@ -13,7 +13,7 @@ export declare class Image extends Shape<ImageConfig> {
13
13
  _hitFunc(context: any): void;
14
14
  getWidth(): any;
15
15
  getHeight(): any;
16
- static fromURL(url: any, callback: any): void;
16
+ static fromURL(url: any, callback: any, onError?: any): void;
17
17
  image: GetSet<CanvasImageSource | undefined, this>;
18
18
  crop: GetSet<IRect, this>;
19
19
  cropX: GetSet<number, this>;
@@ -78,7 +78,7 @@ export class Image extends Shape {
78
78
  var _a, _b;
79
79
  return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
80
80
  }
81
- static fromURL(url, callback) {
81
+ static fromURL(url, callback, onError = null) {
82
82
  var img = Util.createImageElement();
83
83
  img.onload = function () {
84
84
  var image = new Image({
@@ -86,6 +86,7 @@ export class Image extends Shape {
86
86
  });
87
87
  callback(image);
88
88
  };
89
+ img.onerror = onError;
89
90
  img.crossOrigin = 'Anonymous';
90
91
  img.src = url;
91
92
  }
@@ -20,6 +20,7 @@ export declare class Text extends Shape<TextConfig> {
20
20
  textArr: Array<{
21
21
  text: string;
22
22
  width: number;
23
+ lastInParagraph: boolean;
23
24
  }>;
24
25
  _partialText: string;
25
26
  _partialTextX: number;
@@ -92,7 +92,7 @@ export class Text extends Shape {
92
92
  for (n = 0; n < textArrLen; n++) {
93
93
  var lineTranslateX = 0;
94
94
  var lineTranslateY = 0;
95
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = n !== textArrLen - 1, spacesNumber, oneWord, lineWidth;
95
+ var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
96
96
  context.save();
97
97
  if (align === RIGHT) {
98
98
  lineTranslateX += totalWidth - width - padding * 2;
@@ -137,7 +137,7 @@ export class Text extends Shape {
137
137
  var array = stringToArray(text);
138
138
  for (var li = 0; li < array.length; li++) {
139
139
  var letter = array[li];
140
- if (letter === ' ' && n !== textArrLen - 1 && align === JUSTIFY) {
140
+ if (letter === ' ' && !lastLine && align === JUSTIFY) {
141
141
  lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
142
142
  }
143
143
  this._partialTextX = lineTranslateX;
@@ -217,7 +217,11 @@ export class Text extends Shape {
217
217
  line = line.trim();
218
218
  }
219
219
  var width = this._getTextWidth(line);
220
- return this.textArr.push({ text: line, width: width });
220
+ return this.textArr.push({
221
+ text: line,
222
+ width: width,
223
+ lastInParagraph: false,
224
+ });
221
225
  }
222
226
  _getTextWidth(text) {
223
227
  var letterSpacing = this.letterSpacing();
@@ -310,6 +314,9 @@ export class Text extends Shape {
310
314
  if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
311
315
  break;
312
316
  }
317
+ if (this.textArr[this.textArr.length - 1]) {
318
+ this.textArr[this.textArr.length - 1].lastInParagraph = true;
319
+ }
313
320
  }
314
321
  this.textHeight = fontSize;
315
322
  this.textWidth = textWidth;
@@ -108,7 +108,7 @@ export declare class Transformer extends Group {
108
108
  flipEnabled: GetSet<boolean, this>;
109
109
  ignoreStroke: GetSet<boolean, this>;
110
110
  boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
111
- anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Box, this>;
111
+ anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
112
112
  shouldOverdrawWholeArea: GetSet<boolean, this>;
113
113
  useSingleNodeRotation: GetSet<boolean, this>;
114
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "konva",
3
- "version": "8.3.0",
3
+ "version": "8.3.3",
4
4
  "author": "Anton Lavrenov",
5
5
  "files": [
6
6
  "README.md",