konva 10.3.3 → 10.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +1 -1
  2. package/konva.js +1576 -1636
  3. package/konva.min.js +4 -4
  4. package/lib/Animation.d.ts +63 -3
  5. package/lib/Animation.js +86 -65
  6. package/lib/BezierFunctions.d.ts +10 -0
  7. package/lib/BezierFunctions.js +32 -0
  8. package/lib/Canvas.d.ts +53 -0
  9. package/lib/Canvas.js +93 -34
  10. package/lib/Container.d.ts +156 -9
  11. package/lib/Container.js +260 -25
  12. package/lib/Context.d.ts +247 -0
  13. package/lib/Context.js +312 -74
  14. package/lib/Core.js +1 -0
  15. package/lib/DragAndDrop.d.ts +2 -0
  16. package/lib/DragAndDrop.js +92 -21
  17. package/lib/Factory.d.ts +24 -1
  18. package/lib/Factory.js +14 -20
  19. package/lib/FastLayer.d.ts +14 -1
  20. package/lib/FastLayer.js +14 -1
  21. package/lib/Global.d.ts +114 -3
  22. package/lib/Global.js +134 -5
  23. package/lib/Group.d.ts +11 -0
  24. package/lib/Group.js +11 -0
  25. package/lib/Layer.d.ts +128 -3
  26. package/lib/Layer.js +260 -49
  27. package/lib/Node.d.ts +703 -32
  28. package/lib/Node.js +1545 -202
  29. package/lib/PointerEvents.d.ts +2 -1
  30. package/lib/PointerEvents.js +19 -1
  31. package/lib/Shape.d.ts +99 -14
  32. package/lib/Shape.js +1101 -67
  33. package/lib/Stage.d.ts +85 -2
  34. package/lib/Stage.js +205 -14
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +148 -4
  38. package/lib/Util.js +354 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +12 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +17 -6
  44. package/lib/_FullInternals.js +7 -0
  45. package/lib/canvas-backend.js +6 -0
  46. package/lib/filters/Blur.d.ts +18 -0
  47. package/lib/filters/Blur.js +97 -24
  48. package/lib/filters/Brighten.d.ts +21 -0
  49. package/lib/filters/Brighten.js +24 -0
  50. package/lib/filters/Brightness.d.ts +11 -0
  51. package/lib/filters/Brightness.js +16 -0
  52. package/lib/filters/Contrast.d.ts +10 -0
  53. package/lib/filters/Contrast.js +21 -0
  54. package/lib/filters/Emboss.d.ts +20 -0
  55. package/lib/filters/Emboss.js +68 -8
  56. package/lib/filters/Enhance.d.ts +14 -0
  57. package/lib/filters/Enhance.js +34 -0
  58. package/lib/filters/Grayscale.d.ts +9 -0
  59. package/lib/filters/Grayscale.js +12 -0
  60. package/lib/filters/HSL.d.ts +17 -0
  61. package/lib/filters/HSL.js +48 -5
  62. package/lib/filters/HSV.d.ts +18 -0
  63. package/lib/filters/HSV.js +49 -5
  64. package/lib/filters/Invert.d.ts +9 -0
  65. package/lib/filters/Invert.js +12 -0
  66. package/lib/filters/Kaleidoscope.d.ts +12 -0
  67. package/lib/filters/Kaleidoscope.js +83 -0
  68. package/lib/filters/Mask.d.ts +11 -0
  69. package/lib/filters/Mask.js +18 -0
  70. package/lib/filters/Noise.d.ts +19 -0
  71. package/lib/filters/Noise.js +19 -0
  72. package/lib/filters/Pixelate.d.ts +20 -0
  73. package/lib/filters/Pixelate.js +28 -1
  74. package/lib/filters/Posterize.d.ts +21 -0
  75. package/lib/filters/Posterize.js +22 -0
  76. package/lib/filters/RGB.d.ts +21 -0
  77. package/lib/filters/RGB.js +43 -28
  78. package/lib/filters/RGBA.d.ts +23 -0
  79. package/lib/filters/RGBA.js +28 -41
  80. package/lib/filters/Sepia.d.ts +9 -0
  81. package/lib/filters/Sepia.js +10 -0
  82. package/lib/filters/Solarize.d.ts +10 -0
  83. package/lib/filters/Solarize.js +11 -0
  84. package/lib/filters/Threshold.d.ts +22 -0
  85. package/lib/filters/Threshold.js +22 -0
  86. package/lib/shapes/Arc.d.ts +40 -0
  87. package/lib/shapes/Arc.js +89 -6
  88. package/lib/shapes/Arrow.d.ts +24 -1
  89. package/lib/shapes/Arrow.js +83 -0
  90. package/lib/shapes/Circle.d.ts +18 -0
  91. package/lib/shapes/Circle.js +36 -9
  92. package/lib/shapes/Ellipse.d.ts +34 -2
  93. package/lib/shapes/Ellipse.js +67 -9
  94. package/lib/shapes/Image.d.ts +49 -0
  95. package/lib/shapes/Image.js +151 -22
  96. package/lib/shapes/Label.d.ts +65 -1
  97. package/lib/shapes/Label.js +113 -20
  98. package/lib/shapes/Line.d.ts +50 -8
  99. package/lib/shapes/Line.js +116 -20
  100. package/lib/shapes/Path.d.ts +56 -6
  101. package/lib/shapes/Path.js +203 -128
  102. package/lib/shapes/Rect.d.ts +18 -0
  103. package/lib/shapes/Rect.js +36 -0
  104. package/lib/shapes/RegularPolygon.d.ts +22 -0
  105. package/lib/shapes/RegularPolygon.js +70 -0
  106. package/lib/shapes/Ring.d.ts +19 -0
  107. package/lib/shapes/Ring.js +51 -5
  108. package/lib/shapes/Sprite.d.ts +78 -0
  109. package/lib/shapes/Sprite.js +238 -25
  110. package/lib/shapes/Star.d.ts +23 -0
  111. package/lib/shapes/Star.js +62 -0
  112. package/lib/shapes/Text.d.ts +59 -1
  113. package/lib/shapes/Text.js +481 -97
  114. package/lib/shapes/TextPath.d.ts +49 -3
  115. package/lib/shapes/TextPath.js +278 -34
  116. package/lib/shapes/Transformer.d.ts +124 -12
  117. package/lib/shapes/Transformer.js +864 -140
  118. package/lib/shapes/Wedge.d.ts +22 -0
  119. package/lib/shapes/Wedge.js +67 -3
  120. package/lib/skia-backend.js +9 -0
  121. package/lib/types.d.ts +2 -23
  122. package/lib/types.js +1 -21
  123. package/package.json +12 -16
@@ -16,10 +16,52 @@ export interface TextPathConfig extends ShapeConfig {
16
16
  textDecoration?: string;
17
17
  direction?: string;
18
18
  kerningFunc?: (leftChar: string, rightChar: string) => number;
19
- lineHeight?: number;
20
19
  }
20
+ /**
21
+ * Path constructor.
22
+ * @author Jason Follas
23
+ * @constructor
24
+ * @memberof Konva
25
+ * @augments Konva.Shape
26
+ * @param {Object} config
27
+ * @param {String} [config.fontFamily] default is Arial
28
+ * @param {Number} [config.fontSize] default is 12
29
+ * @param {String} [config.fontStyle] Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
30
+ * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
31
+ * @param {String} [config.textBaseline] Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle
32
+ * @param {String} config.text
33
+ * @param {String} config.data SVG data string
34
+ * @param {Function} config.kerningFunc a getter for kerning values for the specified characters
35
+ * @@shapeParams
36
+ * @@nodeParams
37
+ * @example
38
+ * var kerningPairs = {
39
+ * 'A': {
40
+ * ' ': -0.05517578125,
41
+ * 'T': -0.07421875,
42
+ * 'V': -0.07421875
43
+ * }
44
+ * 'V': {
45
+ * ',': -0.091796875,
46
+ * ":": -0.037109375,
47
+ * ";": -0.037109375,
48
+ * "A": -0.07421875
49
+ * }
50
+ * }
51
+ * var textpath = new Konva.TextPath({
52
+ * x: 100,
53
+ * y: 50,
54
+ * fill: '#333',
55
+ * fontSize: '24',
56
+ * fontFamily: 'Arial',
57
+ * text: 'All the world\'s a stage, and all the men and women merely players.',
58
+ * data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
59
+ * kerningFunc(leftChar, rightChar) {
60
+ * return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
61
+ * }
62
+ * });
63
+ */
21
64
  export declare class TextPath extends Shape<TextPathConfig> {
22
- dummyCanvas: HTMLCanvasElement;
23
65
  dataArray: PathSegment[];
24
66
  glyphInfo: Array<{
25
67
  transposeX: number;
@@ -43,6 +85,11 @@ export declare class TextPath extends Shape<TextPathConfig> {
43
85
  _readDataAttribute(): void;
44
86
  _sceneFunc(context: Context): void;
45
87
  _hitFunc(context: Context): void;
88
+ /**
89
+ * get text width in pixels
90
+ * @method
91
+ * @name Konva.TextPath#getTextWidth
92
+ */
46
93
  getTextWidth(): number;
47
94
  getTextHeight(): number;
48
95
  setText(text: string): Text;
@@ -58,7 +105,6 @@ export declare class TextPath extends Shape<TextPathConfig> {
58
105
  width: number;
59
106
  height: number;
60
107
  };
61
- destroy(): this;
62
108
  fontFamily: GetSet<string, this>;
63
109
  fontSize: GetSet<number, this>;
64
110
  fontStyle: GetSet<string, this>;
@@ -2,7 +2,7 @@ import { Util } from "../Util.js";
2
2
  import { Factory } from "../Factory.js";
3
3
  import { Shape } from "../Shape.js";
4
4
  import { Path } from "./Path.js";
5
- import { Text, stringToArray } from "./Text.js";
5
+ import { Text, getDecorationLineWidth, getDummyContext, stringToArray, } from "./Text.js";
6
6
  import { getNumberValidator } from "../Validators.js";
7
7
  import { _registerNode } from "../Global.js";
8
8
  const EMPTY_STRING = '', NORMAL = 'normal';
@@ -12,23 +12,63 @@ function _fillFunc(context) {
12
12
  function _strokeFunc(context) {
13
13
  context.strokeText(this.partialText, 0, 0);
14
14
  }
15
+ /**
16
+ * Path constructor.
17
+ * @author Jason Follas
18
+ * @constructor
19
+ * @memberof Konva
20
+ * @augments Konva.Shape
21
+ * @param {Object} config
22
+ * @param {String} [config.fontFamily] default is Arial
23
+ * @param {Number} [config.fontSize] default is 12
24
+ * @param {String} [config.fontStyle] Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
25
+ * @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
26
+ * @param {String} [config.textBaseline] Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle
27
+ * @param {String} config.text
28
+ * @param {String} config.data SVG data string
29
+ * @param {Function} config.kerningFunc a getter for kerning values for the specified characters
30
+ * @@shapeParams
31
+ * @@nodeParams
32
+ * @example
33
+ * var kerningPairs = {
34
+ * 'A': {
35
+ * ' ': -0.05517578125,
36
+ * 'T': -0.07421875,
37
+ * 'V': -0.07421875
38
+ * }
39
+ * 'V': {
40
+ * ',': -0.091796875,
41
+ * ":": -0.037109375,
42
+ * ";": -0.037109375,
43
+ * "A": -0.07421875
44
+ * }
45
+ * }
46
+ * var textpath = new Konva.TextPath({
47
+ * x: 100,
48
+ * y: 50,
49
+ * fill: '#333',
50
+ * fontSize: '24',
51
+ * fontFamily: 'Arial',
52
+ * text: 'All the world\'s a stage, and all the men and women merely players.',
53
+ * data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
54
+ * kerningFunc(leftChar, rightChar) {
55
+ * return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
56
+ * }
57
+ * });
58
+ */
15
59
  export class TextPath extends Shape {
16
60
  constructor(config) {
61
+ // call super constructor
17
62
  super(config);
18
- this.dummyCanvas = Util.createCanvasElement();
19
63
  this.dataArray = [];
20
64
  this._readDataAttribute();
21
- this.on('dataChange.konva', function () {
22
- this._readDataAttribute();
23
- this._setTextData();
24
- });
25
- this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva directionChange.konva', this._setTextData);
26
65
  this._setTextData();
27
66
  }
28
67
  _getTextPathLength() {
29
68
  return Path.getPathLength(this.dataArray);
30
69
  }
31
70
  _getPointAtLength(length) {
71
+ // if path is not defined yet, do nothing
32
72
  if (!this.attrs.data) {
33
73
  return null;
34
74
  }
@@ -70,10 +110,18 @@ export class TextPath extends Shape {
70
110
  context.lineTo(glyphInfo[i].width, fontSize / 2 + 1);
71
111
  }
72
112
  context.restore();
113
+ //// To assist with debugging visually, uncomment following
114
+ //
115
+ // if (i % 2) context.strokeStyle = 'cyan';
116
+ // else context.strokeStyle = 'green';
117
+ // var p1 = glyphInfo[i].p1;
118
+ // context.moveTo(p0.x, p0.y);
119
+ // context.lineTo(p1.x, p1.y);
120
+ // context.stroke();
73
121
  }
74
122
  if (hasUnderline) {
75
123
  context.strokeStyle = fill;
76
- context.lineWidth = fontSize / 20;
124
+ context.lineWidth = getDecorationLineWidth(fontSize);
77
125
  context.stroke();
78
126
  }
79
127
  if (hasLineThrough) {
@@ -90,7 +138,7 @@ export class TextPath extends Shape {
90
138
  context.restore();
91
139
  }
92
140
  context.strokeStyle = fill;
93
- context.lineWidth = fontSize / 20;
141
+ context.lineWidth = getDecorationLineWidth(fontSize);
94
142
  context.stroke();
95
143
  }
96
144
  context.restore();
@@ -110,6 +158,11 @@ export class TextPath extends Shape {
110
158
  context.setAttr('strokeStyle', this.colorKey);
111
159
  context.stroke();
112
160
  }
161
+ /**
162
+ * get text width in pixels
163
+ * @method
164
+ * @name Konva.TextPath#getTextWidth
165
+ */
113
166
  getTextWidth() {
114
167
  return this.textWidth;
115
168
  }
@@ -124,8 +177,7 @@ export class TextPath extends Shape {
124
177
  return Text.prototype._getContextFont.call(this);
125
178
  }
126
179
  _getTextSize(text) {
127
- const dummyCanvas = this.dummyCanvas;
128
- const _context = dummyCanvas.getContext('2d');
180
+ const _context = getDummyContext();
129
181
  _context.save();
130
182
  _context.font = this._getContextFont();
131
183
  const metrics = _context.measureText(text);
@@ -137,6 +189,12 @@ export class TextPath extends Shape {
137
189
  }
138
190
  _setTextData() {
139
191
  const charArr = stringToArray(this.text());
192
+ // For RTL scripts (Hebrew, Arabic, …) the path is still walked left to
193
+ // right by glyph index, so we lay glyphs out in reversed logical order.
194
+ // A reader scanning the path right-to-left then sees the text in its
195
+ // intended reading order. This does not perform full Unicode bidi or
196
+ // Arabic cursive shaping — those need a real shaping engine — but it
197
+ // makes pure RTL strings render in the right direction.
140
198
  if (this.direction() === 'rtl') {
141
199
  charArr.reverse();
142
200
  }
@@ -159,8 +217,14 @@ export class TextPath extends Shape {
159
217
  const letterSpacing = this.letterSpacing();
160
218
  const align = this.align();
161
219
  const kerningFunc = this.kerningFunc();
220
+ // The sum of individual character widths can exceed the whole-string width
221
+ // due to kerning (browsers place adjacent glyphs closer together than the
222
+ // individual measurements suggest). This difference is the maximum amount
223
+ // by which the accumulated glyph offset can legitimately overshoot the
224
+ // path length when the path is sized to match the visually-measured text.
162
225
  const kerningAdjustment = Math.max(0, width - fullTextWidth);
163
- const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
226
+ // defines the width of the text on a straight line
227
+ const textWidth = Math.max(this.textWidth + (charArr.length - 1) * letterSpacing, 0);
164
228
  let offset = 0;
165
229
  if (align === 'center') {
166
230
  offset = Math.max(0, this.pathLength / 2 - textWidth / 2);
@@ -168,6 +232,11 @@ export class TextPath extends Shape {
168
232
  if (align === 'right') {
169
233
  offset = Math.max(0, this.pathLength - textWidth);
170
234
  }
235
+ // Algorithm for calculating glyph positions:
236
+ // 1. Get the begging point of the glyph on the path using the offsetToGlyph,
237
+ // 2. Get the ending point of the glyph on the path using the offsetToGlyph plus glyph width,
238
+ // 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
239
+ // 4. Add glyph width to the offsetToGlyph and repeat
171
240
  let offsetToGlyph = offset;
172
241
  for (let i = 0; i < chars.length; i++) {
173
242
  const charStartPoint = this._getPointAtLength(offsetToGlyph);
@@ -180,6 +249,10 @@ export class TextPath extends Shape {
180
249
  glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
181
250
  }
182
251
  const charEndLength = offsetToGlyph + glyphWidth;
252
+ // When the path length is sized to match the visually-measured (kerned)
253
+ // text width, the accumulated per-glyph offset can exceed pathLength by
254
+ // up to kerningAdjustment pixels. Clamp to pathLength in that case so
255
+ // the last character is not silently dropped.
183
256
  const charEndPoint = this._getPointAtLength(charEndLength > this.pathLength &&
184
257
  charEndLength - this.pathLength <= kerningAdjustment
185
258
  ? this.pathLength
@@ -189,8 +262,9 @@ export class TextPath extends Shape {
189
262
  }
190
263
  const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
191
264
  let kern = 0;
192
- if (kerningFunc) {
265
+ if (kerningFunc && i > 0) {
193
266
  try {
267
+ // getKerning is a user provided getter. Make sure it never breaks our logic
194
268
  kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
195
269
  }
196
270
  catch (e) {
@@ -230,31 +304,15 @@ export class TextPath extends Shape {
230
304
  points.push(info.p1.x);
231
305
  points.push(info.p1.y);
232
306
  });
233
- let minX = points[0] || 0;
234
- let maxX = points[0] || 0;
235
- let minY = points[1] || 0;
236
- let maxY = points[1] || 0;
237
- let x, y;
238
- for (let i = 0; i < points.length / 2; i++) {
239
- x = points[i * 2];
240
- y = points[i * 2 + 1];
241
- minX = Math.min(minX, x);
242
- maxX = Math.max(maxX, x);
243
- minY = Math.min(minY, y);
244
- maxY = Math.max(maxY, y);
245
- }
307
+ const rect = Util._getPointsRect(points);
246
308
  const fontSize = this.fontSize();
247
309
  return {
248
- x: minX - fontSize / 2,
249
- y: minY - fontSize / 2,
250
- width: maxX - minX + fontSize,
251
- height: maxY - minY + fontSize,
310
+ x: rect.x - fontSize / 2,
311
+ y: rect.y - fontSize / 2,
312
+ width: rect.width + fontSize,
313
+ height: rect.height + fontSize,
252
314
  };
253
315
  }
254
- destroy() {
255
- Util.releaseCanvas(this.dummyCanvas);
256
- return super.destroy();
257
- }
258
316
  }
259
317
  TextPath.prototype._fillFunc = _fillFunc;
260
318
  TextPath.prototype._strokeFunc = _strokeFunc;
@@ -263,15 +321,201 @@ TextPath.prototype._strokeFuncHit = _strokeFunc;
263
321
  TextPath.prototype.className = 'TextPath';
264
322
  TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
265
323
  _registerNode(TextPath);
324
+ TextPath.prototype.on('dataChange.konva', function () {
325
+ this._readDataAttribute();
326
+ this._setTextData();
327
+ });
328
+ // update text data for certain attr changes
329
+ TextPath.prototype.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva fontStyleChange.konva fontVariantChange.konva directionChange.konva', function () {
330
+ this._setTextData();
331
+ });
332
+ /**
333
+ * get/set SVG path data string. This method
334
+ * also automatically parses the data string
335
+ * into a data array. Currently supported SVG data:
336
+ * M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z
337
+ * @name Konva.TextPath#data
338
+ * @method
339
+ * @param {String} data svg path string
340
+ * @returns {String}
341
+ * @example
342
+ * // get data
343
+ * var data = shape.data();
344
+ *
345
+ * // set data
346
+ * shape.data('M200,100h100v50z');
347
+ */
266
348
  Factory.addGetterSetter(TextPath, 'data');
349
+ /**
350
+ * get/set font family
351
+ * @name Konva.TextPath#fontFamily
352
+ * @method
353
+ * @param {String} fontFamily
354
+ * @returns {String}
355
+ * @example
356
+ * // get font family
357
+ * var fontFamily = shape.fontFamily();
358
+ *
359
+ * // set font family
360
+ * shape.fontFamily('Arial');
361
+ */
267
362
  Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
363
+ /**
364
+ * get/set font size in pixels
365
+ * @name Konva.TextPath#fontSize
366
+ * @method
367
+ * @param {Number} fontSize
368
+ * @returns {Number}
369
+ * @example
370
+ * // get font size
371
+ * var fontSize = shape.fontSize();
372
+ *
373
+ * // set font size to 22px
374
+ * shape.fontSize(22);
375
+ */
268
376
  Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
377
+ /**
378
+ * get/set font style. Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
379
+ * @name Konva.TextPath#fontStyle
380
+ * @method
381
+ * @param {String} fontStyle
382
+ * @returns {String}
383
+ * @example
384
+ * // get font style
385
+ * var fontStyle = shape.fontStyle();
386
+ *
387
+ * // set font style
388
+ * shape.fontStyle('bold');
389
+ */
269
390
  Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
391
+ /**
392
+ * get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'
393
+ * @name Konva.TextPath#align
394
+ * @method
395
+ * @param {String} align
396
+ * @returns {String}
397
+ * @example
398
+ * // get text align
399
+ * var align = text.align();
400
+ *
401
+ * // center text
402
+ * text.align('center');
403
+ *
404
+ * // align text to right
405
+ * text.align('right');
406
+ */
270
407
  Factory.addGetterSetter(TextPath, 'align', 'left');
408
+ /**
409
+ * get/set letter spacing. The default is 0.
410
+ * @name Konva.TextPath#letterSpacing
411
+ * @method
412
+ * @param {Number} letterSpacing
413
+ * @returns {Number}
414
+ * @example
415
+ * // get letter spacing value
416
+ * var letterSpacing = shape.letterSpacing();
417
+ *
418
+ * // set the letter spacing value
419
+ * shape.letterSpacing(2);
420
+ */
271
421
  Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
422
+ /**
423
+ * get/set text baseline. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'
424
+ * @name Konva.TextPath#textBaseline
425
+ * @method
426
+ * @param {String} textBaseline
427
+ * @returns {String}
428
+ * @example
429
+ * // get current text baseline
430
+ * var textBaseline = shape.textBaseline();
431
+ *
432
+ * // set new text baseline
433
+ * shape.textBaseline('top');
434
+ */
272
435
  Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
436
+ /**
437
+ * get/set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.
438
+ * @name Konva.TextPath#fontVariant
439
+ * @method
440
+ * @param {String} fontVariant
441
+ * @returns {String}
442
+ * @example
443
+ * // get font variant
444
+ * var fontVariant = shape.fontVariant();
445
+ *
446
+ * // set font variant
447
+ * shape.fontVariant('small-caps');
448
+ */
273
449
  Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
450
+ /**
451
+ * get/set text
452
+ * @name Konva.TextPath#getText
453
+ * @method
454
+ * @param {String} text
455
+ * @returns {String}
456
+ * @example
457
+ * // get text
458
+ * var text = text.text();
459
+ *
460
+ * // set text
461
+ * text.text('Hello world!');
462
+ */
274
463
  Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
464
+ /**
465
+ * get/set text decoration of a text. Can be '', 'underline', 'line-through', or a combination like 'underline line-through'.
466
+ * @name Konva.TextPath#textDecoration
467
+ * @method
468
+ * @param {String} textDecoration
469
+ * @returns {String}
470
+ * @example
471
+ * // get text decoration
472
+ * var textDecoration = shape.textDecoration();
473
+ *
474
+ * // underline text
475
+ * shape.textDecoration('underline');
476
+ *
477
+ * // line-through text
478
+ * shape.textDecoration('line-through');
479
+ *
480
+ * // combine both
481
+ * shape.textDecoration('underline line-through');
482
+ */
275
483
  Factory.addGetterSetter(TextPath, 'textDecoration', '');
484
+ /**
485
+ * get/set kerning function.
486
+ * @name Konva.TextPath#kerningFunc
487
+ * @method
488
+ * @param {String} kerningFunc
489
+ * @returns {String}
490
+ * @example
491
+ * // get text decoration
492
+ * var kerningFunc = text.kerningFunc();
493
+ *
494
+ * // center text
495
+ * text.kerningFunc(function(leftChar, rightChar) {
496
+ * return 1;
497
+ * });
498
+ */
276
499
  Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
500
+ /**
501
+ * get/set text direction. Can be 'inherit', 'ltr' or 'rtl'. Default is 'inherit'.
502
+ *
503
+ * Setting `'rtl'` reverses the per-glyph layout order along the path, so
504
+ * Hebrew/Arabic strings read correctly when scanned right-to-left. This is a
505
+ * pragmatic fix limited by canvas TextPath rendering: each glyph is still
506
+ * drawn independently, so Arabic cursive joining and full Unicode bidi
507
+ * reordering of mixed-direction text are not supported. For best results,
508
+ * pair `direction: 'rtl'` with `align: 'right'` so the text starts at the
509
+ * end of the path.
510
+ * @name Konva.TextPath#direction
511
+ * @method
512
+ * @param {String} direction
513
+ * @returns {String}
514
+ * @example
515
+ * // get direction
516
+ * var direction = textpath.direction();
517
+ *
518
+ * // set direction
519
+ * textpath.direction('rtl');
520
+ */
277
521
  Factory.addGetterSetter(TextPath, 'direction', 'inherit');