konva 10.3.3 → 10.4.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.
Files changed (123) hide show
  1. package/README.md +1 -1
  2. package/konva.js +1327 -1572
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +692 -30
  28. package/lib/Node.js +1534 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +40 -6
  101. package/lib/shapes/Path.js +187 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +12 -16
@@ -1,8 +1,19 @@
1
+ /**
2
+ * Solarize Filter
3
+ * @function
4
+ * @name Solarize
5
+ * @memberof Konva.Filters
6
+ * @param {Object} imageData
7
+ * @example
8
+ * node.cache();
9
+ * node.filters([Konva.Filters.Solarize]);
10
+ */
1
11
  export const Solarize = function (imageData) {
2
12
  const threshold = 128;
3
13
  const d = imageData.data;
4
14
  for (let i = 0; i < d.length; i += 4) {
5
15
  const r = d[i], g = d[i + 1], b = d[i + 2];
16
+ // sRGB luma
6
17
  const L = 0.2126 * r + 0.7152 * g + 0.0722 * b;
7
18
  if (L >= threshold) {
8
19
  d[i] = 255 - r;
@@ -1,2 +1,24 @@
1
1
  import type { Filter } from '../Node.ts';
2
+ /**
3
+ * Threshold Filter. Pushes any value above the mid point to
4
+ * the max and any value below the mid point to the min.
5
+ * This affects the alpha channel.
6
+ * @function
7
+ * @name Threshold
8
+ * @memberof Konva.Filters
9
+ * @param {Object} imageData
10
+ * @author ippo615
11
+ * @example
12
+ * node.cache();
13
+ * node.filters([Konva.Filters.Threshold]);
14
+ * node.threshold(0.1);
15
+ */
2
16
  export declare const Threshold: Filter;
17
+ /**
18
+ * get/set threshold. With {@link Konva.Filters.Threshold} it is a value between 0 and 1. With {@link Konva.Filters.Mask} it is the colour distance to the background, 0 to 255, default 10.
19
+ * @name threshold
20
+ * @method
21
+ * @memberof Konva.Node.prototype
22
+ * @param {Number} threshold
23
+ * @returns {Number}
24
+ */
@@ -1,6 +1,20 @@
1
1
  import { Factory } from "../Factory.js";
2
2
  import { Node } from "../Node.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
+ /**
5
+ * Threshold Filter. Pushes any value above the mid point to
6
+ * the max and any value below the mid point to the min.
7
+ * This affects the alpha channel.
8
+ * @function
9
+ * @name Threshold
10
+ * @memberof Konva.Filters
11
+ * @param {Object} imageData
12
+ * @author ippo615
13
+ * @example
14
+ * node.cache();
15
+ * node.filters([Konva.Filters.Threshold]);
16
+ * node.threshold(0.1);
17
+ */
4
18
  export const Threshold = function (imageData) {
5
19
  const level = this.threshold() * 255, data = imageData.data, len = data.length;
6
20
  for (let i = 0; i < len; i += 1) {
@@ -8,3 +22,11 @@ export const Threshold = function (imageData) {
8
22
  }
9
23
  };
10
24
  Factory.addGetterSetter(Node, 'threshold', 0.5, getNumberValidator(), Factory.afterSetFilter);
25
+ /**
26
+ * get/set threshold. With {@link Konva.Filters.Threshold} it is a value between 0 and 1. With {@link Konva.Filters.Mask} it is the colour distance to the background, 0 to 255, default 10.
27
+ * @name threshold
28
+ * @method
29
+ * @memberof Konva.Node.prototype
30
+ * @param {Number} threshold
31
+ * @returns {Number}
32
+ */
@@ -8,6 +8,30 @@ export interface ArcConfig extends ShapeConfig {
8
8
  outerRadius: number;
9
9
  clockwise?: boolean;
10
10
  }
11
+ /**
12
+ * Arc constructor
13
+ * @constructor
14
+ * @memberof Konva
15
+ * @augments Konva.Shape
16
+ * @param {Object} config
17
+ * @param {Number} config.angle in degrees
18
+ * @param {Number} config.innerRadius
19
+ * @param {Number} config.outerRadius
20
+ * @param {Boolean} [config.clockwise]
21
+ * @@shapeParams
22
+ * @@nodeParams
23
+ * @example
24
+ * // draw a Arc that's pointing downwards
25
+ * var arc = new Konva.Arc({
26
+ * innerRadius: 40,
27
+ * outerRadius: 80,
28
+ * fill: 'red',
29
+ * stroke: 'black',
30
+ * strokeWidth: 5,
31
+ * angle: 60,
32
+ * rotation: -120
33
+ * });
34
+ */
11
35
  export declare class Arc extends Shape<ArcConfig> {
12
36
  _sceneFunc(context: Context): void;
13
37
  getWidth(): number;
@@ -25,3 +49,19 @@ export declare class Arc extends Shape<ArcConfig> {
25
49
  angle: GetSet<number, this>;
26
50
  clockwise: GetSet<boolean, this>;
27
51
  }
52
+ /**
53
+ * get/set clockwise flag
54
+ * @name Konva.Arc#clockwise
55
+ * @method
56
+ * @param {Boolean} clockwise
57
+ * @returns {Boolean}
58
+ * @example
59
+ * // get clockwise flag
60
+ * var clockwise = arc.clockwise();
61
+ *
62
+ * // draw arc counter-clockwise
63
+ * arc.clockwise(false);
64
+ *
65
+ * // draw arc clockwise
66
+ * arc.clockwise(true);
67
+ */
package/lib/shapes/Arc.js CHANGED
@@ -3,20 +3,44 @@ import { Shape } from "../Shape.js";
3
3
  import { Konva } from "../Global.js";
4
4
  import { getNumberValidator, getBooleanValidator } from "../Validators.js";
5
5
  import { _registerNode } from "../Global.js";
6
+ /**
7
+ * Arc constructor
8
+ * @constructor
9
+ * @memberof Konva
10
+ * @augments Konva.Shape
11
+ * @param {Object} config
12
+ * @param {Number} config.angle in degrees
13
+ * @param {Number} config.innerRadius
14
+ * @param {Number} config.outerRadius
15
+ * @param {Boolean} [config.clockwise]
16
+ * @@shapeParams
17
+ * @@nodeParams
18
+ * @example
19
+ * // draw a Arc that's pointing downwards
20
+ * var arc = new Konva.Arc({
21
+ * innerRadius: 40,
22
+ * outerRadius: 80,
23
+ * fill: 'red',
24
+ * stroke: 'black',
25
+ * strokeWidth: 5,
26
+ * angle: 60,
27
+ * rotation: -120
28
+ * });
29
+ */
6
30
  export class Arc extends Shape {
7
31
  _sceneFunc(context) {
8
32
  const angle = Konva.getAngle(this.angle()), clockwise = this.clockwise();
9
33
  context.beginPath();
10
- context.arc(0, 0, this.outerRadius(), 0, angle, clockwise);
11
- context.arc(0, 0, this.innerRadius(), angle, 0, !clockwise);
34
+ context.arc(0, 0, Math.abs(this.outerRadius()), 0, angle, clockwise);
35
+ context.arc(0, 0, Math.abs(this.innerRadius()), angle, 0, !clockwise);
12
36
  context.closePath();
13
37
  context.fillStrokeShape(this);
14
38
  }
15
39
  getWidth() {
16
- return this.outerRadius() * 2;
40
+ return Math.abs(this.outerRadius()) * 2;
17
41
  }
18
42
  getHeight() {
19
- return this.outerRadius() * 2;
43
+ return Math.abs(this.outerRadius()) * 2;
20
44
  }
21
45
  setWidth(width) {
22
46
  this.outerRadius(width / 2);
@@ -25,9 +49,12 @@ export class Arc extends Shape {
25
49
  this.outerRadius(height / 2);
26
50
  }
27
51
  getSelfRect() {
28
- const innerRadius = this.innerRadius();
29
- const outerRadius = this.outerRadius();
52
+ const innerRadius = Math.abs(this.innerRadius());
53
+ const outerRadius = Math.abs(this.outerRadius());
30
54
  const clockwise = this.clockwise();
55
+ // canvas draws a full circle for any non-zero full-turn end angle regardless
56
+ // of direction, and nothing for angle 0. The 360 - angle flip below maps both
57
+ // onto the same value, so handle exact full turns before the trig formula.
31
58
  const rawAngle = Konva.getAngle(this.angle());
32
59
  if (rawAngle % (Math.PI * 2) === 0) {
33
60
  return rawAngle !== 0
@@ -65,7 +92,63 @@ Arc.prototype._attrsAffectingSize = [
65
92
  'clockwise',
66
93
  ];
67
94
  _registerNode(Arc);
95
+ // add getters setters
68
96
  Factory.addGetterSetter(Arc, 'innerRadius', 0, getNumberValidator());
97
+ /**
98
+ * get/set innerRadius
99
+ * @name Konva.Arc#innerRadius
100
+ * @method
101
+ * @param {Number} innerRadius
102
+ * @returns {Number}
103
+ * @example
104
+ * // get inner radius
105
+ * var innerRadius = arc.innerRadius();
106
+ *
107
+ * // set inner radius
108
+ * arc.innerRadius(20);
109
+ */
69
110
  Factory.addGetterSetter(Arc, 'outerRadius', 0, getNumberValidator());
111
+ /**
112
+ * get/set outerRadius
113
+ * @name Konva.Arc#outerRadius
114
+ * @method
115
+ * @param {Number} outerRadius
116
+ * @returns {Number}
117
+ * @example
118
+ * // get outer radius
119
+ * var outerRadius = arc.outerRadius();
120
+ *
121
+ * // set outer radius
122
+ * arc.outerRadius(20);
123
+ */
70
124
  Factory.addGetterSetter(Arc, 'angle', 0, getNumberValidator());
125
+ /**
126
+ * get/set angle in degrees
127
+ * @name Konva.Arc#angle
128
+ * @method
129
+ * @param {Number} angle
130
+ * @returns {Number}
131
+ * @example
132
+ * // get angle
133
+ * var angle = arc.angle();
134
+ *
135
+ * // set angle
136
+ * arc.angle(20);
137
+ */
71
138
  Factory.addGetterSetter(Arc, 'clockwise', false, getBooleanValidator());
139
+ /**
140
+ * get/set clockwise flag
141
+ * @name Konva.Arc#clockwise
142
+ * @method
143
+ * @param {Boolean} clockwise
144
+ * @returns {Boolean}
145
+ * @example
146
+ * // get clockwise flag
147
+ * var clockwise = arc.clockwise();
148
+ *
149
+ * // draw arc counter-clockwise
150
+ * arc.clockwise(false);
151
+ *
152
+ * // draw arc clockwise
153
+ * arc.clockwise(true);
154
+ */
@@ -3,7 +3,6 @@ import { Line } from './Line.ts';
3
3
  import type { GetSet } from '../types.ts';
4
4
  import type { Context } from '../Context.ts';
5
5
  export interface ArrowConfig extends LineConfig {
6
- points: number[];
7
6
  tension?: number;
8
7
  closed?: boolean;
9
8
  pointerLength?: number;
@@ -11,6 +10,30 @@ export interface ArrowConfig extends LineConfig {
11
10
  pointerAtBeginning?: boolean;
12
11
  pointerAtEnding?: boolean;
13
12
  }
13
+ /**
14
+ * Arrow constructor
15
+ * @constructor
16
+ * @memberof Konva
17
+ * @augments Konva.Line
18
+ * @param {Object} config
19
+ * @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
20
+ * @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
21
+ * The default is 0
22
+ * @param {Number} config.pointerLength Arrow pointer length. Default value is 10.
23
+ * @param {Number} config.pointerWidth Arrow pointer width. Default value is 10.
24
+ * @param {Boolean} config.pointerAtBeginning Do we need to draw pointer on beginning position?. Default false.
25
+ * @param {Boolean} config.pointerAtEnding Do we need to draw pointer on ending position?. Default true.
26
+ * @@shapeParams
27
+ * @@nodeParams
28
+ * @example
29
+ * var line = new Konva.Line({
30
+ * points: [73, 70, 340, 23, 450, 60, 500, 20],
31
+ * stroke: 'red',
32
+ * tension: 1,
33
+ * pointerLength : 10,
34
+ * pointerWidth : 12
35
+ * });
36
+ */
14
37
  export declare class Arrow extends Line<ArrowConfig> {
15
38
  _sceneFunc(ctx: Context): void;
16
39
  __fillStroke(ctx: Context): void;
@@ -3,6 +3,30 @@ import { Line } from "./Line.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  import { _registerNode } from "../Global.js";
5
5
  import { Path } from "./Path.js";
6
+ /**
7
+ * Arrow constructor
8
+ * @constructor
9
+ * @memberof Konva
10
+ * @augments Konva.Line
11
+ * @param {Object} config
12
+ * @param {Array} config.points Flat array of points coordinates. You should define them as [x1, y1, x2, y2, x3, y3].
13
+ * @param {Number} [config.tension] Higher values will result in a more curvy line. A value of 0 will result in no interpolation.
14
+ * The default is 0
15
+ * @param {Number} config.pointerLength Arrow pointer length. Default value is 10.
16
+ * @param {Number} config.pointerWidth Arrow pointer width. Default value is 10.
17
+ * @param {Boolean} config.pointerAtBeginning Do we need to draw pointer on beginning position?. Default false.
18
+ * @param {Boolean} config.pointerAtEnding Do we need to draw pointer on ending position?. Default true.
19
+ * @@shapeParams
20
+ * @@nodeParams
21
+ * @example
22
+ * var line = new Konva.Line({
23
+ * points: [73, 70, 340, 23, 450, 60, 500, 20],
24
+ * stroke: 'red',
25
+ * tension: 1,
26
+ * pointerLength : 10,
27
+ * pointerWidth : 12
28
+ * });
29
+ */
6
30
  export class Arrow extends Line {
7
31
  _sceneFunc(ctx) {
8
32
  super._sceneFunc(ctx);
@@ -70,12 +94,18 @@ export class Arrow extends Line {
70
94
  }
71
95
  }
72
96
  __fillStroke(ctx) {
97
+ // here is a tricky part
98
+ // we need to disable dash for arrow pointers
73
99
  const isDashEnabled = this.dashEnabled();
74
100
  if (isDashEnabled) {
101
+ // manually disable dash for head
102
+ // it is better not to use setter here,
103
+ // because it will trigger attr change event
75
104
  this.attrs.dashEnabled = false;
76
105
  ctx.setLineDash([]);
77
106
  }
78
107
  ctx.fillStrokeShape(this);
108
+ // restore old value
79
109
  if (isDashEnabled) {
80
110
  this.attrs.dashEnabled = true;
81
111
  }
@@ -93,7 +123,60 @@ export class Arrow extends Line {
93
123
  }
94
124
  Arrow.prototype.className = 'Arrow';
95
125
  _registerNode(Arrow);
126
+ /**
127
+ * get/set pointerLength
128
+ * @name Konva.Arrow#pointerLength
129
+ * @method
130
+ * @param {Number} Length of pointer of arrow. The default is 10.
131
+ * @returns {Number}
132
+ * @example
133
+ * // get length
134
+ * var pointerLength = line.pointerLength();
135
+ *
136
+ * // set length
137
+ * line.pointerLength(15);
138
+ */
96
139
  Factory.addGetterSetter(Arrow, 'pointerLength', 10, getNumberValidator());
140
+ /**
141
+ * get/set pointerWidth
142
+ * @name Konva.Arrow#pointerWidth
143
+ * @method
144
+ * @param {Number} Width of pointer of arrow.
145
+ * The default is 10.
146
+ * @returns {Number}
147
+ * @example
148
+ * // get width
149
+ * var pointerWidth = line.pointerWidth();
150
+ *
151
+ * // set width
152
+ * line.pointerWidth(15);
153
+ */
97
154
  Factory.addGetterSetter(Arrow, 'pointerWidth', 10, getNumberValidator());
155
+ /**
156
+ * get/set pointerAtBeginning
157
+ * @name Konva.Arrow#pointerAtBeginning
158
+ * @method
159
+ * @param {Number} Should pointer displayed at beginning of arrow. The default is false.
160
+ * @returns {Boolean}
161
+ * @example
162
+ * // get value
163
+ * var pointerAtBeginning = line.pointerAtBeginning();
164
+ *
165
+ * // set value
166
+ * line.pointerAtBeginning(true);
167
+ */
98
168
  Factory.addGetterSetter(Arrow, 'pointerAtBeginning', false);
169
+ /**
170
+ * get/set pointerAtEnding
171
+ * @name Konva.Arrow#pointerAtEnding
172
+ * @method
173
+ * @param {Number} Should pointer displayed at ending of arrow. The default is true.
174
+ * @returns {Boolean}
175
+ * @example
176
+ * // get value
177
+ * var pointerAtEnding = line.pointerAtEnding();
178
+ *
179
+ * // set value
180
+ * line.pointerAtEnding(false);
181
+ */
99
182
  Factory.addGetterSetter(Arrow, 'pointerAtEnding', true);
@@ -5,6 +5,24 @@ import type { Context } from '../Context.ts';
5
5
  export interface CircleConfig extends ShapeConfig {
6
6
  radius?: number;
7
7
  }
8
+ /**
9
+ * Circle constructor
10
+ * @constructor
11
+ * @memberof Konva
12
+ * @augments Konva.Shape
13
+ * @param {Object} config
14
+ * @param {Number} config.radius
15
+ * @@shapeParams
16
+ * @@nodeParams
17
+ * @example
18
+ * // create circle
19
+ * var circle = new Konva.Circle({
20
+ * radius: 40,
21
+ * fill: 'red',
22
+ * stroke: 'black',
23
+ * strokeWidth: 5
24
+ * });
25
+ */
8
26
  export declare class Circle extends Shape<CircleConfig> {
9
27
  _sceneFunc(context: Context): void;
10
28
  getWidth(): number;
@@ -2,32 +2,59 @@ import { Factory } from "../Factory.js";
2
2
  import { Shape } from "../Shape.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  import { _registerNode } from "../Global.js";
5
+ /**
6
+ * Circle constructor
7
+ * @constructor
8
+ * @memberof Konva
9
+ * @augments Konva.Shape
10
+ * @param {Object} config
11
+ * @param {Number} config.radius
12
+ * @@shapeParams
13
+ * @@nodeParams
14
+ * @example
15
+ * // create circle
16
+ * var circle = new Konva.Circle({
17
+ * radius: 40,
18
+ * fill: 'red',
19
+ * stroke: 'black',
20
+ * strokeWidth: 5
21
+ * });
22
+ */
5
23
  export class Circle extends Shape {
6
24
  _sceneFunc(context) {
7
25
  context.beginPath();
8
- context.arc(0, 0, this.attrs.radius || 0, 0, Math.PI * 2, false);
26
+ context.arc(0, 0, Math.abs(this.attrs.radius || 0), 0, Math.PI * 2, false);
9
27
  context.closePath();
10
28
  context.fillStrokeShape(this);
11
29
  }
12
30
  getWidth() {
13
- return this.radius() * 2;
31
+ return Math.abs(this.radius()) * 2;
14
32
  }
15
33
  getHeight() {
16
- return this.radius() * 2;
34
+ return Math.abs(this.radius()) * 2;
17
35
  }
18
36
  setWidth(width) {
19
- if (this.radius() !== width / 2) {
20
- this.radius(width / 2);
21
- }
37
+ this.radius(width / 2);
22
38
  }
23
39
  setHeight(height) {
24
- if (this.radius() !== height / 2) {
25
- this.radius(height / 2);
26
- }
40
+ this.radius(height / 2);
27
41
  }
28
42
  }
29
43
  Circle.prototype._centroid = true;
30
44
  Circle.prototype.className = 'Circle';
31
45
  Circle.prototype._attrsAffectingSize = ['radius'];
32
46
  _registerNode(Circle);
47
+ /**
48
+ * get/set radius
49
+ * @name Konva.Circle#radius
50
+ * @method
51
+ * @param {Number} radius
52
+ * @returns {Number}
53
+ * @example
54
+ * // get radius
55
+ * var radius = circle.radius();
56
+ *
57
+ * // set radius
58
+ * circle.radius(10);
59
+ */
33
60
  Factory.addGetterSetter(Circle, 'radius', 0, getNumberValidator());
@@ -3,9 +3,28 @@ import { Shape } from '../Shape.ts';
3
3
  import type { Context } from '../Context.ts';
4
4
  import type { GetSet, Vector2d } from '../types.ts';
5
5
  export interface EllipseConfig extends ShapeConfig {
6
- radiusX: number;
7
- radiusY: number;
6
+ radius?: Vector2d;
7
+ radiusX?: number;
8
+ radiusY?: number;
8
9
  }
10
+ /**
11
+ * Ellipse constructor
12
+ * @constructor
13
+ * @memberof Konva
14
+ * @augments Konva.Shape
15
+ * @param {Object} config
16
+ * @param {Object} config.radius defines x and y radius
17
+ * @@shapeParams
18
+ * @@nodeParams
19
+ * @example
20
+ * var ellipse = new Konva.Ellipse({
21
+ * radius : {
22
+ * x : 50,
23
+ * y : 50
24
+ * },
25
+ * fill: 'red'
26
+ * });
27
+ */
9
28
  export declare class Ellipse extends Shape<EllipseConfig> {
10
29
  _sceneFunc(context: Context): void;
11
30
  getWidth(): number;
@@ -16,3 +35,16 @@ export declare class Ellipse extends Shape<EllipseConfig> {
16
35
  radiusX: GetSet<number, this>;
17
36
  radiusY: GetSet<number, this>;
18
37
  }
38
+ /**
39
+ * get/set radius y
40
+ * @name Konva.Ellipse#radiusY
41
+ * @method
42
+ * @param {Number} y
43
+ * @returns {Number}
44
+ * @example
45
+ * // get radius y
46
+ * var radiusY = ellipse.radiusY();
47
+ *
48
+ * // set radius y
49
+ * ellipse.radiusY(200);
50
+ */
@@ -2,24 +2,37 @@ import { Factory } from "../Factory.js";
2
2
  import { Shape } from "../Shape.js";
3
3
  import { getNumberValidator } from "../Validators.js";
4
4
  import { _registerNode } from "../Global.js";
5
+ /**
6
+ * Ellipse constructor
7
+ * @constructor
8
+ * @memberof Konva
9
+ * @augments Konva.Shape
10
+ * @param {Object} config
11
+ * @param {Object} config.radius defines x and y radius
12
+ * @@shapeParams
13
+ * @@nodeParams
14
+ * @example
15
+ * var ellipse = new Konva.Ellipse({
16
+ * radius : {
17
+ * x : 50,
18
+ * y : 50
19
+ * },
20
+ * fill: 'red'
21
+ * });
22
+ */
5
23
  export class Ellipse extends Shape {
6
24
  _sceneFunc(context) {
7
- const rx = this.radiusX(), ry = this.radiusY();
25
+ const rx = Math.abs(this.radiusX()), ry = Math.abs(this.radiusY());
8
26
  context.beginPath();
9
- context.save();
10
- if (rx !== ry) {
11
- context.scale(1, ry / rx);
12
- }
13
- context.arc(0, 0, rx, 0, Math.PI * 2, false);
14
- context.restore();
27
+ context.ellipse(0, 0, rx, ry, 0, 0, Math.PI * 2, false);
15
28
  context.closePath();
16
29
  context.fillStrokeShape(this);
17
30
  }
18
31
  getWidth() {
19
- return this.radiusX() * 2;
32
+ return Math.abs(this.radiusX()) * 2;
20
33
  }
21
34
  getHeight() {
22
- return this.radiusY() * 2;
35
+ return Math.abs(this.radiusY()) * 2;
23
36
  }
24
37
  setWidth(width) {
25
38
  this.radiusX(width / 2);
@@ -32,6 +45,51 @@ Ellipse.prototype.className = 'Ellipse';
32
45
  Ellipse.prototype._centroid = true;
33
46
  Ellipse.prototype._attrsAffectingSize = ['radiusX', 'radiusY'];
34
47
  _registerNode(Ellipse);
48
+ // add getters setters
35
49
  Factory.addComponentsGetterSetter(Ellipse, 'radius', ['x', 'y']);
50
+ /**
51
+ * get/set radius
52
+ * @name Konva.Ellipse#radius
53
+ * @method
54
+ * @param {Object} radius
55
+ * @param {Number} radius.x
56
+ * @param {Number} radius.y
57
+ * @returns {Object}
58
+ * @example
59
+ * // get radius
60
+ * var radius = ellipse.radius();
61
+ *
62
+ * // set radius
63
+ * ellipse.radius({
64
+ * x: 200,
65
+ * y: 100
66
+ * });
67
+ */
36
68
  Factory.addGetterSetter(Ellipse, 'radiusX', 0, getNumberValidator());
69
+ /**
70
+ * get/set radius x
71
+ * @name Konva.Ellipse#radiusX
72
+ * @method
73
+ * @param {Number} x
74
+ * @returns {Number}
75
+ * @example
76
+ * // get radius x
77
+ * var radiusX = ellipse.radiusX();
78
+ *
79
+ * // set radius x
80
+ * ellipse.radiusX(200);
81
+ */
37
82
  Factory.addGetterSetter(Ellipse, 'radiusY', 0, getNumberValidator());
83
+ /**
84
+ * get/set radius y
85
+ * @name Konva.Ellipse#radiusY
86
+ * @method
87
+ * @param {Number} y
88
+ * @returns {Number}
89
+ * @example
90
+ * // get radius y
91
+ * var radiusY = ellipse.radiusY();
92
+ *
93
+ * // set radius y
94
+ * ellipse.radiusY(200);
95
+ */