konva 8.3.1 → 8.3.2

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.
Files changed (126) hide show
  1. package/cmj/Util.js +6 -1
  2. package/cmj/shapes/Arc.js +16 -24
  3. package/cmj/shapes/Image.d.ts +1 -1
  4. package/cmj/shapes/Image.js +2 -1
  5. package/konva.js +28 -27
  6. package/konva.min.js +3 -3
  7. package/lib/Animation.js +0 -1
  8. package/lib/Canvas.js +0 -1
  9. package/lib/Container.js +0 -1
  10. package/lib/Context.js +0 -1
  11. package/lib/Core.js +0 -1
  12. package/lib/DragAndDrop.js +0 -1
  13. package/lib/Factory.js +0 -1
  14. package/lib/FastLayer.js +0 -1
  15. package/lib/Global.js +1 -2
  16. package/lib/Group.js +0 -1
  17. package/lib/Layer.js +0 -1
  18. package/lib/Node.js +0 -1
  19. package/lib/PointerEvents.js +0 -1
  20. package/lib/Shape.js +0 -1
  21. package/lib/Stage.js +0 -1
  22. package/lib/Tween.js +0 -1
  23. package/lib/Util.js +6 -2
  24. package/lib/Validators.js +0 -1
  25. package/lib/_CoreInternals.js +0 -1
  26. package/lib/_FullInternals.js +0 -1
  27. package/lib/filters/Blur.js +0 -1
  28. package/lib/filters/Brighten.js +0 -1
  29. package/lib/filters/Contrast.js +0 -1
  30. package/lib/filters/Emboss.js +0 -1
  31. package/lib/filters/Enhance.js +0 -1
  32. package/lib/filters/Grayscale.js +0 -1
  33. package/lib/filters/HSL.js +0 -1
  34. package/lib/filters/HSV.js +0 -1
  35. package/lib/filters/Invert.js +0 -1
  36. package/lib/filters/Kaleidoscope.js +0 -1
  37. package/lib/filters/Mask.js +0 -1
  38. package/lib/filters/Noise.js +0 -1
  39. package/lib/filters/Pixelate.js +0 -1
  40. package/lib/filters/Posterize.js +0 -1
  41. package/lib/filters/RGB.js +0 -1
  42. package/lib/filters/RGBA.js +0 -1
  43. package/lib/filters/Sepia.js +0 -1
  44. package/lib/filters/Solarize.js +0 -1
  45. package/lib/filters/Threshold.js +0 -1
  46. package/lib/index-node.js +0 -1
  47. package/lib/index.js +0 -1
  48. package/lib/shapes/Arc.js +16 -25
  49. package/lib/shapes/Arrow.js +0 -1
  50. package/lib/shapes/Circle.js +0 -1
  51. package/lib/shapes/Ellipse.js +0 -1
  52. package/lib/shapes/Image.d.ts +1 -1
  53. package/lib/shapes/Image.js +2 -2
  54. package/lib/shapes/Label.js +0 -1
  55. package/lib/shapes/Line.js +0 -1
  56. package/lib/shapes/Path.js +0 -1
  57. package/lib/shapes/Rect.js +0 -1
  58. package/lib/shapes/RegularPolygon.js +0 -1
  59. package/lib/shapes/Ring.js +0 -1
  60. package/lib/shapes/Sprite.js +0 -1
  61. package/lib/shapes/Star.js +0 -1
  62. package/lib/shapes/Text.js +0 -1
  63. package/lib/shapes/TextPath.js +0 -1
  64. package/lib/shapes/Transformer.js +0 -1
  65. package/lib/shapes/Wedge.js +0 -1
  66. package/lib/types.js +0 -1
  67. package/package.json +1 -1
  68. package/lib/Animation.js.map +0 -1
  69. package/lib/Canvas.js.map +0 -1
  70. package/lib/Container.js.map +0 -1
  71. package/lib/Context.js.map +0 -1
  72. package/lib/Core.js.map +0 -1
  73. package/lib/DragAndDrop.js.map +0 -1
  74. package/lib/Factory.js.map +0 -1
  75. package/lib/FastLayer.js.map +0 -1
  76. package/lib/Global.js.map +0 -1
  77. package/lib/Group.js.map +0 -1
  78. package/lib/Layer.js.map +0 -1
  79. package/lib/Node.js.map +0 -1
  80. package/lib/PointerEvents.js.map +0 -1
  81. package/lib/Shape.js.map +0 -1
  82. package/lib/Stage.js.map +0 -1
  83. package/lib/Tween.js.map +0 -1
  84. package/lib/Util.js.map +0 -1
  85. package/lib/Validators.js.map +0 -1
  86. package/lib/_CoreInternals.js.map +0 -1
  87. package/lib/_FullInternals.js.map +0 -1
  88. package/lib/filters/Blur.js.map +0 -1
  89. package/lib/filters/Brighten.js.map +0 -1
  90. package/lib/filters/Contrast.js.map +0 -1
  91. package/lib/filters/Emboss.js.map +0 -1
  92. package/lib/filters/Enhance.js.map +0 -1
  93. package/lib/filters/Grayscale.js.map +0 -1
  94. package/lib/filters/HSL.js.map +0 -1
  95. package/lib/filters/HSV.js.map +0 -1
  96. package/lib/filters/Invert.js.map +0 -1
  97. package/lib/filters/Kaleidoscope.js.map +0 -1
  98. package/lib/filters/Mask.js.map +0 -1
  99. package/lib/filters/Noise.js.map +0 -1
  100. package/lib/filters/Pixelate.js.map +0 -1
  101. package/lib/filters/Posterize.js.map +0 -1
  102. package/lib/filters/RGB.js.map +0 -1
  103. package/lib/filters/RGBA.js.map +0 -1
  104. package/lib/filters/Sepia.js.map +0 -1
  105. package/lib/filters/Solarize.js.map +0 -1
  106. package/lib/filters/Threshold.js.map +0 -1
  107. package/lib/index-node.js.map +0 -1
  108. package/lib/index.js.map +0 -1
  109. package/lib/shapes/Arc.js.map +0 -1
  110. package/lib/shapes/Arrow.js.map +0 -1
  111. package/lib/shapes/Circle.js.map +0 -1
  112. package/lib/shapes/Ellipse.js.map +0 -1
  113. package/lib/shapes/Image.js.map +0 -1
  114. package/lib/shapes/Label.js.map +0 -1
  115. package/lib/shapes/Line.js.map +0 -1
  116. package/lib/shapes/Path.js.map +0 -1
  117. package/lib/shapes/Rect.js.map +0 -1
  118. package/lib/shapes/RegularPolygon.js.map +0 -1
  119. package/lib/shapes/Ring.js.map +0 -1
  120. package/lib/shapes/Sprite.js.map +0 -1
  121. package/lib/shapes/Star.js.map +0 -1
  122. package/lib/shapes/Text.js.map +0 -1
  123. package/lib/shapes/TextPath.js.map +0 -1
  124. package/lib/shapes/Transformer.js.map +0 -1
  125. package/lib/shapes/Wedge.js.map +0 -1
  126. package/lib/types.js.map +0 -1
package/cmj/Util.js CHANGED
@@ -478,7 +478,12 @@ exports.Util = {
478
478
  _rgbaColorToRGBA(str) {
479
479
  if (str.indexOf('rgba(') === 0) {
480
480
  str = str.match(/rgba\(([^)]+)\)/)[1];
481
- var parts = str.split(/ *, */).map(Number);
481
+ var parts = str.split(/ *, */).map((n, index) => {
482
+ if (n.slice(-1) === '%') {
483
+ return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
484
+ }
485
+ return Number(n);
486
+ });
482
487
  return {
483
488
  r: parts[0],
484
489
  g: parts[1],
package/cmj/shapes/Arc.js CHANGED
@@ -28,31 +28,23 @@ class Arc extends Shape_1.Shape {
28
28
  this.outerRadius(height / 2);
29
29
  }
30
30
  getSelfRect() {
31
- const radius = this.outerRadius();
32
- const DEG_TO_RAD = Math.PI / 180;
33
- const angle = this.angle() * DEG_TO_RAD;
34
- const inc = 1 * DEG_TO_RAD;
35
- let start = 0;
36
- let end = angle + inc;
37
- if (this.clockwise()) {
38
- start = end;
39
- end = 360;
40
- }
41
- const xs = [];
42
- const ys = [];
43
- for (let i = 0; i < end; i += inc) {
44
- xs.push(Math.cos(i));
45
- ys.push(Math.sin(i));
46
- }
47
- const minX = Math.round(radius * Math.min(...xs));
48
- const maxX = Math.round(radius * Math.max(...xs));
49
- const minY = Math.round(radius * Math.min(...ys));
50
- const maxY = Math.round(radius * Math.max(...ys));
31
+ const innerRadius = this.innerRadius();
32
+ const outerRadius = this.outerRadius();
33
+ const clockwise = this.clockwise();
34
+ const angle = Global_1.Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
35
+ const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
36
+ const boundRightRatio = 1;
37
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
38
+ const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
39
+ const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
40
+ const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
41
+ const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
42
+ const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
51
43
  return {
52
- x: minX || 0,
53
- y: minY || 0,
54
- width: maxX - minX,
55
- height: maxY - minY
44
+ x: Math.round(boundLeft),
45
+ y: Math.round(clockwise ? -1 * boundBottom : boundTop),
46
+ width: Math.round(boundRight - boundLeft),
47
+ height: Math.round(boundBottom - boundTop)
56
48
  };
57
49
  }
58
50
  }
@@ -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>;
@@ -81,7 +81,7 @@ class Image extends Shape_1.Shape {
81
81
  var _a, _b;
82
82
  return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
83
83
  }
84
- static fromURL(url, callback) {
84
+ static fromURL(url, callback, onError = null) {
85
85
  var img = Util_1.Util.createImageElement();
86
86
  img.onload = function () {
87
87
  var image = new Image({
@@ -89,6 +89,7 @@ class Image extends Shape_1.Shape {
89
89
  });
90
90
  callback(image);
91
91
  };
92
+ img.onerror = onError;
92
93
  img.crossOrigin = 'Anonymous';
93
94
  img.src = url;
94
95
  }
package/konva.js CHANGED
@@ -5,10 +5,10 @@
5
5
  })(this, (function () { 'use strict';
6
6
 
7
7
  /*
8
- * Konva JavaScript Framework v8.3.1
8
+ * Konva JavaScript Framework v8.3.2
9
9
  * http://konvajs.org/
10
10
  * Licensed under the MIT
11
- * Date: Thu Dec 09 2021
11
+ * Date: Tue Jan 04 2022
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.3.1',
38
+ version: '8.3.2',
39
39
  isBrowser: detectBrowser(),
40
40
  isUnminified: /param/.test(function (param) { }.toString()),
41
41
  dblClickWindow: 400,
@@ -794,7 +794,12 @@
794
794
  _rgbaColorToRGBA(str) {
795
795
  if (str.indexOf('rgba(') === 0) {
796
796
  str = str.match(/rgba\(([^)]+)\)/)[1];
797
- var parts = str.split(/ *, */).map(Number);
797
+ var parts = str.split(/ *, */).map((n, index) => {
798
+ if (n.slice(-1) === '%') {
799
+ return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
800
+ }
801
+ return Number(n);
802
+ });
798
803
  return {
799
804
  r: parts[0],
800
805
  g: parts[1],
@@ -9721,29 +9726,23 @@
9721
9726
  this.outerRadius(height / 2);
9722
9727
  }
9723
9728
  getSelfRect() {
9724
- const radius = this.outerRadius();
9725
- const DEG_TO_RAD = Math.PI / 180;
9726
- const angle = this.angle() * DEG_TO_RAD;
9727
- const inc = 1 * DEG_TO_RAD;
9728
- let end = angle + inc;
9729
- if (this.clockwise()) {
9730
- end = 360;
9731
- }
9732
- const xs = [];
9733
- const ys = [];
9734
- for (let i = 0; i < end; i += inc) {
9735
- xs.push(Math.cos(i));
9736
- ys.push(Math.sin(i));
9737
- }
9738
- const minX = Math.round(radius * Math.min(...xs));
9739
- const maxX = Math.round(radius * Math.max(...xs));
9740
- const minY = Math.round(radius * Math.min(...ys));
9741
- const maxY = Math.round(radius * Math.max(...ys));
9729
+ const innerRadius = this.innerRadius();
9730
+ const outerRadius = this.outerRadius();
9731
+ const clockwise = this.clockwise();
9732
+ const angle = Konva$2.getAngle(clockwise ? 360 - this.angle() : this.angle());
9733
+ const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
9734
+ const boundRightRatio = 1;
9735
+ const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), 3 * Math.PI / 2));
9736
+ const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
9737
+ const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
9738
+ const boundRight = boundRightRatio * (outerRadius );
9739
+ const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
9740
+ const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
9742
9741
  return {
9743
- x: minX || 0,
9744
- y: minY || 0,
9745
- width: maxX - minX,
9746
- height: maxY - minY
9742
+ x: Math.round(boundLeft),
9743
+ y: Math.round(clockwise ? -1 * boundBottom : boundTop),
9744
+ width: Math.round(boundRight - boundLeft),
9745
+ height: Math.round(boundBottom - boundTop)
9747
9746
  };
9748
9747
  }
9749
9748
  }
@@ -11678,6 +11677,7 @@
11678
11677
  * @memberof Konva.Image
11679
11678
  * @param {String} url image source
11680
11679
  * @param {Function} callback with Konva.Image instance as first argument
11680
+ * @param {Function} onError optional error handler
11681
11681
  * @example
11682
11682
  * Konva.Image.fromURL(imageURL, function(image){
11683
11683
  * // image is Konva.Image instance
@@ -11685,7 +11685,7 @@
11685
11685
  * layer.draw();
11686
11686
  * });
11687
11687
  */
11688
- static fromURL(url, callback) {
11688
+ static fromURL(url, callback, onError = null) {
11689
11689
  var img = Util.createImageElement();
11690
11690
  img.onload = function () {
11691
11691
  var image = new Image({
@@ -11693,6 +11693,7 @@
11693
11693
  });
11694
11694
  callback(image);
11695
11695
  };
11696
+ img.onerror = onError;
11696
11697
  img.crossOrigin = 'Anonymous';
11697
11698
  img.src = url;
11698
11699
  }