konva 8.4.3 → 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 (190) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17669 -16989
  3. package/konva.min.js +3 -3
  4. package/lib/Animation.js +11 -7
  5. package/lib/BezierFunctions.d.ts +6 -0
  6. package/lib/BezierFunctions.js +791 -0
  7. package/lib/Canvas.d.ts +1 -0
  8. package/lib/Canvas.js +26 -18
  9. package/lib/Container.js +16 -12
  10. package/lib/Context.d.ts +3 -1
  11. package/lib/Context.js +18 -10
  12. package/lib/Core.js +7 -3
  13. package/lib/DragAndDrop.js +25 -22
  14. package/lib/Factory.js +27 -24
  15. package/lib/FastLayer.js +10 -6
  16. package/lib/Global.js +16 -12
  17. package/lib/Group.js +10 -6
  18. package/lib/Layer.js +37 -33
  19. package/lib/Node.js +95 -90
  20. package/lib/PointerEvents.js +15 -7
  21. package/lib/Shape.js +90 -86
  22. package/lib/Stage.js +51 -47
  23. package/lib/Tween.js +26 -22
  24. package/lib/Util.js +29 -25
  25. package/lib/Validators.js +58 -44
  26. package/lib/_CoreInternals.js +36 -33
  27. package/lib/_FullInternals.js +78 -75
  28. package/lib/filters/Blur.js +9 -5
  29. package/lib/filters/Brighten.js +9 -5
  30. package/lib/filters/Contrast.js +9 -5
  31. package/lib/filters/Emboss.js +14 -10
  32. package/lib/filters/Enhance.js +9 -5
  33. package/lib/filters/Grayscale.js +5 -1
  34. package/lib/filters/HSL.js +11 -7
  35. package/lib/filters/HSV.js +11 -7
  36. package/lib/filters/Invert.js +5 -1
  37. package/lib/filters/Kaleidoscope.js +13 -9
  38. package/lib/filters/Mask.js +9 -5
  39. package/lib/filters/Noise.js +9 -5
  40. package/lib/filters/Pixelate.js +11 -7
  41. package/lib/filters/Posterize.js +9 -5
  42. package/lib/filters/RGB.js +11 -7
  43. package/lib/filters/RGBA.js +12 -8
  44. package/lib/filters/Sepia.js +5 -1
  45. package/lib/filters/Solarize.js +5 -1
  46. package/lib/filters/Threshold.js +9 -5
  47. package/lib/index-node.js +7 -5
  48. package/lib/index.js +4 -2
  49. package/lib/shapes/Arc.js +17 -13
  50. package/lib/shapes/Arrow.js +17 -13
  51. package/lib/shapes/Circle.js +11 -7
  52. package/lib/shapes/Ellipse.js +13 -9
  53. package/lib/shapes/Image.js +21 -17
  54. package/lib/shapes/Label.js +18 -13
  55. package/lib/shapes/Line.js +14 -10
  56. package/lib/shapes/Path.d.ts +5 -2
  57. package/lib/shapes/Path.js +44 -43
  58. package/lib/shapes/Rect.js +13 -9
  59. package/lib/shapes/RegularPolygon.js +12 -8
  60. package/lib/shapes/Ring.js +12 -8
  61. package/lib/shapes/Sprite.js +19 -15
  62. package/lib/shapes/Star.js +13 -9
  63. package/lib/shapes/Text.js +31 -26
  64. package/lib/shapes/TextPath.d.ts +5 -1
  65. package/lib/shapes/TextPath.js +82 -188
  66. package/lib/shapes/Transformer.js +85 -81
  67. package/lib/shapes/Wedge.js +16 -12
  68. package/lib/types.d.ts +6 -0
  69. package/lib/types.js +5 -2
  70. package/package.json +13 -42
  71. package/cmj/Animation.d.ts +0 -24
  72. package/cmj/Animation.js +0 -145
  73. package/cmj/Canvas.d.ts +0 -32
  74. package/cmj/Canvas.js +0 -114
  75. package/cmj/Container.d.ts +0 -47
  76. package/cmj/Container.js +0 -325
  77. package/cmj/Context.d.ts +0 -85
  78. package/cmj/Context.js +0 -538
  79. package/cmj/Core.d.ts +0 -3
  80. package/cmj/Core.js +0 -7
  81. package/cmj/DragAndDrop.d.ts +0 -17
  82. package/cmj/DragAndDrop.js +0 -111
  83. package/cmj/Factory.d.ts +0 -11
  84. package/cmj/Factory.js +0 -125
  85. package/cmj/FastLayer.d.ts +0 -4
  86. package/cmj/FastLayer.js +0 -16
  87. package/cmj/Global.d.ts +0 -34
  88. package/cmj/Global.js +0 -61
  89. package/cmj/Group.d.ts +0 -8
  90. package/cmj/Group.js +0 -17
  91. package/cmj/Layer.d.ts +0 -61
  92. package/cmj/Layer.js +0 -309
  93. package/cmj/Node.d.ts +0 -328
  94. package/cmj/Node.js +0 -1420
  95. package/cmj/PointerEvents.d.ts +0 -11
  96. package/cmj/PointerEvents.js +0 -45
  97. package/cmj/Shape.d.ts +0 -186
  98. package/cmj/Shape.js +0 -521
  99. package/cmj/Stage.d.ts +0 -85
  100. package/cmj/Stage.js +0 -692
  101. package/cmj/Tween.d.ts +0 -86
  102. package/cmj/Tween.js +0 -520
  103. package/cmj/Util.d.ts +0 -91
  104. package/cmj/Util.js +0 -801
  105. package/cmj/Validators.d.ts +0 -11
  106. package/cmj/Validators.js +0 -192
  107. package/cmj/_CoreInternals.d.ts +0 -152
  108. package/cmj/_CoreInternals.js +0 -37
  109. package/cmj/_FullInternals.d.ts +0 -196
  110. package/cmj/_FullInternals.js +0 -81
  111. package/cmj/filters/Blur.d.ts +0 -2
  112. package/cmj/filters/Blur.js +0 -701
  113. package/cmj/filters/Brighten.d.ts +0 -2
  114. package/cmj/filters/Brighten.js +0 -16
  115. package/cmj/filters/Contrast.d.ts +0 -2
  116. package/cmj/filters/Contrast.js +0 -38
  117. package/cmj/filters/Emboss.d.ts +0 -2
  118. package/cmj/filters/Emboss.js +0 -106
  119. package/cmj/filters/Enhance.d.ts +0 -2
  120. package/cmj/filters/Enhance.js +0 -87
  121. package/cmj/filters/Grayscale.d.ts +0 -2
  122. package/cmj/filters/Grayscale.js +0 -13
  123. package/cmj/filters/HSL.d.ts +0 -2
  124. package/cmj/filters/HSL.js +0 -28
  125. package/cmj/filters/HSV.d.ts +0 -2
  126. package/cmj/filters/HSV.js +0 -28
  127. package/cmj/filters/Invert.d.ts +0 -2
  128. package/cmj/filters/Invert.js +0 -12
  129. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  130. package/cmj/filters/Kaleidoscope.js +0 -137
  131. package/cmj/filters/Mask.d.ts +0 -2
  132. package/cmj/filters/Mask.js +0 -144
  133. package/cmj/filters/Noise.d.ts +0 -2
  134. package/cmj/filters/Noise.js +0 -16
  135. package/cmj/filters/Pixelate.d.ts +0 -2
  136. package/cmj/filters/Pixelate.js +0 -64
  137. package/cmj/filters/Posterize.d.ts +0 -2
  138. package/cmj/filters/Posterize.js +0 -14
  139. package/cmj/filters/RGB.d.ts +0 -2
  140. package/cmj/filters/RGB.js +0 -43
  141. package/cmj/filters/RGBA.d.ts +0 -2
  142. package/cmj/filters/RGBA.js +0 -53
  143. package/cmj/filters/Sepia.d.ts +0 -2
  144. package/cmj/filters/Sepia.js +0 -15
  145. package/cmj/filters/Solarize.d.ts +0 -2
  146. package/cmj/filters/Solarize.js +0 -29
  147. package/cmj/filters/Threshold.d.ts +0 -2
  148. package/cmj/filters/Threshold.js +0 -14
  149. package/cmj/index-node.d.ts +0 -2
  150. package/cmj/index-node.js +0 -21
  151. package/cmj/index-types.d.ts +0 -181
  152. package/cmj/index.d.ts +0 -2
  153. package/cmj/index.js +0 -4
  154. package/cmj/package.json +0 -6
  155. package/cmj/shapes/Arc.d.ts +0 -26
  156. package/cmj/shapes/Arc.js +0 -59
  157. package/cmj/shapes/Arrow.d.ts +0 -26
  158. package/cmj/shapes/Arrow.js +0 -103
  159. package/cmj/shapes/Circle.d.ts +0 -14
  160. package/cmj/shapes/Circle.js +0 -37
  161. package/cmj/shapes/Ellipse.d.ts +0 -17
  162. package/cmj/shapes/Ellipse.js +0 -41
  163. package/cmj/shapes/Image.d.ts +0 -25
  164. package/cmj/shapes/Image.js +0 -117
  165. package/cmj/shapes/Label.d.ts +0 -36
  166. package/cmj/shapes/Label.js +0 -178
  167. package/cmj/shapes/Line.d.ts +0 -28
  168. package/cmj/shapes/Line.js +0 -159
  169. package/cmj/shapes/Path.d.ts +0 -37
  170. package/cmj/shapes/Path.js +0 -631
  171. package/cmj/shapes/Rect.d.ts +0 -10
  172. package/cmj/shapes/Rect.js +0 -26
  173. package/cmj/shapes/RegularPolygon.d.ts +0 -23
  174. package/cmj/shapes/RegularPolygon.js +0 -69
  175. package/cmj/shapes/Ring.d.ts +0 -16
  176. package/cmj/shapes/Ring.js +0 -37
  177. package/cmj/shapes/Sprite.d.ts +0 -31
  178. package/cmj/shapes/Sprite.js +0 -112
  179. package/cmj/shapes/Star.d.ts +0 -18
  180. package/cmj/shapes/Star.js +0 -42
  181. package/cmj/shapes/Text.d.ts +0 -63
  182. package/cmj/shapes/Text.js +0 -373
  183. package/cmj/shapes/TextPath.d.ts +0 -56
  184. package/cmj/shapes/TextPath.js +0 -351
  185. package/cmj/shapes/Transformer.d.ts +0 -116
  186. package/cmj/shapes/Transformer.js +0 -971
  187. package/cmj/shapes/Wedge.d.ts +0 -18
  188. package/cmj/shapes/Wedge.js +0 -42
  189. package/cmj/types.d.ts +0 -50
  190. package/cmj/types.js +0 -25
@@ -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,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,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,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,11 +1,15 @@
1
- import { Util } from '../Util.js';
2
- import { Factory } from '../Factory.js';
3
- import { Shape } from '../Shape.js';
4
- import { getNumberValidator, getStringValidator, getNumberOrAutoValidator, getBooleanValidator, } from '../Validators.js';
5
- import { _registerNode } from '../Global.js';
6
- export function stringToArray(string) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Text = exports.stringToArray = void 0;
4
+ const Util_1 = require("../Util");
5
+ const Factory_1 = require("../Factory");
6
+ const Shape_1 = require("../Shape");
7
+ const Validators_1 = require("../Validators");
8
+ const Global_1 = require("../Global");
9
+ function stringToArray(string) {
7
10
  return Array.from(string);
8
11
  }
12
+ exports.stringToArray = stringToArray;
9
13
  var AUTO = 'auto', CENTER = 'center', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
10
14
  'fontFamily',
11
15
  'fontSize',
@@ -41,7 +45,7 @@ function getDummyContext() {
41
45
  if (dummyContext) {
42
46
  return dummyContext;
43
47
  }
44
- dummyContext = Util.createCanvasElement().getContext(CONTEXT_2D);
48
+ dummyContext = Util_1.Util.createCanvasElement().getContext(CONTEXT_2D);
45
49
  return dummyContext;
46
50
  }
47
51
  function _fillFunc(context) {
@@ -59,7 +63,7 @@ function checkDefaultFill(config) {
59
63
  }
60
64
  return config;
61
65
  }
62
- export class Text extends Shape {
66
+ class Text extends Shape_1.Shape {
63
67
  constructor(config) {
64
68
  super(checkDefaultFill(config));
65
69
  this._partialTextX = 0;
@@ -167,7 +171,7 @@ export class Text extends Shape {
167
171
  context.fillStrokeShape(this);
168
172
  }
169
173
  setText(text) {
170
- var str = Util._isString(text)
174
+ var str = Util_1.Util._isString(text)
171
175
  ? text
172
176
  : text === null || text === undefined
173
177
  ? ''
@@ -190,7 +194,7 @@ export class Text extends Shape {
190
194
  return this.textWidth;
191
195
  }
192
196
  getTextHeight() {
193
- Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
197
+ Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
194
198
  return this.textHeight;
195
199
  }
196
200
  measureSize(text) {
@@ -339,6 +343,7 @@ export class Text extends Shape {
339
343
  return true;
340
344
  }
341
345
  }
346
+ exports.Text = Text;
342
347
  Text.prototype._fillFunc = _fillFunc;
343
348
  Text.prototype._strokeFunc = _strokeFunc;
344
349
  Text.prototype.className = TEXT_UPPER;
@@ -350,19 +355,19 @@ Text.prototype._attrsAffectingSize = [
350
355
  'lineHeight',
351
356
  'letterSpacing',
352
357
  ];
353
- _registerNode(Text);
354
- Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator());
355
- Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator());
356
- Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
357
- Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator());
358
- Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
359
- Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
360
- Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator());
361
- Factory.addGetterSetter(Text, 'align', LEFT);
362
- Factory.addGetterSetter(Text, 'verticalAlign', TOP);
363
- Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator());
364
- Factory.addGetterSetter(Text, 'wrap', WORD);
365
- Factory.addGetterSetter(Text, 'ellipsis', false, getBooleanValidator());
366
- Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
367
- Factory.addGetterSetter(Text, 'text', '', getStringValidator());
368
- Factory.addGetterSetter(Text, 'textDecoration', '');
358
+ (0, Global_1._registerNode)(Text);
359
+ Factory_1.Factory.overWriteSetter(Text, 'width', (0, Validators_1.getNumberOrAutoValidator)());
360
+ Factory_1.Factory.overWriteSetter(Text, 'height', (0, Validators_1.getNumberOrAutoValidator)());
361
+ Factory_1.Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
362
+ Factory_1.Factory.addGetterSetter(Text, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
363
+ Factory_1.Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
364
+ Factory_1.Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
365
+ Factory_1.Factory.addGetterSetter(Text, 'padding', 0, (0, Validators_1.getNumberValidator)());
366
+ Factory_1.Factory.addGetterSetter(Text, 'align', LEFT);
367
+ Factory_1.Factory.addGetterSetter(Text, 'verticalAlign', TOP);
368
+ Factory_1.Factory.addGetterSetter(Text, 'lineHeight', 1, (0, Validators_1.getNumberValidator)());
369
+ Factory_1.Factory.addGetterSetter(Text, 'wrap', WORD);
370
+ Factory_1.Factory.addGetterSetter(Text, 'ellipsis', false, (0, Validators_1.getBooleanValidator)());
371
+ Factory_1.Factory.addGetterSetter(Text, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
372
+ Factory_1.Factory.addGetterSetter(Text, 'text', '', (0, Validators_1.getStringValidator)());
373
+ Factory_1.Factory.addGetterSetter(Text, 'textDecoration', '');
@@ -21,9 +21,13 @@ export declare class TextPath extends Shape<TextPathConfig> {
21
21
  p1: Vector2d;
22
22
  }>;
23
23
  partialText: string;
24
+ pathLength: number;
24
25
  textWidth: number;
25
26
  textHeight: number;
26
27
  constructor(config?: TextPathConfig);
28
+ _getTextPathLength(): number;
29
+ _getPointAtLength(length: number): any;
30
+ _readDataAttribute(): void;
27
31
  _sceneFunc(context: Context): void;
28
32
  _hitFunc(context: Context): void;
29
33
  getTextWidth(): number;
@@ -34,7 +38,7 @@ export declare class TextPath extends Shape<TextPathConfig> {
34
38
  width: number;
35
39
  height: number;
36
40
  };
37
- _setTextData(): void;
41
+ _setTextData(): any;
38
42
  getSelfRect(): {
39
43
  x: number;
40
44
  y: number;
@@ -1,10 +1,13 @@
1
- import { Util } from '../Util.js';
2
- import { Factory } from '../Factory.js';
3
- import { Shape } from '../Shape.js';
4
- import { Path } from './Path.js';
5
- import { Text, stringToArray } from './Text.js';
6
- import { getNumberValidator } from '../Validators.js';
7
- import { _registerNode } from '../Global.js';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextPath = void 0;
4
+ const Util_1 = require("../Util");
5
+ const Factory_1 = require("../Factory");
6
+ const Shape_1 = require("../Shape");
7
+ const Path_1 = require("./Path");
8
+ const Text_1 = require("./Text");
9
+ const Validators_1 = require("../Validators");
10
+ const Global_1 = require("../Global");
8
11
  var EMPTY_STRING = '', NORMAL = 'normal';
9
12
  function _fillFunc(context) {
10
13
  context.fillText(this.partialText, 0, 0);
@@ -12,19 +15,36 @@ function _fillFunc(context) {
12
15
  function _strokeFunc(context) {
13
16
  context.strokeText(this.partialText, 0, 0);
14
17
  }
15
- export class TextPath extends Shape {
18
+ class TextPath extends Shape_1.Shape {
16
19
  constructor(config) {
17
20
  super(config);
18
- this.dummyCanvas = Util.createCanvasElement();
21
+ this.dummyCanvas = Util_1.Util.createCanvasElement();
19
22
  this.dataArray = [];
20
- this.dataArray = Path.parsePathData(this.attrs.data);
23
+ this._readDataAttribute();
21
24
  this.on('dataChange.konva', function () {
22
- this.dataArray = Path.parsePathData(this.attrs.data);
25
+ this._readDataAttribute();
23
26
  this._setTextData();
24
27
  });
25
28
  this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
26
29
  this._setTextData();
27
30
  }
31
+ _getTextPathLength() {
32
+ return Path_1.Path.getPathLength(this.dataArray);
33
+ }
34
+ _getPointAtLength(length) {
35
+ if (!this.attrs.data) {
36
+ return null;
37
+ }
38
+ const totalLength = this.pathLength;
39
+ if (length - 1 > totalLength) {
40
+ return null;
41
+ }
42
+ return Path_1.Path.getPointAtLengthOfDataArray(length, this.dataArray);
43
+ }
44
+ _readDataAttribute() {
45
+ this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
46
+ this.pathLength = this._getTextPathLength();
47
+ }
28
48
  _sceneFunc(context) {
29
49
  context.setAttr('font', this._getContextFont());
30
50
  context.setAttr('textBaseline', this.textBaseline());
@@ -78,14 +98,14 @@ export class TextPath extends Shape {
78
98
  return this.textWidth;
79
99
  }
80
100
  getTextHeight() {
81
- Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
101
+ Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
82
102
  return this.textHeight;
83
103
  }
84
104
  setText(text) {
85
- return Text.prototype.setText.call(this, text);
105
+ return Text_1.Text.prototype.setText.call(this, text);
86
106
  }
87
107
  _getContextFont() {
88
- return Text.prototype._getContextFont.call(this);
108
+ return Text_1.Text.prototype._getContextFont.call(this);
89
109
  }
90
110
  _getTextSize(text) {
91
111
  var dummyCanvas = this.dummyCanvas;
@@ -96,171 +116,44 @@ export class TextPath extends Shape {
96
116
  _context.restore();
97
117
  return {
98
118
  width: metrics.width,
99
- height: parseInt(this.attrs.fontSize, 10),
119
+ height: parseInt(`${this.fontSize()}`, 10),
100
120
  };
101
121
  }
102
122
  _setTextData() {
103
- var that = this;
104
- var size = this._getTextSize(this.attrs.text);
105
- var letterSpacing = this.letterSpacing();
106
- var align = this.align();
107
- var kerningFunc = this.kerningFunc();
108
- this.textWidth = size.width;
109
- this.textHeight = size.height;
110
- var textFullWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
123
+ const { width, height } = this._getTextSize(this.attrs.text);
124
+ this.textWidth = width;
125
+ this.textHeight = height;
111
126
  this.glyphInfo = [];
112
- var fullPathWidth = 0;
113
- for (var l = 0; l < that.dataArray.length; l++) {
114
- if (that.dataArray[l].pathLength > 0) {
115
- fullPathWidth += that.dataArray[l].pathLength;
116
- }
127
+ if (!this.attrs.data) {
128
+ return null;
117
129
  }
118
- var offset = 0;
130
+ const letterSpacing = this.letterSpacing();
131
+ const align = this.align();
132
+ const kerningFunc = this.kerningFunc();
133
+ const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
134
+ let offset = 0;
119
135
  if (align === 'center') {
120
- offset = Math.max(0, fullPathWidth / 2 - textFullWidth / 2);
136
+ offset = Math.max(0, this.pathLength / 2 - textWidth / 2);
121
137
  }
122
138
  if (align === 'right') {
123
- offset = Math.max(0, fullPathWidth - textFullWidth);
124
- }
125
- var charArr = stringToArray(this.text());
126
- var spacesNumber = this.text().split(' ').length - 1;
127
- var p0, p1, pathCmd;
128
- var pIndex = -1;
129
- var currentT = 0;
130
- var getNextPathSegment = function () {
131
- currentT = 0;
132
- var pathData = that.dataArray;
133
- for (var j = pIndex + 1; j < pathData.length; j++) {
134
- if (pathData[j].pathLength > 0) {
135
- pIndex = j;
136
- return pathData[j];
137
- }
138
- else if (pathData[j].command === 'M') {
139
- p0 = {
140
- x: pathData[j].points[0],
141
- y: pathData[j].points[1],
142
- };
143
- }
144
- }
145
- return {};
146
- };
147
- var findSegmentToFitCharacter = function (c) {
148
- var glyphWidth = that._getTextSize(c).width + letterSpacing;
149
- if (c === ' ' && align === 'justify') {
150
- glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
151
- }
152
- var currLen = 0;
153
- var attempts = 0;
154
- p1 = undefined;
155
- while (Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 &&
156
- attempts < 20) {
157
- attempts++;
158
- var cumulativePathLength = currLen;
159
- while (pathCmd === undefined) {
160
- pathCmd = getNextPathSegment();
161
- if (pathCmd &&
162
- cumulativePathLength + pathCmd.pathLength < glyphWidth) {
163
- cumulativePathLength += pathCmd.pathLength;
164
- pathCmd = undefined;
165
- }
166
- }
167
- if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
168
- return undefined;
169
- }
170
- var needNewSegment = false;
171
- switch (pathCmd.command) {
172
- case 'L':
173
- if (Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) {
174
- p1 = Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y);
175
- }
176
- else {
177
- pathCmd = undefined;
178
- }
179
- break;
180
- case 'A':
181
- var start = pathCmd.points[4];
182
- var dTheta = pathCmd.points[5];
183
- var end = pathCmd.points[4] + dTheta;
184
- if (currentT === 0) {
185
- currentT = start + 0.00000001;
186
- }
187
- else if (glyphWidth > currLen) {
188
- currentT += ((Math.PI / 180.0) * dTheta) / Math.abs(dTheta);
189
- }
190
- else {
191
- currentT -= ((Math.PI / 360.0) * dTheta) / Math.abs(dTheta);
192
- }
193
- if ((dTheta < 0 && currentT < end) ||
194
- (dTheta >= 0 && currentT > end)) {
195
- currentT = end;
196
- needNewSegment = true;
197
- }
198
- p1 = Path.getPointOnEllipticalArc(pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], currentT, pathCmd.points[6]);
199
- break;
200
- case 'C':
201
- if (currentT === 0) {
202
- if (glyphWidth > pathCmd.pathLength) {
203
- currentT = 0.00000001;
204
- }
205
- else {
206
- currentT = glyphWidth / pathCmd.pathLength;
207
- }
208
- }
209
- else if (glyphWidth > currLen) {
210
- currentT += (glyphWidth - currLen) / pathCmd.pathLength / 2;
211
- }
212
- else {
213
- currentT = Math.max(currentT - (currLen - glyphWidth) / pathCmd.pathLength / 2, 0);
214
- }
215
- if (currentT > 1.0) {
216
- currentT = 1.0;
217
- needNewSegment = true;
218
- }
219
- p1 = Path.getPointOnCubicBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], pathCmd.points[4], pathCmd.points[5]);
220
- break;
221
- case 'Q':
222
- if (currentT === 0) {
223
- currentT = glyphWidth / pathCmd.pathLength;
224
- }
225
- else if (glyphWidth > currLen) {
226
- currentT += (glyphWidth - currLen) / pathCmd.pathLength;
227
- }
228
- else {
229
- currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
230
- }
231
- if (currentT > 1.0) {
232
- currentT = 1.0;
233
- needNewSegment = true;
234
- }
235
- p1 = Path.getPointOnQuadraticBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3]);
236
- break;
237
- }
238
- if (p1 !== undefined) {
239
- currLen = Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
240
- }
241
- if (needNewSegment) {
242
- needNewSegment = false;
243
- pathCmd = undefined;
244
- }
245
- }
246
- };
247
- var testChar = 'C';
248
- var glyphWidth = that._getTextSize(testChar).width + letterSpacing;
249
- var lettersInOffset = offset / glyphWidth - 1;
250
- for (var k = 0; k < lettersInOffset; k++) {
251
- findSegmentToFitCharacter(testChar);
252
- if (p0 === undefined || p1 === undefined) {
253
- break;
254
- }
255
- p0 = p1;
139
+ offset = Math.max(0, this.pathLength - textWidth);
256
140
  }
141
+ const charArr = (0, Text_1.stringToArray)(this.text());
142
+ let offsetToGlyph = offset;
257
143
  for (var i = 0; i < charArr.length; i++) {
258
- findSegmentToFitCharacter(charArr[i]);
259
- if (p0 === undefined || p1 === undefined) {
260
- break;
144
+ const charStartPoint = this._getPointAtLength(offsetToGlyph);
145
+ if (!charStartPoint)
146
+ return;
147
+ let glyphWidth = this._getTextSize(charArr[i]).width + letterSpacing;
148
+ if (charArr[i] === ' ' && align === 'justify') {
149
+ const numberOfSpaces = this.text().split(' ').length - 1;
150
+ glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
261
151
  }
262
- var width = Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
263
- var kern = 0;
152
+ const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
153
+ if (!charEndPoint)
154
+ return;
155
+ const width = Path_1.Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
156
+ let kern = 0;
264
157
  if (kerningFunc) {
265
158
  try {
266
159
  kern = kerningFunc(charArr[i - 1], charArr[i]) * this.fontSize();
@@ -269,20 +162,20 @@ export class TextPath extends Shape {
269
162
  kern = 0;
270
163
  }
271
164
  }
272
- p0.x += kern;
273
- p1.x += kern;
165
+ charStartPoint.x += kern;
166
+ charEndPoint.x += kern;
274
167
  this.textWidth += kern;
275
- var midpoint = Path.getPointOnLine(kern + width / 2.0, p0.x, p0.y, p1.x, p1.y);
276
- var rotation = Math.atan2(p1.y - p0.y, p1.x - p0.x);
168
+ const midpoint = Path_1.Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
169
+ const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x);
277
170
  this.glyphInfo.push({
278
171
  transposeX: midpoint.x,
279
172
  transposeY: midpoint.y,
280
173
  text: charArr[i],
281
174
  rotation: rotation,
282
- p0: p0,
283
- p1: p1,
175
+ p0: charStartPoint,
176
+ p1: charEndPoint,
284
177
  });
285
- p0 = p1;
178
+ offsetToGlyph += glyphWidth;
286
179
  }
287
180
  }
288
181
  getSelfRect() {
@@ -323,25 +216,26 @@ export class TextPath extends Shape {
323
216
  };
324
217
  }
325
218
  destroy() {
326
- Util.releaseCanvas(this.dummyCanvas);
219
+ Util_1.Util.releaseCanvas(this.dummyCanvas);
327
220
  return super.destroy();
328
221
  }
329
222
  }
223
+ exports.TextPath = TextPath;
330
224
  TextPath.prototype._fillFunc = _fillFunc;
331
225
  TextPath.prototype._strokeFunc = _strokeFunc;
332
226
  TextPath.prototype._fillFuncHit = _fillFunc;
333
227
  TextPath.prototype._strokeFuncHit = _strokeFunc;
334
228
  TextPath.prototype.className = 'TextPath';
335
229
  TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
336
- _registerNode(TextPath);
337
- Factory.addGetterSetter(TextPath, 'data');
338
- Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
339
- Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
340
- Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
341
- Factory.addGetterSetter(TextPath, 'align', 'left');
342
- Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
343
- Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
344
- Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
345
- Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
346
- Factory.addGetterSetter(TextPath, 'textDecoration', null);
347
- Factory.addGetterSetter(TextPath, 'kerningFunc', null);
230
+ (0, Global_1._registerNode)(TextPath);
231
+ Factory_1.Factory.addGetterSetter(TextPath, 'data');
232
+ Factory_1.Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
233
+ Factory_1.Factory.addGetterSetter(TextPath, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
234
+ Factory_1.Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
235
+ Factory_1.Factory.addGetterSetter(TextPath, 'align', 'left');
236
+ Factory_1.Factory.addGetterSetter(TextPath, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
237
+ Factory_1.Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
238
+ Factory_1.Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
239
+ Factory_1.Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
240
+ Factory_1.Factory.addGetterSetter(TextPath, 'textDecoration', null);
241
+ Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', null);