konva 9.3.21 → 10.0.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 (129) hide show
  1. package/README.md +1 -1
  2. package/konva.js +664 -226
  3. package/konva.min.js +46 -4
  4. package/lib/Animation.d.ts +2 -2
  5. package/lib/Animation.js +7 -11
  6. package/lib/BezierFunctions.js +9 -15
  7. package/lib/Canvas.d.ts +1 -1
  8. package/lib/Canvas.js +14 -20
  9. package/lib/Container.d.ts +7 -6
  10. package/lib/Container.js +12 -16
  11. package/lib/Context.d.ts +7 -5
  12. package/lib/Context.js +34 -14
  13. package/lib/Core.d.ts +2 -2
  14. package/lib/Core.js +3 -7
  15. package/lib/DragAndDrop.d.ts +3 -3
  16. package/lib/DragAndDrop.js +24 -27
  17. package/lib/Factory.d.ts +2 -2
  18. package/lib/Factory.js +24 -27
  19. package/lib/FastLayer.d.ts +1 -1
  20. package/lib/FastLayer.js +6 -10
  21. package/lib/Global.d.ts +4 -3
  22. package/lib/Global.js +19 -19
  23. package/lib/Group.d.ts +4 -3
  24. package/lib/Group.js +6 -10
  25. package/lib/Layer.d.ts +10 -9
  26. package/lib/Layer.js +33 -37
  27. package/lib/Node.d.ts +16 -13
  28. package/lib/Node.js +207 -123
  29. package/lib/PointerEvents.d.ts +4 -4
  30. package/lib/PointerEvents.js +7 -14
  31. package/lib/Shape.d.ts +7 -4
  32. package/lib/Shape.js +91 -91
  33. package/lib/Stage.d.ts +8 -7
  34. package/lib/Stage.js +66 -56
  35. package/lib/Tween.d.ts +3 -2
  36. package/lib/Tween.js +29 -31
  37. package/lib/Util.d.ts +3 -2
  38. package/lib/Util.js +98 -38
  39. package/lib/Validators.js +44 -57
  40. package/lib/_CoreInternals.d.ts +49 -23
  41. package/lib/_CoreInternals.js +33 -36
  42. package/lib/_FullInternals.d.ts +126 -62
  43. package/lib/_FullInternals.js +77 -78
  44. package/lib/canvas-backend.d.ts +2 -0
  45. package/lib/canvas-backend.js +27 -0
  46. package/lib/filters/Blur.d.ts +1 -1
  47. package/lib/filters/Blur.js +5 -9
  48. package/lib/filters/Brighten.d.ts +1 -1
  49. package/lib/filters/Brighten.js +5 -9
  50. package/lib/filters/Brightness.d.ts +2 -0
  51. package/lib/filters/Brightness.js +8 -0
  52. package/lib/filters/Contrast.d.ts +1 -1
  53. package/lib/filters/Contrast.js +5 -9
  54. package/lib/filters/Emboss.d.ts +1 -1
  55. package/lib/filters/Emboss.js +95 -101
  56. package/lib/filters/Enhance.d.ts +1 -1
  57. package/lib/filters/Enhance.js +5 -9
  58. package/lib/filters/Grayscale.d.ts +1 -1
  59. package/lib/filters/Grayscale.js +1 -5
  60. package/lib/filters/HSL.d.ts +1 -1
  61. package/lib/filters/HSL.js +7 -11
  62. package/lib/filters/HSV.d.ts +1 -1
  63. package/lib/filters/HSV.js +7 -11
  64. package/lib/filters/Invert.d.ts +1 -1
  65. package/lib/filters/Invert.js +1 -5
  66. package/lib/filters/Kaleidoscope.d.ts +1 -1
  67. package/lib/filters/Kaleidoscope.js +9 -13
  68. package/lib/filters/Mask.d.ts +1 -1
  69. package/lib/filters/Mask.js +16 -10
  70. package/lib/filters/Noise.d.ts +1 -1
  71. package/lib/filters/Noise.js +5 -9
  72. package/lib/filters/Pixelate.d.ts +1 -1
  73. package/lib/filters/Pixelate.js +7 -11
  74. package/lib/filters/Posterize.d.ts +1 -1
  75. package/lib/filters/Posterize.js +5 -9
  76. package/lib/filters/RGB.d.ts +1 -1
  77. package/lib/filters/RGB.js +7 -11
  78. package/lib/filters/RGBA.d.ts +1 -1
  79. package/lib/filters/RGBA.js +8 -12
  80. package/lib/filters/Sepia.d.ts +1 -1
  81. package/lib/filters/Sepia.js +1 -5
  82. package/lib/filters/Solarize.d.ts +1 -1
  83. package/lib/filters/Solarize.js +13 -29
  84. package/lib/filters/Threshold.d.ts +1 -1
  85. package/lib/filters/Threshold.js +5 -9
  86. package/lib/index.d.ts +1 -1
  87. package/lib/index.js +2 -4
  88. package/lib/shapes/Arc.d.ts +4 -3
  89. package/lib/shapes/Arc.js +13 -17
  90. package/lib/shapes/Arrow.d.ts +4 -3
  91. package/lib/shapes/Arrow.js +13 -17
  92. package/lib/shapes/Circle.d.ts +4 -3
  93. package/lib/shapes/Circle.js +7 -11
  94. package/lib/shapes/Ellipse.d.ts +4 -3
  95. package/lib/shapes/Ellipse.js +9 -13
  96. package/lib/shapes/Image.d.ts +4 -3
  97. package/lib/shapes/Image.js +17 -21
  98. package/lib/shapes/Label.d.ts +7 -6
  99. package/lib/shapes/Label.js +13 -18
  100. package/lib/shapes/Line.d.ts +4 -3
  101. package/lib/shapes/Line.js +10 -14
  102. package/lib/shapes/Path.d.ts +3 -2
  103. package/lib/shapes/Path.js +83 -23
  104. package/lib/shapes/Rect.d.ts +4 -3
  105. package/lib/shapes/Rect.js +9 -13
  106. package/lib/shapes/RegularPolygon.d.ts +6 -3
  107. package/lib/shapes/RegularPolygon.js +19 -16
  108. package/lib/shapes/Ring.d.ts +4 -3
  109. package/lib/shapes/Ring.js +8 -12
  110. package/lib/shapes/Sprite.d.ts +5 -4
  111. package/lib/shapes/Sprite.js +15 -19
  112. package/lib/shapes/Star.d.ts +4 -3
  113. package/lib/shapes/Star.js +9 -13
  114. package/lib/shapes/Text.d.ts +16 -3
  115. package/lib/shapes/Text.js +73 -53
  116. package/lib/shapes/TextPath.d.ts +5 -4
  117. package/lib/shapes/TextPath.js +48 -41
  118. package/lib/shapes/Transformer.d.ts +8 -8
  119. package/lib/shapes/Transformer.js +90 -90
  120. package/lib/shapes/Wedge.d.ts +4 -3
  121. package/lib/shapes/Wedge.js +12 -16
  122. package/lib/skia-backend.d.ts +2 -0
  123. package/lib/skia-backend.js +24 -0
  124. package/lib/types.d.ts +22 -22
  125. package/lib/types.js +21 -25
  126. package/package.json +53 -25
  127. package/lib/index-node.d.ts +0 -2
  128. package/lib/index-node.js +0 -21
  129. package/lib/index-types.d.ts +0 -181
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Text = void 0;
4
- exports.stringToArray = stringToArray;
5
- const Util_1 = require("../Util");
6
- const Factory_1 = require("../Factory");
7
- const Shape_1 = require("../Shape");
8
- const Global_1 = require("../Global");
9
- const Validators_1 = require("../Validators");
10
- const Global_2 = require("../Global");
11
- function stringToArray(string) {
1
+ import { Util } from "../Util.js";
2
+ import { Factory } from "../Factory.js";
3
+ import { Shape } from "../Shape.js";
4
+ import { Konva } from "../Global.js";
5
+ import { getNumberValidator, getStringValidator, getNumberOrAutoValidator, getBooleanValidator, } from "../Validators.js";
6
+ import { _registerNode } from "../Global.js";
7
+ export function stringToArray(string) {
12
8
  return [...string].reduce((acc, char, index, array) => {
13
9
  if (/\p{Emoji}/u.test(char)) {
14
10
  const nextChar = array[index + 1];
@@ -68,7 +64,7 @@ function getDummyContext() {
68
64
  if (dummyContext) {
69
65
  return dummyContext;
70
66
  }
71
- dummyContext = Util_1.Util.createCanvasElement().getContext(CONTEXT_2D);
67
+ dummyContext = Util.createCanvasElement().getContext(CONTEXT_2D);
72
68
  return dummyContext;
73
69
  }
74
70
  function _fillFunc(context) {
@@ -87,7 +83,7 @@ function checkDefaultFill(config) {
87
83
  }
88
84
  return config;
89
85
  }
90
- class Text extends Shape_1.Shape {
86
+ export class Text extends Shape {
91
87
  constructor(config) {
92
88
  super(checkDefaultFill(config));
93
89
  this._partialTextX = 0;
@@ -98,20 +94,21 @@ class Text extends Shape_1.Shape {
98
94
  this._setTextData();
99
95
  }
100
96
  _sceneFunc(context) {
97
+ var _a, _b;
101
98
  const textArr = this.textArr, textArrLen = textArr.length;
102
99
  if (!this.text()) {
103
100
  return;
104
101
  }
105
- let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
102
+ let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
106
103
  direction = direction === INHERIT ? context.direction : direction;
107
104
  let translateY = lineHeightPx / 2;
108
105
  let baseline = MIDDLE;
109
- if (Global_1.Konva._fixTextRendering) {
106
+ if (!Konva.legacyTextRendering) {
110
107
  const metrics = this.measureSize('M');
111
108
  baseline = 'alphabetic';
112
- translateY =
113
- (metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2 +
114
- lineHeightPx / 2;
109
+ const ascent = (_a = metrics.fontBoundingBoxAscent) !== null && _a !== void 0 ? _a : metrics.actualBoundingBoxAscent;
110
+ const descent = (_b = metrics.fontBoundingBoxDescent) !== null && _b !== void 0 ? _b : metrics.actualBoundingBoxDescent;
111
+ translateY = (ascent - descent) / 2 + lineHeightPx / 2;
115
112
  }
116
113
  if (direction === RTL) {
117
114
  context.setAttr('direction', direction);
@@ -140,7 +137,7 @@ class Text extends Shape_1.Shape {
140
137
  if (shouldUnderline) {
141
138
  context.save();
142
139
  context.beginPath();
143
- const yOffset = Global_1.Konva._fixTextRendering
140
+ const yOffset = !Konva.legacyTextRendering
144
141
  ? Math.round(fontSize / 4)
145
142
  : Math.round(fontSize / 2);
146
143
  const x = lineTranslateX;
@@ -154,20 +151,8 @@ class Text extends Shape_1.Shape {
154
151
  context.stroke();
155
152
  context.restore();
156
153
  }
157
- if (shouldLineThrough) {
158
- context.save();
159
- context.beginPath();
160
- const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;
161
- context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
162
- const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
163
- context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
164
- context.lineWidth = fontSize / 15;
165
- const gradient = this._getLinearGradient();
166
- context.strokeStyle = gradient || fill;
167
- context.stroke();
168
- context.restore();
169
- }
170
- if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
154
+ if (direction !== RTL &&
155
+ (letterSpacing !== 0 || align === JUSTIFY || charRenderFunc)) {
171
156
  const spacesNumber = text.split(' ').length - 1;
172
157
  const array = stringToArray(text);
173
158
  for (let li = 0; li < array.length; li++) {
@@ -178,7 +163,27 @@ class Text extends Shape_1.Shape {
178
163
  this._partialTextX = lineTranslateX;
179
164
  this._partialTextY = translateY + lineTranslateY;
180
165
  this._partialText = letter;
166
+ if (charRenderFunc) {
167
+ context.save();
168
+ const previousLines = textArr.slice(0, n);
169
+ const previousGraphemes = previousLines.reduce((acc, line) => acc + stringToArray(line.text).length, 0);
170
+ const charIndex = li + previousGraphemes;
171
+ charRenderFunc({
172
+ char: letter,
173
+ index: charIndex,
174
+ x: lineTranslateX,
175
+ y: translateY + lineTranslateY,
176
+ lineIndex: n,
177
+ column: li,
178
+ isLastInLine: lastLine,
179
+ width: this.measureSize(letter).width,
180
+ context,
181
+ });
182
+ }
181
183
  context.fillStrokeShape(this);
184
+ if (charRenderFunc) {
185
+ context.restore();
186
+ }
182
187
  lineTranslateX += this.measureSize(letter).width + letterSpacing;
183
188
  }
184
189
  }
@@ -191,6 +196,21 @@ class Text extends Shape_1.Shape {
191
196
  this._partialText = text;
192
197
  context.fillStrokeShape(this);
193
198
  }
199
+ if (shouldLineThrough) {
200
+ context.save();
201
+ context.beginPath();
202
+ const yOffset = !Konva.legacyTextRendering
203
+ ? -Math.round(fontSize / 4)
204
+ : 0;
205
+ context.moveTo(0, translateY + lineTranslateY + yOffset);
206
+ const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
207
+ context.lineTo(Math.round(lineWidth), translateY + lineTranslateY + yOffset);
208
+ context.lineWidth = fontSize / 15;
209
+ const gradient = this._getLinearGradient();
210
+ context.strokeStyle = gradient || fill;
211
+ context.stroke();
212
+ context.restore();
213
+ }
194
214
  context.restore();
195
215
  if (textArrLen > 1) {
196
216
  translateY += lineHeightPx;
@@ -205,7 +225,7 @@ class Text extends Shape_1.Shape {
205
225
  context.fillStrokeShape(this);
206
226
  }
207
227
  setText(text) {
208
- const str = Util_1.Util._isString(text)
228
+ const str = Util._isString(text)
209
229
  ? text
210
230
  : text === null || text === undefined
211
231
  ? ''
@@ -228,7 +248,7 @@ class Text extends Shape_1.Shape {
228
248
  return this.textWidth;
229
249
  }
230
250
  getTextHeight() {
231
- Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
251
+ Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
232
252
  return this.textHeight;
233
253
  }
234
254
  measureSize(text) {
@@ -408,7 +428,6 @@ class Text extends Shape_1.Shape {
408
428
  return super._useBufferCanvas();
409
429
  }
410
430
  }
411
- exports.Text = Text;
412
431
  Text.prototype._fillFunc = _fillFunc;
413
432
  Text.prototype._strokeFunc = _strokeFunc;
414
433
  Text.prototype.className = TEXT_UPPER;
@@ -420,20 +439,21 @@ Text.prototype._attrsAffectingSize = [
420
439
  'lineHeight',
421
440
  'letterSpacing',
422
441
  ];
423
- (0, Global_2._registerNode)(Text);
424
- Factory_1.Factory.overWriteSetter(Text, 'width', (0, Validators_1.getNumberOrAutoValidator)());
425
- Factory_1.Factory.overWriteSetter(Text, 'height', (0, Validators_1.getNumberOrAutoValidator)());
426
- Factory_1.Factory.addGetterSetter(Text, 'direction', INHERIT);
427
- Factory_1.Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
428
- Factory_1.Factory.addGetterSetter(Text, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
429
- Factory_1.Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
430
- Factory_1.Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
431
- Factory_1.Factory.addGetterSetter(Text, 'padding', 0, (0, Validators_1.getNumberValidator)());
432
- Factory_1.Factory.addGetterSetter(Text, 'align', LEFT);
433
- Factory_1.Factory.addGetterSetter(Text, 'verticalAlign', TOP);
434
- Factory_1.Factory.addGetterSetter(Text, 'lineHeight', 1, (0, Validators_1.getNumberValidator)());
435
- Factory_1.Factory.addGetterSetter(Text, 'wrap', WORD);
436
- Factory_1.Factory.addGetterSetter(Text, 'ellipsis', false, (0, Validators_1.getBooleanValidator)());
437
- Factory_1.Factory.addGetterSetter(Text, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
438
- Factory_1.Factory.addGetterSetter(Text, 'text', '', (0, Validators_1.getStringValidator)());
439
- Factory_1.Factory.addGetterSetter(Text, 'textDecoration', '');
442
+ _registerNode(Text);
443
+ Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator());
444
+ Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator());
445
+ Factory.addGetterSetter(Text, 'direction', INHERIT);
446
+ Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
447
+ Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator());
448
+ Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
449
+ Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
450
+ Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator());
451
+ Factory.addGetterSetter(Text, 'align', LEFT);
452
+ Factory.addGetterSetter(Text, 'verticalAlign', TOP);
453
+ Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator());
454
+ Factory.addGetterSetter(Text, 'wrap', WORD);
455
+ Factory.addGetterSetter(Text, 'ellipsis', false, getBooleanValidator());
456
+ Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
457
+ Factory.addGetterSetter(Text, 'text', '', getStringValidator());
458
+ Factory.addGetterSetter(Text, 'textDecoration', '');
459
+ Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
@@ -1,7 +1,8 @@
1
- import { Context } from '../Context.js';
2
- import { Shape, ShapeConfig } from '../Shape.js';
3
- import { Text } from './Text.js';
4
- import { GetSet, PathSegment, Vector2d } from '../types.js';
1
+ import type { Context } from '../Context.ts';
2
+ import type { ShapeConfig } from '../Shape.ts';
3
+ import { Shape } from '../Shape.ts';
4
+ import { Text } from './Text.ts';
5
+ import type { GetSet, PathSegment, Vector2d } from '../types.ts';
5
6
  export interface TextPathConfig extends ShapeConfig {
6
7
  text?: string;
7
8
  data?: string;
@@ -1,13 +1,10 @@
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");
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";
11
8
  const EMPTY_STRING = '', NORMAL = 'normal';
12
9
  function _fillFunc(context) {
13
10
  context.fillText(this.partialText, 0, 0);
@@ -15,10 +12,10 @@ function _fillFunc(context) {
15
12
  function _strokeFunc(context) {
16
13
  context.strokeText(this.partialText, 0, 0);
17
14
  }
18
- class TextPath extends Shape_1.Shape {
15
+ export class TextPath extends Shape {
19
16
  constructor(config) {
20
17
  super(config);
21
- this.dummyCanvas = Util_1.Util.createCanvasElement();
18
+ this.dummyCanvas = Util.createCanvasElement();
22
19
  this.dataArray = [];
23
20
  this._readDataAttribute();
24
21
  this.on('dataChange.konva', function () {
@@ -29,7 +26,7 @@ class TextPath extends Shape_1.Shape {
29
26
  this._setTextData();
30
27
  }
31
28
  _getTextPathLength() {
32
- return Path_1.Path.getPathLength(this.dataArray);
29
+ return Path.getPathLength(this.dataArray);
33
30
  }
34
31
  _getPointAtLength(length) {
35
32
  if (!this.attrs.data) {
@@ -39,10 +36,10 @@ class TextPath extends Shape_1.Shape {
39
36
  if (length - 1 > totalLength) {
40
37
  return null;
41
38
  }
42
- return Path_1.Path.getPointAtLengthOfDataArray(length, this.dataArray);
39
+ return Path.getPointAtLengthOfDataArray(length, this.dataArray);
43
40
  }
44
41
  _readDataAttribute() {
45
- this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
42
+ this.dataArray = Path.parsePathData(this.attrs.data);
46
43
  this.pathLength = this._getTextPathLength();
47
44
  }
48
45
  _sceneFunc(context) {
@@ -98,14 +95,14 @@ class TextPath extends Shape_1.Shape {
98
95
  return this.textWidth;
99
96
  }
100
97
  getTextHeight() {
101
- Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
98
+ Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
102
99
  return this.textHeight;
103
100
  }
104
101
  setText(text) {
105
- return Text_1.Text.prototype.setText.call(this, text);
102
+ return Text.prototype.setText.call(this, text);
106
103
  }
107
104
  _getContextFont() {
108
- return Text_1.Text.prototype._getContextFont.call(this);
105
+ return Text.prototype._getContextFont.call(this);
109
106
  }
110
107
  _getTextSize(text) {
111
108
  const dummyCanvas = this.dummyCanvas;
@@ -120,7 +117,17 @@ class TextPath extends Shape_1.Shape {
120
117
  };
121
118
  }
122
119
  _setTextData() {
123
- const { width, height } = this._getTextSize(this.attrs.text);
120
+ const charArr = stringToArray(this.text());
121
+ const chars = [];
122
+ let width = 0;
123
+ for (let i = 0; i < charArr.length; i++) {
124
+ chars.push({
125
+ char: charArr[i],
126
+ width: this._getTextSize(charArr[i]).width,
127
+ });
128
+ width += chars[i].width;
129
+ }
130
+ const { height } = this._getTextSize(this.attrs.text);
124
131
  this.textWidth = width;
125
132
  this.textHeight = height;
126
133
  this.glyphInfo = [];
@@ -138,25 +145,26 @@ class TextPath extends Shape_1.Shape {
138
145
  if (align === 'right') {
139
146
  offset = Math.max(0, this.pathLength - textWidth);
140
147
  }
141
- const charArr = (0, Text_1.stringToArray)(this.text());
142
148
  let offsetToGlyph = offset;
143
- for (let i = 0; i < charArr.length; i++) {
149
+ for (let i = 0; i < chars.length; i++) {
144
150
  const charStartPoint = this._getPointAtLength(offsetToGlyph);
145
151
  if (!charStartPoint)
146
152
  return;
147
- let glyphWidth = this._getTextSize(charArr[i]).width + letterSpacing;
148
- if (charArr[i] === ' ' && align === 'justify') {
153
+ const char = chars[i].char;
154
+ let glyphWidth = chars[i].width + letterSpacing;
155
+ if (char === ' ' && align === 'justify') {
149
156
  const numberOfSpaces = this.text().split(' ').length - 1;
150
157
  glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
151
158
  }
152
159
  const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
153
- if (!charEndPoint)
160
+ if (!charEndPoint) {
154
161
  return;
155
- const width = Path_1.Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
162
+ }
163
+ const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
156
164
  let kern = 0;
157
165
  if (kerningFunc) {
158
166
  try {
159
- kern = kerningFunc(charArr[i - 1], charArr[i]) * this.fontSize();
167
+ kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
160
168
  }
161
169
  catch (e) {
162
170
  kern = 0;
@@ -165,7 +173,7 @@ class TextPath extends Shape_1.Shape {
165
173
  charStartPoint.x += kern;
166
174
  charEndPoint.x += kern;
167
175
  this.textWidth += kern;
168
- const midpoint = Path_1.Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
176
+ const midpoint = Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
169
177
  const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x);
170
178
  this.glyphInfo.push({
171
179
  transposeX: midpoint.x,
@@ -216,26 +224,25 @@ class TextPath extends Shape_1.Shape {
216
224
  };
217
225
  }
218
226
  destroy() {
219
- Util_1.Util.releaseCanvas(this.dummyCanvas);
227
+ Util.releaseCanvas(this.dummyCanvas);
220
228
  return super.destroy();
221
229
  }
222
230
  }
223
- exports.TextPath = TextPath;
224
231
  TextPath.prototype._fillFunc = _fillFunc;
225
232
  TextPath.prototype._strokeFunc = _strokeFunc;
226
233
  TextPath.prototype._fillFuncHit = _fillFunc;
227
234
  TextPath.prototype._strokeFuncHit = _strokeFunc;
228
235
  TextPath.prototype.className = 'TextPath';
229
236
  TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
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', '');
241
- Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
237
+ _registerNode(TextPath);
238
+ Factory.addGetterSetter(TextPath, 'data');
239
+ Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
240
+ Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
241
+ Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
242
+ Factory.addGetterSetter(TextPath, 'align', 'left');
243
+ Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
244
+ Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
245
+ Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
246
+ Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
247
+ Factory.addGetterSetter(TextPath, 'textDecoration', '');
248
+ Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
@@ -1,9 +1,9 @@
1
- import { Transform } from '../Util.js';
2
- import { Node } from '../Node.js';
3
- import { Rect } from './Rect.js';
4
- import { Group } from '../Group.js';
5
- import { ContainerConfig } from '../Container.js';
6
- import { GetSet, IRect, Vector2d } from '../types.js';
1
+ import { Transform } from '../Util.ts';
2
+ import { Node } from '../Node.ts';
3
+ import { Rect } from './Rect.ts';
4
+ import { Group } from '../Group.ts';
5
+ import type { ContainerConfig } from '../Container.ts';
6
+ import type { GetSet, IRect, Vector2d } from '../types.ts';
7
7
  export interface Box extends IRect {
8
8
  rotation: number;
9
9
  }
@@ -49,11 +49,11 @@ export declare class Transformer extends Group {
49
49
  constructor(config?: TransformerConfig);
50
50
  attachTo(node: Node): this;
51
51
  setNode(node: Node): this;
52
- getNode(): Node<import("../Node.js").NodeConfig>;
52
+ getNode(): Node<import("../Node.ts").NodeConfig>;
53
53
  _getEventNamespace(): string;
54
54
  setNodes(nodes?: Array<Node>): this;
55
55
  _proxyDrag(node: Node): void;
56
- getNodes(): Node<import("../Node.js").NodeConfig>[];
56
+ getNodes(): Node<import("../Node.ts").NodeConfig>[];
57
57
  getActiveAnchor(): string | null;
58
58
  detach(): void;
59
59
  _resetTransformCache(): void;