konva 8.4.2 → 9.0.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 (242) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16968
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +11 -7
  6. package/lib/BezierFunctions.d.ts +6 -0
  7. package/lib/BezierFunctions.js +791 -0
  8. package/lib/Canvas.d.ts +2 -1
  9. package/lib/Canvas.js +26 -18
  10. package/lib/Container.d.ts +4 -4
  11. package/lib/Container.js +16 -12
  12. package/lib/Context.d.ts +16 -13
  13. package/lib/Context.js +27 -19
  14. package/lib/Core.d.ts +2 -2
  15. package/lib/Core.js +7 -3
  16. package/lib/DragAndDrop.d.ts +3 -3
  17. package/lib/DragAndDrop.js +25 -22
  18. package/lib/Factory.js +27 -24
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +10 -6
  21. package/lib/Global.js +16 -12
  22. package/lib/Group.d.ts +3 -3
  23. package/lib/Group.js +10 -6
  24. package/lib/Layer.d.ts +9 -9
  25. package/lib/Layer.js +37 -33
  26. package/lib/Node.d.ts +8 -8
  27. package/lib/Node.js +95 -90
  28. package/lib/PointerEvents.d.ts +4 -4
  29. package/lib/PointerEvents.js +15 -7
  30. package/lib/Shape.d.ts +6 -4
  31. package/lib/Shape.js +90 -86
  32. package/lib/Stage.d.ts +7 -7
  33. package/lib/Stage.js +51 -47
  34. package/lib/Tween.d.ts +2 -2
  35. package/lib/Tween.js +26 -22
  36. package/lib/Util.d.ts +2 -2
  37. package/lib/Util.js +29 -25
  38. package/lib/Validators.js +58 -44
  39. package/lib/_CoreInternals.d.ts +29 -29
  40. package/lib/_CoreInternals.js +36 -33
  41. package/lib/_FullInternals.d.ts +67 -67
  42. package/lib/_FullInternals.js +78 -75
  43. package/lib/filters/Blur.d.ts +1 -1
  44. package/lib/filters/Blur.js +9 -5
  45. package/lib/filters/Brighten.d.ts +1 -1
  46. package/lib/filters/Brighten.js +9 -5
  47. package/lib/filters/Contrast.d.ts +1 -1
  48. package/lib/filters/Contrast.js +9 -5
  49. package/lib/filters/Emboss.d.ts +1 -1
  50. package/lib/filters/Emboss.js +14 -10
  51. package/lib/filters/Enhance.d.ts +1 -1
  52. package/lib/filters/Enhance.js +9 -5
  53. package/lib/filters/Grayscale.d.ts +1 -1
  54. package/lib/filters/Grayscale.js +5 -1
  55. package/lib/filters/HSL.d.ts +1 -1
  56. package/lib/filters/HSL.js +11 -7
  57. package/lib/filters/HSV.d.ts +1 -1
  58. package/lib/filters/HSV.js +11 -7
  59. package/lib/filters/Invert.d.ts +1 -1
  60. package/lib/filters/Invert.js +5 -1
  61. package/lib/filters/Kaleidoscope.d.ts +1 -1
  62. package/lib/filters/Kaleidoscope.js +13 -9
  63. package/lib/filters/Mask.d.ts +1 -1
  64. package/lib/filters/Mask.js +9 -5
  65. package/lib/filters/Noise.d.ts +1 -1
  66. package/lib/filters/Noise.js +9 -5
  67. package/lib/filters/Pixelate.d.ts +1 -1
  68. package/lib/filters/Pixelate.js +11 -7
  69. package/lib/filters/Posterize.d.ts +1 -1
  70. package/lib/filters/Posterize.js +9 -5
  71. package/lib/filters/RGB.d.ts +1 -1
  72. package/lib/filters/RGB.js +11 -7
  73. package/lib/filters/RGBA.d.ts +1 -1
  74. package/lib/filters/RGBA.js +12 -8
  75. package/lib/filters/Sepia.d.ts +1 -1
  76. package/lib/filters/Sepia.js +5 -1
  77. package/lib/filters/Solarize.d.ts +1 -1
  78. package/lib/filters/Solarize.js +5 -1
  79. package/lib/filters/Threshold.d.ts +1 -1
  80. package/lib/filters/Threshold.js +9 -5
  81. package/lib/index-node.d.ts +1 -1
  82. package/lib/index-node.js +7 -5
  83. package/lib/index-types.d.ts +124 -124
  84. package/lib/index.d.ts +1 -1
  85. package/lib/index.js +4 -2
  86. package/lib/shapes/Arc.d.ts +6 -5
  87. package/lib/shapes/Arc.js +17 -13
  88. package/lib/shapes/Arrow.d.ts +5 -4
  89. package/lib/shapes/Arrow.js +17 -13
  90. package/lib/shapes/Circle.d.ts +6 -5
  91. package/lib/shapes/Circle.js +11 -7
  92. package/lib/shapes/Ellipse.d.ts +6 -5
  93. package/lib/shapes/Ellipse.js +13 -9
  94. package/lib/shapes/Image.d.ts +5 -5
  95. package/lib/shapes/Image.js +21 -17
  96. package/lib/shapes/Label.d.ts +8 -7
  97. package/lib/shapes/Label.js +18 -13
  98. package/lib/shapes/Line.d.ts +3 -3
  99. package/lib/shapes/Line.js +14 -10
  100. package/lib/shapes/Path.d.ts +6 -3
  101. package/lib/shapes/Path.js +44 -43
  102. package/lib/shapes/Rect.d.ts +3 -3
  103. package/lib/shapes/Rect.js +13 -9
  104. package/lib/shapes/RegularPolygon.d.ts +6 -5
  105. package/lib/shapes/RegularPolygon.js +12 -8
  106. package/lib/shapes/Ring.d.ts +6 -5
  107. package/lib/shapes/Ring.js +12 -8
  108. package/lib/shapes/Sprite.d.ts +7 -6
  109. package/lib/shapes/Sprite.js +19 -15
  110. package/lib/shapes/Star.d.ts +6 -5
  111. package/lib/shapes/Star.js +13 -9
  112. package/lib/shapes/Text.d.ts +8 -7
  113. package/lib/shapes/Text.js +31 -26
  114. package/lib/shapes/TextPath.d.ts +12 -7
  115. package/lib/shapes/TextPath.js +82 -188
  116. package/lib/shapes/Transformer.d.ts +10 -10
  117. package/lib/shapes/Transformer.js +92 -81
  118. package/lib/shapes/Wedge.d.ts +6 -5
  119. package/lib/shapes/Wedge.js +16 -12
  120. package/lib/types.d.ts +6 -0
  121. package/lib/types.js +5 -2
  122. package/package.json +13 -42
  123. package/cmj/Animation.d.ts +0 -24
  124. package/cmj/Animation.js +0 -145
  125. package/cmj/Canvas.d.ts +0 -32
  126. package/cmj/Canvas.js +0 -114
  127. package/cmj/Container.d.ts +0 -47
  128. package/cmj/Container.js +0 -325
  129. package/cmj/Context.d.ts +0 -84
  130. package/cmj/Context.js +0 -538
  131. package/cmj/Core.d.ts +0 -3
  132. package/cmj/Core.js +0 -7
  133. package/cmj/DragAndDrop.d.ts +0 -17
  134. package/cmj/DragAndDrop.js +0 -111
  135. package/cmj/Factory.d.ts +0 -11
  136. package/cmj/Factory.js +0 -125
  137. package/cmj/FastLayer.d.ts +0 -4
  138. package/cmj/FastLayer.js +0 -16
  139. package/cmj/Global.d.ts +0 -34
  140. package/cmj/Global.js +0 -61
  141. package/cmj/Group.d.ts +0 -8
  142. package/cmj/Group.js +0 -17
  143. package/cmj/Layer.d.ts +0 -61
  144. package/cmj/Layer.js +0 -309
  145. package/cmj/Node.d.ts +0 -328
  146. package/cmj/Node.js +0 -1420
  147. package/cmj/PointerEvents.d.ts +0 -11
  148. package/cmj/PointerEvents.js +0 -45
  149. package/cmj/Shape.d.ts +0 -184
  150. package/cmj/Shape.js +0 -521
  151. package/cmj/Stage.d.ts +0 -85
  152. package/cmj/Stage.js +0 -692
  153. package/cmj/Tween.d.ts +0 -86
  154. package/cmj/Tween.js +0 -520
  155. package/cmj/Util.d.ts +0 -91
  156. package/cmj/Util.js +0 -801
  157. package/cmj/Validators.d.ts +0 -11
  158. package/cmj/Validators.js +0 -192
  159. package/cmj/_CoreInternals.d.ts +0 -152
  160. package/cmj/_CoreInternals.js +0 -37
  161. package/cmj/_FullInternals.d.ts +0 -196
  162. package/cmj/_FullInternals.js +0 -81
  163. package/cmj/filters/Blur.d.ts +0 -2
  164. package/cmj/filters/Blur.js +0 -701
  165. package/cmj/filters/Brighten.d.ts +0 -2
  166. package/cmj/filters/Brighten.js +0 -16
  167. package/cmj/filters/Contrast.d.ts +0 -2
  168. package/cmj/filters/Contrast.js +0 -38
  169. package/cmj/filters/Emboss.d.ts +0 -2
  170. package/cmj/filters/Emboss.js +0 -106
  171. package/cmj/filters/Enhance.d.ts +0 -2
  172. package/cmj/filters/Enhance.js +0 -87
  173. package/cmj/filters/Grayscale.d.ts +0 -2
  174. package/cmj/filters/Grayscale.js +0 -13
  175. package/cmj/filters/HSL.d.ts +0 -2
  176. package/cmj/filters/HSL.js +0 -28
  177. package/cmj/filters/HSV.d.ts +0 -2
  178. package/cmj/filters/HSV.js +0 -28
  179. package/cmj/filters/Invert.d.ts +0 -2
  180. package/cmj/filters/Invert.js +0 -12
  181. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  182. package/cmj/filters/Kaleidoscope.js +0 -137
  183. package/cmj/filters/Mask.d.ts +0 -2
  184. package/cmj/filters/Mask.js +0 -144
  185. package/cmj/filters/Noise.d.ts +0 -2
  186. package/cmj/filters/Noise.js +0 -16
  187. package/cmj/filters/Pixelate.d.ts +0 -2
  188. package/cmj/filters/Pixelate.js +0 -64
  189. package/cmj/filters/Posterize.d.ts +0 -2
  190. package/cmj/filters/Posterize.js +0 -14
  191. package/cmj/filters/RGB.d.ts +0 -2
  192. package/cmj/filters/RGB.js +0 -43
  193. package/cmj/filters/RGBA.d.ts +0 -2
  194. package/cmj/filters/RGBA.js +0 -53
  195. package/cmj/filters/Sepia.d.ts +0 -2
  196. package/cmj/filters/Sepia.js +0 -15
  197. package/cmj/filters/Solarize.d.ts +0 -2
  198. package/cmj/filters/Solarize.js +0 -29
  199. package/cmj/filters/Threshold.d.ts +0 -2
  200. package/cmj/filters/Threshold.js +0 -14
  201. package/cmj/index-node.d.ts +0 -2
  202. package/cmj/index-node.js +0 -21
  203. package/cmj/index-types.d.ts +0 -181
  204. package/cmj/index.d.ts +0 -2
  205. package/cmj/index.js +0 -4
  206. package/cmj/package.json +0 -6
  207. package/cmj/shapes/Arc.d.ts +0 -25
  208. package/cmj/shapes/Arc.js +0 -59
  209. package/cmj/shapes/Arrow.d.ts +0 -25
  210. package/cmj/shapes/Arrow.js +0 -103
  211. package/cmj/shapes/Circle.d.ts +0 -13
  212. package/cmj/shapes/Circle.js +0 -37
  213. package/cmj/shapes/Ellipse.d.ts +0 -16
  214. package/cmj/shapes/Ellipse.js +0 -41
  215. package/cmj/shapes/Image.d.ts +0 -25
  216. package/cmj/shapes/Image.js +0 -117
  217. package/cmj/shapes/Label.d.ts +0 -35
  218. package/cmj/shapes/Label.js +0 -178
  219. package/cmj/shapes/Line.d.ts +0 -28
  220. package/cmj/shapes/Line.js +0 -159
  221. package/cmj/shapes/Path.d.ts +0 -37
  222. package/cmj/shapes/Path.js +0 -631
  223. package/cmj/shapes/Rect.d.ts +0 -10
  224. package/cmj/shapes/Rect.js +0 -26
  225. package/cmj/shapes/RegularPolygon.d.ts +0 -22
  226. package/cmj/shapes/RegularPolygon.js +0 -69
  227. package/cmj/shapes/Ring.d.ts +0 -15
  228. package/cmj/shapes/Ring.js +0 -37
  229. package/cmj/shapes/Sprite.d.ts +0 -30
  230. package/cmj/shapes/Sprite.js +0 -112
  231. package/cmj/shapes/Star.d.ts +0 -17
  232. package/cmj/shapes/Star.js +0 -42
  233. package/cmj/shapes/Text.d.ts +0 -62
  234. package/cmj/shapes/Text.js +0 -373
  235. package/cmj/shapes/TextPath.d.ts +0 -55
  236. package/cmj/shapes/TextPath.js +0 -351
  237. package/cmj/shapes/Transformer.d.ts +0 -116
  238. package/cmj/shapes/Transformer.js +0 -964
  239. package/cmj/shapes/Wedge.d.ts +0 -17
  240. package/cmj/shapes/Wedge.js +0 -42
  241. package/cmj/types.d.ts +0 -50
  242. package/cmj/types.js +0 -25
@@ -1,12 +1,13 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { Group } from '../Group';
3
- import { ContainerConfig } from '../Container';
4
- import { GetSet } from '../types';
5
- import { Text } from './Text';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { Group } from '../Group.js';
3
+ import { Context } from '../Context.js';
4
+ import { ContainerConfig } from '../Container.js';
5
+ import { GetSet } from '../types.js';
6
+ import { Text } from './Text.js';
6
7
  export interface LabelConfig extends ContainerConfig {
7
8
  }
8
9
  export declare class Label extends Group {
9
- constructor(config?: any);
10
+ constructor(config?: LabelConfig);
10
11
  getText(): Text;
11
12
  getTag(): Tag;
12
13
  _addListeners(text: any): void;
@@ -21,7 +22,7 @@ export interface TagConfig extends ShapeConfig {
21
22
  cornerRadius?: number | Array<number>;
22
23
  }
23
24
  export declare class Tag extends Shape<TagConfig> {
24
- _sceneFunc(context: any): void;
25
+ _sceneFunc(context: Context): void;
25
26
  getSelfRect(): {
26
27
  x: number;
27
28
  y: number;
@@ -1,8 +1,11 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { Group } from '../Group.js';
4
- import { getNumberOrArrayOfNumbersValidator, getNumberValidator, } from '../Validators.js';
5
- import { _registerNode } from '../Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tag = exports.Label = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Group_1 = require("../Group");
7
+ const Validators_1 = require("../Validators");
8
+ const Global_1 = require("../Global");
6
9
  var ATTR_CHANGE_LIST = [
7
10
  'fontFamily',
8
11
  'fontSize',
@@ -16,7 +19,7 @@ var ATTR_CHANGE_LIST = [
16
19
  'pointerWidth',
17
20
  'pointerHeight',
18
21
  ], CHANGE_KONVA = 'Change.konva', NONE = 'none', UP = 'up', RIGHT = 'right', DOWN = 'down', LEFT = 'left', attrChangeListLen = ATTR_CHANGE_LIST.length;
19
- export class Label extends Group {
22
+ class Label extends Group_1.Group {
20
23
  constructor(config) {
21
24
  super(config);
22
25
  this.on('add.konva', function (evt) {
@@ -86,9 +89,10 @@ export class Label extends Group {
86
89
  }
87
90
  }
88
91
  }
92
+ exports.Label = Label;
89
93
  Label.prototype.className = 'Label';
90
- _registerNode(Label);
91
- export class Tag extends Shape {
94
+ (0, Global_1._registerNode)(Label);
95
+ class Tag extends Shape_1.Shape {
92
96
  _sceneFunc(context) {
93
97
  var width = this.width(), height = this.height(), pointerDirection = this.pointerDirection(), pointerWidth = this.pointerWidth(), pointerHeight = this.pointerHeight(), cornerRadius = this.cornerRadius();
94
98
  let topLeft = 0;
@@ -165,9 +169,10 @@ export class Tag extends Shape {
165
169
  };
166
170
  }
167
171
  }
172
+ exports.Tag = Tag;
168
173
  Tag.prototype.className = 'Tag';
169
- _registerNode(Tag);
170
- Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
171
- Factory.addGetterSetter(Tag, 'pointerWidth', 0, getNumberValidator());
172
- Factory.addGetterSetter(Tag, 'pointerHeight', 0, getNumberValidator());
173
- Factory.addGetterSetter(Tag, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
174
+ (0, Global_1._registerNode)(Tag);
175
+ Factory_1.Factory.addGetterSetter(Tag, 'pointerDirection', NONE);
176
+ Factory_1.Factory.addGetterSetter(Tag, 'pointerWidth', 0, (0, Validators_1.getNumberValidator)());
177
+ Factory_1.Factory.addGetterSetter(Tag, 'pointerHeight', 0, (0, Validators_1.getNumberValidator)());
178
+ Factory_1.Factory.addGetterSetter(Tag, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
@@ -1,6 +1,6 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
3
- import { Context } from '../Context';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { GetSet } from '../types.js';
3
+ import { Context } from '../Context.js';
4
4
  export interface LineConfig extends ShapeConfig {
5
5
  points?: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
6
6
  tension?: number;
@@ -1,7 +1,10 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { getNumberValidator, getNumberArrayValidator } from '../Validators.js';
4
- import { _registerNode } from '../Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Line = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Validators_1 = require("../Validators");
7
+ const Global_1 = require("../Global");
5
8
  function getControlPoints(x0, y0, x1, y1, x2, y2, t) {
6
9
  var d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2)), d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)), fa = (t * d01) / (d01 + d12), fb = (t * d12) / (d01 + d12), p1x = x1 - fa * (x2 - x0), p1y = y1 - fa * (y2 - y0), p2x = x1 + fb * (x2 - x0), p2y = y1 + fb * (y2 - y0);
7
10
  return [p1x, p1y, p2x, p2y];
@@ -22,7 +25,7 @@ function expandPoints(p, tension) {
22
25
  }
23
26
  return allPoints;
24
27
  }
25
- export class Line extends Shape {
28
+ class Line extends Shape_1.Shape {
26
29
  constructor(config) {
27
30
  super(config);
28
31
  this.on('pointsChange.konva tensionChange.konva closedChange.konva bezierChange.konva', function () {
@@ -146,10 +149,11 @@ export class Line extends Shape {
146
149
  };
147
150
  }
148
151
  }
152
+ exports.Line = Line;
149
153
  Line.prototype.className = 'Line';
150
154
  Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
151
- _registerNode(Line);
152
- Factory.addGetterSetter(Line, 'closed', false);
153
- Factory.addGetterSetter(Line, 'bezier', false);
154
- Factory.addGetterSetter(Line, 'tension', 0, getNumberValidator());
155
- Factory.addGetterSetter(Line, 'points', [], getNumberArrayValidator());
155
+ (0, Global_1._registerNode)(Line);
156
+ Factory_1.Factory.addGetterSetter(Line, 'closed', false);
157
+ Factory_1.Factory.addGetterSetter(Line, 'bezier', false);
158
+ Factory_1.Factory.addGetterSetter(Line, 'tension', 0, (0, Validators_1.getNumberValidator)());
159
+ Factory_1.Factory.addGetterSetter(Line, 'points', [], (0, Validators_1.getNumberArrayValidator)());
@@ -1,5 +1,5 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { GetSet, PathSegment } from '../types.js';
3
3
  export interface PathConfig extends ShapeConfig {
4
4
  data?: string;
5
5
  }
@@ -7,6 +7,7 @@ export declare class Path extends Shape<PathConfig> {
7
7
  dataArray: any[];
8
8
  pathLength: number;
9
9
  constructor(config?: PathConfig);
10
+ _readDataAttribute(): void;
10
11
  _sceneFunc(context: any): void;
11
12
  getSelfRect(): {
12
13
  x: any;
@@ -18,6 +19,8 @@ export declare class Path extends Shape<PathConfig> {
18
19
  getPointAtLength(length: any): any;
19
20
  data: GetSet<string, this>;
20
21
  static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
22
+ static getPathLength(dataArray: PathSegment[]): number;
23
+ static getPointAtLengthOfDataArray(length: number, dataArray: any): any;
21
24
  static getPointOnLine(dist: any, P1x: any, P1y: any, P2x: any, P2y: any, fromX?: any, fromY?: any): any;
22
25
  static getPointOnCubicBezier(pct: any, P1x: any, P1y: any, P2x: any, P2y: any, P3x: any, P3y: any, P4x: any, P4y: any): {
23
26
  x: number;
@@ -31,7 +34,7 @@ export declare class Path extends Shape<PathConfig> {
31
34
  x: any;
32
35
  y: any;
33
36
  };
34
- static parsePathData(data: any): any[];
37
+ static parsePathData(data: any): PathSegment[];
35
38
  static calcLength(x: any, y: any, cmd: any, points: any): any;
36
39
  static convertEndpointToCenterParameterization(x1: any, y1: any, x2: any, y2: any, fa: any, fs: any, rx: any, ry: any, psiDeg: any): any[];
37
40
  }
@@ -1,24 +1,24 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { _registerNode } from '../Global.js';
4
- export class Path extends Shape {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Path = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Global_1 = require("../Global");
7
+ const BezierFunctions_1 = require("../BezierFunctions");
8
+ class Path extends Shape_1.Shape {
5
9
  constructor(config) {
6
10
  super(config);
7
11
  this.dataArray = [];
8
12
  this.pathLength = 0;
9
- this.dataArray = Path.parsePathData(this.data());
10
- this.pathLength = 0;
11
- for (var i = 0; i < this.dataArray.length; ++i) {
12
- this.pathLength += this.dataArray[i].pathLength;
13
- }
13
+ this._readDataAttribute();
14
14
  this.on('dataChange.konva', function () {
15
- this.dataArray = Path.parsePathData(this.data());
16
- this.pathLength = 0;
17
- for (var i = 0; i < this.dataArray.length; ++i) {
18
- this.pathLength += this.dataArray[i].pathLength;
19
- }
15
+ this._readDataAttribute();
20
16
  });
21
17
  }
18
+ _readDataAttribute() {
19
+ this.dataArray = Path.parsePathData(this.data());
20
+ this.pathLength = Path.getPathLength(this.dataArray);
21
+ }
22
22
  _sceneFunc(context) {
23
23
  var ca = this.dataArray;
24
24
  context.beginPath();
@@ -127,37 +127,54 @@ export class Path extends Shape {
127
127
  return this.pathLength;
128
128
  }
129
129
  getPointAtLength(length) {
130
- var point, i = 0, ii = this.dataArray.length;
130
+ return Path.getPointAtLengthOfDataArray(length, this.dataArray);
131
+ }
132
+ static getLineLength(x1, y1, x2, y2) {
133
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
134
+ }
135
+ static getPathLength(dataArray) {
136
+ let pathLength = 0;
137
+ for (var i = 0; i < dataArray.length; ++i) {
138
+ pathLength += dataArray[i].pathLength;
139
+ }
140
+ return pathLength;
141
+ }
142
+ static getPointAtLengthOfDataArray(length, dataArray) {
143
+ var point, i = 0, ii = dataArray.length;
131
144
  if (!ii) {
132
145
  return null;
133
146
  }
134
- while (i < ii && length > this.dataArray[i].pathLength) {
135
- length -= this.dataArray[i].pathLength;
147
+ while (i < ii && length > dataArray[i].pathLength) {
148
+ length -= dataArray[i].pathLength;
136
149
  ++i;
137
150
  }
138
151
  if (i === ii) {
139
- point = this.dataArray[i - 1].points.slice(-2);
152
+ point = dataArray[i - 1].points.slice(-2);
140
153
  return {
141
154
  x: point[0],
142
155
  y: point[1],
143
156
  };
144
157
  }
145
158
  if (length < 0.01) {
146
- point = this.dataArray[i].points.slice(0, 2);
159
+ point = dataArray[i].points.slice(0, 2);
147
160
  return {
148
161
  x: point[0],
149
162
  y: point[1],
150
163
  };
151
164
  }
152
- var cp = this.dataArray[i];
165
+ var cp = dataArray[i];
153
166
  var p = cp.points;
154
167
  switch (cp.command) {
155
168
  case 'L':
156
169
  return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
157
170
  case 'C':
158
- return Path.getPointOnCubicBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3], p[4], p[5]);
171
+ return Path.getPointOnCubicBezier((0, BezierFunctions_1.t2length)(length, Path.getPathLength(dataArray), (i) => {
172
+ return (0, BezierFunctions_1.getCubicArcLength)([cp.start.x, p[0], p[2], p[4]], [cp.start.y, p[1], p[3], p[5]], i);
173
+ }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3], p[4], p[5]);
159
174
  case 'Q':
160
- return Path.getPointOnQuadraticBezier(length / cp.pathLength, cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
175
+ return Path.getPointOnQuadraticBezier((0, BezierFunctions_1.t2length)(length, Path.getPathLength(dataArray), (i) => {
176
+ return (0, BezierFunctions_1.getQuadraticArcLength)([cp.start.x, p[0], p[2]], [cp.start.y, p[1], p[3]], i);
177
+ }), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
161
178
  case 'A':
162
179
  var cx = p[0], cy = p[1], rx = p[2], ry = p[3], theta = p[4], dTheta = p[5], psi = p[6];
163
180
  theta += (dTheta * length) / cp.pathLength;
@@ -165,9 +182,6 @@ export class Path extends Shape {
165
182
  }
166
183
  return null;
167
184
  }
168
- static getLineLength(x1, y1, x2, y2) {
169
- return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
170
- }
171
185
  static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
172
186
  if (fromX === undefined) {
173
187
  fromX = P1x;
@@ -524,23 +538,9 @@ export class Path extends Shape {
524
538
  case 'L':
525
539
  return path.getLineLength(x, y, points[0], points[1]);
526
540
  case 'C':
527
- len = 0.0;
528
- p1 = path.getPointOnCubicBezier(0, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
529
- for (t = 0.01; t <= 1; t += 0.01) {
530
- p2 = path.getPointOnCubicBezier(t, x, y, points[0], points[1], points[2], points[3], points[4], points[5]);
531
- len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
532
- p1 = p2;
533
- }
534
- return len;
541
+ return (0, BezierFunctions_1.getCubicArcLength)([x, points[0], points[2], points[4]], [y, points[1], points[3], points[5]], 1);
535
542
  case 'Q':
536
- len = 0.0;
537
- p1 = path.getPointOnQuadraticBezier(0, x, y, points[0], points[1], points[2], points[3]);
538
- for (t = 0.01; t <= 1; t += 0.01) {
539
- p2 = path.getPointOnQuadraticBezier(t, x, y, points[0], points[1], points[2], points[3]);
540
- len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
541
- p1 = p2;
542
- }
543
- return len;
543
+ return (0, BezierFunctions_1.getQuadraticArcLength)([x, points[0], points[2]], [y, points[1], points[3]], 1);
544
544
  case 'A':
545
545
  len = 0.0;
546
546
  var start = points[4];
@@ -621,7 +621,8 @@ export class Path extends Shape {
621
621
  return [cx, cy, rx, ry, theta, dTheta, psi, fs];
622
622
  }
623
623
  }
624
+ exports.Path = Path;
624
625
  Path.prototype.className = 'Path';
625
626
  Path.prototype._attrsAffectingSize = ['data'];
626
- _registerNode(Path);
627
- Factory.addGetterSetter(Path, 'data');
627
+ (0, Global_1._registerNode)(Path);
628
+ Factory_1.Factory.addGetterSetter(Path, 'data');
@@ -1,6 +1,6 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
3
- import { Context } from '../Context';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { GetSet } from '../types.js';
3
+ import { Context } from '../Context.js';
4
4
  export interface RectConfig extends ShapeConfig {
5
5
  cornerRadius?: number | number[];
6
6
  }
@@ -1,9 +1,12 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { _registerNode } from '../Global.js';
4
- import { Util } from '../Util.js';
5
- import { getNumberOrArrayOfNumbersValidator } from '../Validators.js';
6
- export class Rect extends Shape {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Rect = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Global_1 = require("../Global");
7
+ const Util_1 = require("../Util");
8
+ const Validators_1 = require("../Validators");
9
+ class Rect extends Shape_1.Shape {
7
10
  _sceneFunc(context) {
8
11
  var cornerRadius = this.cornerRadius(), width = this.width(), height = this.height();
9
12
  context.beginPath();
@@ -11,12 +14,13 @@ export class Rect extends Shape {
11
14
  context.rect(0, 0, width, height);
12
15
  }
13
16
  else {
14
- Util.drawRoundedRectPath(context, width, height, cornerRadius);
17
+ Util_1.Util.drawRoundedRectPath(context, width, height, cornerRadius);
15
18
  }
16
19
  context.closePath();
17
20
  context.fillStrokeShape(this);
18
21
  }
19
22
  }
23
+ exports.Rect = Rect;
20
24
  Rect.prototype.className = 'Rect';
21
- _registerNode(Rect);
22
- Factory.addGetterSetter(Rect, 'cornerRadius', 0, getNumberOrArrayOfNumbersValidator(4));
25
+ (0, Global_1._registerNode)(Rect);
26
+ Factory_1.Factory.addGetterSetter(Rect, 'cornerRadius', 0, (0, Validators_1.getNumberOrArrayOfNumbersValidator)(4));
@@ -1,11 +1,12 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { GetSet } from '../types.js';
3
+ import { Context } from '../Context.js';
3
4
  export interface RegularPolygonConfig extends ShapeConfig {
4
5
  sides: number;
5
6
  radius: number;
6
7
  }
7
8
  export declare class RegularPolygon extends Shape<RegularPolygonConfig> {
8
- _sceneFunc(context: any): void;
9
+ _sceneFunc(context: Context): void;
9
10
  _getPoints(): any[];
10
11
  getSelfRect(): {
11
12
  x: any;
@@ -15,8 +16,8 @@ export declare class RegularPolygon extends Shape<RegularPolygonConfig> {
15
16
  };
16
17
  getWidth(): number;
17
18
  getHeight(): number;
18
- setWidth(width: any): void;
19
- setHeight(height: any): void;
19
+ setWidth(width: number): void;
20
+ setHeight(height: number): void;
20
21
  radius: GetSet<number, this>;
21
22
  sides: GetSet<number, this>;
22
23
  }
@@ -1,8 +1,11 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { getNumberValidator } from '../Validators.js';
4
- import { _registerNode } from '../Global.js';
5
- export class RegularPolygon extends Shape {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RegularPolygon = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Validators_1 = require("../Validators");
7
+ const Global_1 = require("../Global");
8
+ class RegularPolygon extends Shape_1.Shape {
6
9
  _sceneFunc(context) {
7
10
  const points = this._getPoints();
8
11
  context.beginPath();
@@ -57,9 +60,10 @@ export class RegularPolygon extends Shape {
57
60
  this.radius(height / 2);
58
61
  }
59
62
  }
63
+ exports.RegularPolygon = RegularPolygon;
60
64
  RegularPolygon.prototype.className = 'RegularPolygon';
61
65
  RegularPolygon.prototype._centroid = true;
62
66
  RegularPolygon.prototype._attrsAffectingSize = ['radius'];
63
- _registerNode(RegularPolygon);
64
- Factory.addGetterSetter(RegularPolygon, 'radius', 0, getNumberValidator());
65
- Factory.addGetterSetter(RegularPolygon, 'sides', 0, getNumberValidator());
67
+ (0, Global_1._registerNode)(RegularPolygon);
68
+ Factory_1.Factory.addGetterSetter(RegularPolygon, 'radius', 0, (0, Validators_1.getNumberValidator)());
69
+ Factory_1.Factory.addGetterSetter(RegularPolygon, 'sides', 0, (0, Validators_1.getNumberValidator)());
@@ -1,15 +1,16 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
1
+ import { Shape, ShapeConfig } from '../Shape.js';
2
+ import { GetSet } from '../types.js';
3
+ import { Context } from '../Context.js';
3
4
  export interface RingConfig extends ShapeConfig {
4
5
  innerRadius: number;
5
6
  outerRadius: number;
6
7
  }
7
8
  export declare class Ring extends Shape<RingConfig> {
8
- _sceneFunc(context: any): void;
9
+ _sceneFunc(context: Context): void;
9
10
  getWidth(): number;
10
11
  getHeight(): number;
11
- setWidth(width: any): void;
12
- setHeight(height: any): void;
12
+ setWidth(width: number): void;
13
+ setHeight(height: number): void;
13
14
  outerRadius: GetSet<number, this>;
14
15
  innerRadius: GetSet<number, this>;
15
16
  }
@@ -1,9 +1,12 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { getNumberValidator } from '../Validators.js';
4
- import { _registerNode } from '../Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ring = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Validators_1 = require("../Validators");
7
+ const Global_1 = require("../Global");
5
8
  var PIx2 = Math.PI * 2;
6
- export class Ring extends Shape {
9
+ class Ring extends Shape_1.Shape {
7
10
  _sceneFunc(context) {
8
11
  context.beginPath();
9
12
  context.arc(0, 0, this.innerRadius(), 0, PIx2, false);
@@ -25,9 +28,10 @@ export class Ring extends Shape {
25
28
  this.outerRadius(height / 2);
26
29
  }
27
30
  }
31
+ exports.Ring = Ring;
28
32
  Ring.prototype.className = 'Ring';
29
33
  Ring.prototype._centroid = true;
30
34
  Ring.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
31
- _registerNode(Ring);
32
- Factory.addGetterSetter(Ring, 'innerRadius', 0, getNumberValidator());
33
- Factory.addGetterSetter(Ring, 'outerRadius', 0, getNumberValidator());
35
+ (0, Global_1._registerNode)(Ring);
36
+ Factory_1.Factory.addGetterSetter(Ring, 'innerRadius', 0, (0, Validators_1.getNumberValidator)());
37
+ Factory_1.Factory.addGetterSetter(Ring, 'outerRadius', 0, (0, Validators_1.getNumberValidator)());
@@ -1,6 +1,7 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { Animation } from '../Animation';
3
- import { GetSet } from '../types';
1
+ import { Context } from '../Context.js';
2
+ import { Shape, ShapeConfig } from '../Shape.js';
3
+ import { Animation } from '../Animation.js';
4
+ import { GetSet } from '../types.js';
4
5
  export interface SpriteConfig extends ShapeConfig {
5
6
  animation: string;
6
7
  animations: any;
@@ -12,9 +13,9 @@ export declare class Sprite extends Shape<SpriteConfig> {
12
13
  _updated: boolean;
13
14
  anim: Animation;
14
15
  interval: any;
15
- constructor(config: any);
16
- _sceneFunc(context: any): void;
17
- _hitFunc(context: any): void;
16
+ constructor(config: SpriteConfig);
17
+ _sceneFunc(context: Context): void;
18
+ _hitFunc(context: Context): void;
18
19
  _useBufferCanvas(): boolean;
19
20
  _setInterval(): void;
20
21
  start(): void;
@@ -1,13 +1,16 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { Animation } from '../Animation.js';
4
- import { getNumberValidator } from '../Validators.js';
5
- import { _registerNode } from '../Global.js';
6
- export class Sprite extends Shape {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Sprite = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Animation_1 = require("../Animation");
7
+ const Validators_1 = require("../Validators");
8
+ const Global_1 = require("../Global");
9
+ class Sprite extends Shape_1.Shape {
7
10
  constructor(config) {
8
11
  super(config);
9
12
  this._updated = true;
10
- this.anim = new Animation(() => {
13
+ this.anim = new Animation_1.Animation(() => {
11
14
  var updated = this._updated;
12
15
  this._updated = false;
13
16
  return updated;
@@ -93,15 +96,16 @@ export class Sprite extends Shape {
93
96
  }
94
97
  }
95
98
  }
99
+ exports.Sprite = Sprite;
96
100
  Sprite.prototype.className = 'Sprite';
97
- _registerNode(Sprite);
98
- Factory.addGetterSetter(Sprite, 'animation');
99
- Factory.addGetterSetter(Sprite, 'animations');
100
- Factory.addGetterSetter(Sprite, 'frameOffsets');
101
- Factory.addGetterSetter(Sprite, 'image');
102
- Factory.addGetterSetter(Sprite, 'frameIndex', 0, getNumberValidator());
103
- Factory.addGetterSetter(Sprite, 'frameRate', 17, getNumberValidator());
104
- Factory.backCompat(Sprite, {
101
+ (0, Global_1._registerNode)(Sprite);
102
+ Factory_1.Factory.addGetterSetter(Sprite, 'animation');
103
+ Factory_1.Factory.addGetterSetter(Sprite, 'animations');
104
+ Factory_1.Factory.addGetterSetter(Sprite, 'frameOffsets');
105
+ Factory_1.Factory.addGetterSetter(Sprite, 'image');
106
+ Factory_1.Factory.addGetterSetter(Sprite, 'frameIndex', 0, (0, Validators_1.getNumberValidator)());
107
+ Factory_1.Factory.addGetterSetter(Sprite, 'frameRate', 17, (0, Validators_1.getNumberValidator)());
108
+ Factory_1.Factory.backCompat(Sprite, {
105
109
  index: 'frameIndex',
106
110
  getIndex: 'getFrameIndex',
107
111
  setIndex: 'setFrameIndex',
@@ -1,16 +1,17 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
1
+ import { Context } from '../Context.js';
2
+ import { Shape, ShapeConfig } from '../Shape.js';
3
+ import { GetSet } from '../types.js';
3
4
  export interface StarConfig extends ShapeConfig {
4
5
  numPoints: number;
5
6
  innerRadius: number;
6
7
  outerRadius: number;
7
8
  }
8
9
  export declare class Star extends Shape<StarConfig> {
9
- _sceneFunc(context: any): void;
10
+ _sceneFunc(context: Context): void;
10
11
  getWidth(): number;
11
12
  getHeight(): number;
12
- setWidth(width: any): void;
13
- setHeight(height: any): void;
13
+ setWidth(width: number): void;
14
+ setHeight(height: number): void;
14
15
  outerRadius: GetSet<number, this>;
15
16
  innerRadius: GetSet<number, this>;
16
17
  numPoints: GetSet<number, this>;
@@ -1,8 +1,11 @@
1
- import { Factory } from '../Factory.js';
2
- import { Shape } from '../Shape.js';
3
- import { getNumberValidator } from '../Validators.js';
4
- import { _registerNode } from '../Global.js';
5
- export class Star extends Shape {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Star = void 0;
4
+ const Factory_1 = require("../Factory");
5
+ const Shape_1 = require("../Shape");
6
+ const Validators_1 = require("../Validators");
7
+ const Global_1 = require("../Global");
8
+ class Star extends Shape_1.Shape {
6
9
  _sceneFunc(context) {
7
10
  var innerRadius = this.innerRadius(), outerRadius = this.outerRadius(), numPoints = this.numPoints();
8
11
  context.beginPath();
@@ -29,10 +32,11 @@ export class Star extends Shape {
29
32
  this.outerRadius(height / 2);
30
33
  }
31
34
  }
35
+ exports.Star = Star;
32
36
  Star.prototype.className = 'Star';
33
37
  Star.prototype._centroid = true;
34
38
  Star.prototype._attrsAffectingSize = ['innerRadius', 'outerRadius'];
35
- _registerNode(Star);
36
- Factory.addGetterSetter(Star, 'numPoints', 5, getNumberValidator());
37
- Factory.addGetterSetter(Star, 'innerRadius', 0, getNumberValidator());
38
- Factory.addGetterSetter(Star, 'outerRadius', 0, getNumberValidator());
39
+ (0, Global_1._registerNode)(Star);
40
+ Factory_1.Factory.addGetterSetter(Star, 'numPoints', 5, (0, Validators_1.getNumberValidator)());
41
+ Factory_1.Factory.addGetterSetter(Star, 'innerRadius', 0, (0, Validators_1.getNumberValidator)());
42
+ Factory_1.Factory.addGetterSetter(Star, 'outerRadius', 0, (0, Validators_1.getNumberValidator)());
@@ -1,5 +1,6 @@
1
- import { Shape, ShapeConfig } from '../Shape';
2
- import { GetSet } from '../types';
1
+ import { Context } from '../Context.js';
2
+ import { Shape, ShapeConfig } from '../Shape.js';
3
+ import { GetSet } from '../types.js';
3
4
  export declare function stringToArray(string: string): string[];
4
5
  export interface TextConfig extends ShapeConfig {
5
6
  text?: string;
@@ -28,9 +29,9 @@ export declare class Text extends Shape<TextConfig> {
28
29
  textWidth: number;
29
30
  textHeight: number;
30
31
  constructor(config?: TextConfig);
31
- _sceneFunc(context: any): void;
32
- _hitFunc(context: any): void;
33
- setText(text: any): this;
32
+ _sceneFunc(context: Context): void;
33
+ _hitFunc(context: Context): void;
34
+ setText(text: string): this;
34
35
  getWidth(): any;
35
36
  getHeight(): any;
36
37
  getTextWidth(): number;
@@ -40,8 +41,8 @@ export declare class Text extends Shape<TextConfig> {
40
41
  height: number;
41
42
  };
42
43
  _getContextFont(): string;
43
- _addTextLine(line: any): number;
44
- _getTextWidth(text: any): any;
44
+ _addTextLine(line: string): number;
45
+ _getTextWidth(text: string): number;
45
46
  _setTextData(): void;
46
47
  _shouldHandleEllipsis(currentHeightPx: number): boolean;
47
48
  _tryToAddEllipsisToLastLine(): void;