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,373 +0,0 @@
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) {
10
- return Array.from(string);
11
- }
12
- exports.stringToArray = stringToArray;
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 = [
14
- 'fontFamily',
15
- 'fontSize',
16
- 'fontStyle',
17
- 'fontVariant',
18
- 'padding',
19
- 'align',
20
- 'verticalAlign',
21
- 'lineHeight',
22
- 'text',
23
- 'width',
24
- 'height',
25
- 'wrap',
26
- 'ellipsis',
27
- 'letterSpacing',
28
- ], attrChangeListLen = ATTR_CHANGE_LIST.length;
29
- function normalizeFontFamily(fontFamily) {
30
- return fontFamily
31
- .split(',')
32
- .map((family) => {
33
- family = family.trim();
34
- const hasSpace = family.indexOf(' ') >= 0;
35
- const hasQuotes = family.indexOf('"') >= 0 || family.indexOf("'") >= 0;
36
- if (hasSpace && !hasQuotes) {
37
- family = `"${family}"`;
38
- }
39
- return family;
40
- })
41
- .join(', ');
42
- }
43
- var dummyContext;
44
- function getDummyContext() {
45
- if (dummyContext) {
46
- return dummyContext;
47
- }
48
- dummyContext = Util_1.Util.createCanvasElement().getContext(CONTEXT_2D);
49
- return dummyContext;
50
- }
51
- function _fillFunc(context) {
52
- context.fillText(this._partialText, this._partialTextX, this._partialTextY);
53
- }
54
- function _strokeFunc(context) {
55
- context.strokeText(this._partialText, this._partialTextX, this._partialTextY);
56
- }
57
- function checkDefaultFill(config) {
58
- config = config || {};
59
- if (!config.fillLinearGradientColorStops &&
60
- !config.fillRadialGradientColorStops &&
61
- !config.fillPatternImage) {
62
- config.fill = config.fill || 'black';
63
- }
64
- return config;
65
- }
66
- class Text extends Shape_1.Shape {
67
- constructor(config) {
68
- super(checkDefaultFill(config));
69
- this._partialTextX = 0;
70
- this._partialTextY = 0;
71
- for (var n = 0; n < attrChangeListLen; n++) {
72
- this.on(ATTR_CHANGE_LIST[n] + CHANGE_KONVA, this._setTextData);
73
- }
74
- this._setTextData();
75
- }
76
- _sceneFunc(context) {
77
- var textArr = this.textArr, textArrLen = textArr.length;
78
- if (!this.text()) {
79
- return;
80
- }
81
- var padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), 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;
82
- var translateY = 0;
83
- var translateY = lineHeightPx / 2;
84
- var lineTranslateX = 0;
85
- var lineTranslateY = 0;
86
- context.setAttr('font', this._getContextFont());
87
- context.setAttr('textBaseline', MIDDLE);
88
- context.setAttr('textAlign', LEFT);
89
- if (verticalAlign === MIDDLE) {
90
- alignY = (this.getHeight() - textArrLen * lineHeightPx - padding * 2) / 2;
91
- }
92
- else if (verticalAlign === BOTTOM) {
93
- alignY = this.getHeight() - textArrLen * lineHeightPx - padding * 2;
94
- }
95
- context.translate(padding, alignY + padding);
96
- for (n = 0; n < textArrLen; n++) {
97
- var lineTranslateX = 0;
98
- var lineTranslateY = 0;
99
- var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
100
- context.save();
101
- if (align === RIGHT) {
102
- lineTranslateX += totalWidth - width - padding * 2;
103
- }
104
- else if (align === CENTER) {
105
- lineTranslateX += (totalWidth - width - padding * 2) / 2;
106
- }
107
- if (shouldUnderline) {
108
- context.save();
109
- context.beginPath();
110
- context.moveTo(lineTranslateX, translateY + lineTranslateY + Math.round(fontSize / 2));
111
- spacesNumber = text.split(' ').length - 1;
112
- oneWord = spacesNumber === 0;
113
- lineWidth =
114
- align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
115
- context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + Math.round(fontSize / 2));
116
- context.lineWidth = fontSize / 15;
117
- const gradient = this._getLinearGradient();
118
- context.strokeStyle = gradient || fill;
119
- context.stroke();
120
- context.restore();
121
- }
122
- if (shouldLineThrough) {
123
- context.save();
124
- context.beginPath();
125
- context.moveTo(lineTranslateX, translateY + lineTranslateY);
126
- spacesNumber = text.split(' ').length - 1;
127
- oneWord = spacesNumber === 0;
128
- lineWidth =
129
- align === JUSTIFY && lastLine && !oneWord
130
- ? totalWidth - padding * 2
131
- : width;
132
- context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY);
133
- context.lineWidth = fontSize / 15;
134
- const gradient = this._getLinearGradient();
135
- context.strokeStyle = gradient || fill;
136
- context.stroke();
137
- context.restore();
138
- }
139
- if (letterSpacing !== 0 || align === JUSTIFY) {
140
- spacesNumber = text.split(' ').length - 1;
141
- var array = stringToArray(text);
142
- for (var li = 0; li < array.length; li++) {
143
- var letter = array[li];
144
- if (letter === ' ' && !lastLine && align === JUSTIFY) {
145
- lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
146
- }
147
- this._partialTextX = lineTranslateX;
148
- this._partialTextY = translateY + lineTranslateY;
149
- this._partialText = letter;
150
- context.fillStrokeShape(this);
151
- lineTranslateX += this.measureSize(letter).width + letterSpacing;
152
- }
153
- }
154
- else {
155
- this._partialTextX = lineTranslateX;
156
- this._partialTextY = translateY + lineTranslateY;
157
- this._partialText = text;
158
- context.fillStrokeShape(this);
159
- }
160
- context.restore();
161
- if (textArrLen > 1) {
162
- translateY += lineHeightPx;
163
- }
164
- }
165
- }
166
- _hitFunc(context) {
167
- var width = this.getWidth(), height = this.getHeight();
168
- context.beginPath();
169
- context.rect(0, 0, width, height);
170
- context.closePath();
171
- context.fillStrokeShape(this);
172
- }
173
- setText(text) {
174
- var str = Util_1.Util._isString(text)
175
- ? text
176
- : text === null || text === undefined
177
- ? ''
178
- : text + '';
179
- this._setAttr(TEXT, str);
180
- return this;
181
- }
182
- getWidth() {
183
- var isAuto = this.attrs.width === AUTO || this.attrs.width === undefined;
184
- return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
185
- }
186
- getHeight() {
187
- var isAuto = this.attrs.height === AUTO || this.attrs.height === undefined;
188
- return isAuto
189
- ? this.fontSize() * this.textArr.length * this.lineHeight() +
190
- this.padding() * 2
191
- : this.attrs.height;
192
- }
193
- getTextWidth() {
194
- return this.textWidth;
195
- }
196
- getTextHeight() {
197
- Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
198
- return this.textHeight;
199
- }
200
- measureSize(text) {
201
- var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
202
- _context.save();
203
- _context.font = this._getContextFont();
204
- metrics = _context.measureText(text);
205
- _context.restore();
206
- return {
207
- width: metrics.width,
208
- height: fontSize,
209
- };
210
- }
211
- _getContextFont() {
212
- return (this.fontStyle() +
213
- SPACE +
214
- this.fontVariant() +
215
- SPACE +
216
- (this.fontSize() + PX_SPACE) +
217
- normalizeFontFamily(this.fontFamily()));
218
- }
219
- _addTextLine(line) {
220
- const align = this.align();
221
- if (align === JUSTIFY) {
222
- line = line.trim();
223
- }
224
- var width = this._getTextWidth(line);
225
- return this.textArr.push({
226
- text: line,
227
- width: width,
228
- lastInParagraph: false,
229
- });
230
- }
231
- _getTextWidth(text) {
232
- var letterSpacing = this.letterSpacing();
233
- var length = text.length;
234
- return (getDummyContext().measureText(text).width +
235
- (length ? letterSpacing * (length - 1) : 0));
236
- }
237
- _setTextData() {
238
- var lines = this.text().split('\n'), fontSize = +this.fontSize(), textWidth = 0, lineHeightPx = this.lineHeight() * fontSize, width = this.attrs.width, height = this.attrs.height, fixedWidth = width !== AUTO && width !== undefined, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxWidth = width - padding * 2, maxHeightPx = height - padding * 2, currentHeightPx = 0, wrap = this.wrap(), shouldWrap = wrap !== NONE, wrapAtWord = wrap !== CHAR && shouldWrap, shouldAddEllipsis = this.ellipsis();
239
- this.textArr = [];
240
- getDummyContext().font = this._getContextFont();
241
- var additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0;
242
- for (var i = 0, max = lines.length; i < max; ++i) {
243
- var line = lines[i];
244
- var lineWidth = this._getTextWidth(line);
245
- if (fixedWidth && lineWidth > maxWidth) {
246
- while (line.length > 0) {
247
- var low = 0, high = line.length, match = '', matchWidth = 0;
248
- while (low < high) {
249
- var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr) + additionalWidth;
250
- if (substrWidth <= maxWidth) {
251
- low = mid + 1;
252
- match = substr;
253
- matchWidth = substrWidth;
254
- }
255
- else {
256
- high = mid;
257
- }
258
- }
259
- if (match) {
260
- if (wrapAtWord) {
261
- var wrapIndex;
262
- var nextChar = line[match.length];
263
- var nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
264
- if (nextIsSpaceOrDash && matchWidth <= maxWidth) {
265
- wrapIndex = match.length;
266
- }
267
- else {
268
- wrapIndex =
269
- Math.max(match.lastIndexOf(SPACE), match.lastIndexOf(DASH)) +
270
- 1;
271
- }
272
- if (wrapIndex > 0) {
273
- low = wrapIndex;
274
- match = match.slice(0, low);
275
- matchWidth = this._getTextWidth(match);
276
- }
277
- }
278
- match = match.trimRight();
279
- this._addTextLine(match);
280
- textWidth = Math.max(textWidth, matchWidth);
281
- currentHeightPx += lineHeightPx;
282
- var shouldHandleEllipsis = this._shouldHandleEllipsis(currentHeightPx);
283
- if (shouldHandleEllipsis) {
284
- this._tryToAddEllipsisToLastLine();
285
- break;
286
- }
287
- line = line.slice(low);
288
- line = line.trimLeft();
289
- if (line.length > 0) {
290
- lineWidth = this._getTextWidth(line);
291
- if (lineWidth <= maxWidth) {
292
- this._addTextLine(line);
293
- currentHeightPx += lineHeightPx;
294
- textWidth = Math.max(textWidth, lineWidth);
295
- break;
296
- }
297
- }
298
- }
299
- else {
300
- break;
301
- }
302
- }
303
- }
304
- else {
305
- this._addTextLine(line);
306
- currentHeightPx += lineHeightPx;
307
- textWidth = Math.max(textWidth, lineWidth);
308
- if (this._shouldHandleEllipsis(currentHeightPx) && i < max - 1) {
309
- this._tryToAddEllipsisToLastLine();
310
- }
311
- }
312
- if (this.textArr[this.textArr.length - 1]) {
313
- this.textArr[this.textArr.length - 1].lastInParagraph = true;
314
- }
315
- if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
316
- break;
317
- }
318
- }
319
- this.textHeight = fontSize;
320
- this.textWidth = textWidth;
321
- }
322
- _shouldHandleEllipsis(currentHeightPx) {
323
- var fontSize = +this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, height = this.attrs.height, fixedHeight = height !== AUTO && height !== undefined, padding = this.padding(), maxHeightPx = height - padding * 2, wrap = this.wrap(), shouldWrap = wrap !== NONE;
324
- return (!shouldWrap ||
325
- (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx));
326
- }
327
- _tryToAddEllipsisToLastLine() {
328
- var width = this.attrs.width, fixedWidth = width !== AUTO && width !== undefined, padding = this.padding(), maxWidth = width - padding * 2, shouldAddEllipsis = this.ellipsis();
329
- var lastLine = this.textArr[this.textArr.length - 1];
330
- if (!lastLine || !shouldAddEllipsis) {
331
- return;
332
- }
333
- if (fixedWidth) {
334
- var haveSpace = this._getTextWidth(lastLine.text + ELLIPSIS) < maxWidth;
335
- if (!haveSpace) {
336
- lastLine.text = lastLine.text.slice(0, lastLine.text.length - 3);
337
- }
338
- }
339
- this.textArr.splice(this.textArr.length - 1, 1);
340
- this._addTextLine(lastLine.text + ELLIPSIS);
341
- }
342
- getStrokeScaleEnabled() {
343
- return true;
344
- }
345
- }
346
- exports.Text = Text;
347
- Text.prototype._fillFunc = _fillFunc;
348
- Text.prototype._strokeFunc = _strokeFunc;
349
- Text.prototype.className = TEXT_UPPER;
350
- Text.prototype._attrsAffectingSize = [
351
- 'text',
352
- 'fontSize',
353
- 'padding',
354
- 'wrap',
355
- 'lineHeight',
356
- 'letterSpacing',
357
- ];
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', '');
@@ -1,56 +0,0 @@
1
- import { Context } from '../Context';
2
- import { Shape, ShapeConfig } from '../Shape';
3
- import { GetSet, Vector2d } from '../types';
4
- export interface TextPathConfig extends ShapeConfig {
5
- text?: string;
6
- data?: string;
7
- fontFamily?: string;
8
- fontSize?: number;
9
- fontStyle?: string;
10
- letterSpacing?: number;
11
- }
12
- export declare class TextPath extends Shape<TextPathConfig> {
13
- dummyCanvas: HTMLCanvasElement;
14
- dataArray: any[];
15
- glyphInfo: Array<{
16
- transposeX: number;
17
- transposeY: number;
18
- text: string;
19
- rotation: number;
20
- p0: Vector2d;
21
- p1: Vector2d;
22
- }>;
23
- partialText: string;
24
- textWidth: number;
25
- textHeight: number;
26
- constructor(config?: TextPathConfig);
27
- _sceneFunc(context: Context): void;
28
- _hitFunc(context: Context): void;
29
- getTextWidth(): number;
30
- getTextHeight(): number;
31
- setText(text: string): any;
32
- _getContextFont(): any;
33
- _getTextSize(text: string): {
34
- width: number;
35
- height: number;
36
- };
37
- _setTextData(): void;
38
- getSelfRect(): {
39
- x: number;
40
- y: number;
41
- width: number;
42
- height: number;
43
- };
44
- destroy(): this;
45
- fontFamily: GetSet<string, this>;
46
- fontSize: GetSet<number, this>;
47
- fontStyle: GetSet<string, this>;
48
- fontVariant: GetSet<string, this>;
49
- align: GetSet<string, this>;
50
- letterSpacing: GetSet<number, this>;
51
- text: GetSet<string, this>;
52
- data: GetSet<string, this>;
53
- kerningFunc: GetSet<(leftChar: string, rightChar: string) => number, this>;
54
- textBaseline: GetSet<string, this>;
55
- textDecoration: GetSet<string, this>;
56
- }