konva 10.3.2 → 10.4.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 +5 -1
  2. package/konva.js +1327 -1572
  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 +1 -0
  16. package/lib/DragAndDrop.js +66 -17
  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 +692 -30
  28. package/lib/Node.js +1534 -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 +81 -1
  34. package/lib/Stage.js +166 -7
  35. package/lib/Tween.d.ts +159 -4
  36. package/lib/Tween.js +243 -24
  37. package/lib/Util.d.ts +147 -4
  38. package/lib/Util.js +332 -82
  39. package/lib/Validators.d.ts +0 -2
  40. package/lib/Validators.js +3 -25
  41. package/lib/_CoreInternals.d.ts +10 -6
  42. package/lib/_CoreInternals.js +1 -0
  43. package/lib/_FullInternals.d.ts +15 -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 +40 -6
  101. package/lib/shapes/Path.js +187 -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 +108 -11
  117. package/lib/shapes/Transformer.js +744 -102
  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 +24 -21
package/lib/Tween.d.ts CHANGED
@@ -38,15 +38,44 @@ declare class TweenEngine {
38
38
  pause(): void;
39
39
  getTimer(): number;
40
40
  }
41
- export interface TweenConfig extends NodeConfig {
41
+ export interface TweenOwnConfig {
42
+ node: Node;
43
+ duration?: number;
42
44
  easing?: (typeof Easings)[keyof typeof Easings];
43
45
  yoyo?: boolean;
44
- onReset?: Function;
45
46
  onFinish?: Function;
46
47
  onUpdate?: Function;
47
- duration?: number;
48
- node: Node;
48
+ onReset?: Function;
49
+ }
50
+ export interface TweenConfig extends NodeConfig, TweenOwnConfig {
49
51
  }
52
+ /**
53
+ * Tween constructor. Tweens enable you to animate a node between the current state and a new state.
54
+ * You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
55
+ * a linear easing. For more tweening options, check out {@link Konva.Easings}
56
+ * @constructor
57
+ * @memberof Konva
58
+ * @example
59
+ * // instantiate new tween which fully rotates a node in 1 second
60
+ * var tween = new Konva.Tween({
61
+ * // list of tween specific properties
62
+ * node: node,
63
+ * duration: 1,
64
+ * easing: Konva.Easings.EaseInOut,
65
+ * yoyo: false, // play back and forth
66
+ * onUpdate: () => console.log('node attrs updated'),
67
+ * onFinish: () => console.log('finished'),
68
+ * // set new values for any attributes of a passed node
69
+ * rotation: 360,
70
+ * fill: 'red'
71
+ * });
72
+ *
73
+ * // play tween
74
+ * tween.play();
75
+ *
76
+ * // pause tween
77
+ * tween.pause();
78
+ */
50
79
  export declare class Tween {
51
80
  static attrs: {};
52
81
  static tweens: {};
@@ -61,30 +90,156 @@ export declare class Tween {
61
90
  _addAttr(key: any, end: any): void;
62
91
  _tweenFunc(i: any): void;
63
92
  _addListeners(): void;
93
+ /**
94
+ * play
95
+ * @method
96
+ * @name Konva.Tween#play
97
+ * @returns {Tween}
98
+ */
64
99
  play(): this;
100
+ /**
101
+ * reverse
102
+ * @method
103
+ * @name Konva.Tween#reverse
104
+ * @returns {Tween}
105
+ */
65
106
  reverse(): this;
107
+ /**
108
+ * reset
109
+ * @method
110
+ * @name Konva.Tween#reset
111
+ * @returns {Tween}
112
+ */
66
113
  reset(): this;
114
+ /**
115
+ * seek
116
+ * @method
117
+ * @name Konva.Tween#seek
118
+ * @param {Number} t time in seconds between 0 and the duration
119
+ * @returns {Tween}
120
+ */
67
121
  seek(t: any): this;
122
+ /**
123
+ * pause
124
+ * @method
125
+ * @name Konva.Tween#pause
126
+ * @returns {Tween}
127
+ */
68
128
  pause(): this;
129
+ /**
130
+ * finish
131
+ * @method
132
+ * @name Konva.Tween#finish
133
+ * @returns {Tween}
134
+ */
69
135
  finish(): this;
136
+ /**
137
+ * destroy
138
+ * @method
139
+ * @name Konva.Tween#destroy
140
+ */
70
141
  destroy(): void;
71
142
  }
143
+ /**
144
+ * @namespace Easings
145
+ * @memberof Konva
146
+ */
72
147
  export declare const Easings: {
148
+ /**
149
+ * back ease in
150
+ * @function
151
+ * @memberof Konva.Easings
152
+ */
73
153
  BackEaseIn(t: any, b: any, c: any, d: any): any;
154
+ /**
155
+ * back ease out
156
+ * @function
157
+ * @memberof Konva.Easings
158
+ */
74
159
  BackEaseOut(t: any, b: any, c: any, d: any): any;
160
+ /**
161
+ * back ease in out
162
+ * @function
163
+ * @memberof Konva.Easings
164
+ */
75
165
  BackEaseInOut(t: any, b: any, c: any, d: any): any;
166
+ /**
167
+ * elastic ease in
168
+ * @function
169
+ * @memberof Konva.Easings
170
+ */
76
171
  ElasticEaseIn(t: any, b: any, c: any, d: any, a: any, p: any): any;
172
+ /**
173
+ * elastic ease out
174
+ * @function
175
+ * @memberof Konva.Easings
176
+ */
77
177
  ElasticEaseOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
178
+ /**
179
+ * elastic ease in out
180
+ * @function
181
+ * @memberof Konva.Easings
182
+ */
78
183
  ElasticEaseInOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
184
+ /**
185
+ * bounce ease out
186
+ * @function
187
+ * @memberof Konva.Easings
188
+ */
79
189
  BounceEaseOut(t: any, b: any, c: any, d: any): any;
190
+ /**
191
+ * bounce ease in
192
+ * @function
193
+ * @memberof Konva.Easings
194
+ */
80
195
  BounceEaseIn(t: any, b: any, c: any, d: any): any;
196
+ /**
197
+ * bounce ease in out
198
+ * @function
199
+ * @memberof Konva.Easings
200
+ */
81
201
  BounceEaseInOut(t: any, b: any, c: any, d: any): any;
202
+ /**
203
+ * ease in
204
+ * @function
205
+ * @memberof Konva.Easings
206
+ */
82
207
  EaseIn(t: any, b: any, c: any, d: any): any;
208
+ /**
209
+ * ease out
210
+ * @function
211
+ * @memberof Konva.Easings
212
+ */
83
213
  EaseOut(t: any, b: any, c: any, d: any): any;
214
+ /**
215
+ * ease in out
216
+ * @function
217
+ * @memberof Konva.Easings
218
+ */
84
219
  EaseInOut(t: any, b: any, c: any, d: any): any;
220
+ /**
221
+ * strong ease in
222
+ * @function
223
+ * @memberof Konva.Easings
224
+ */
85
225
  StrongEaseIn(t: any, b: any, c: any, d: any): any;
226
+ /**
227
+ * strong ease out
228
+ * @function
229
+ * @memberof Konva.Easings
230
+ */
86
231
  StrongEaseOut(t: any, b: any, c: any, d: any): any;
232
+ /**
233
+ * strong ease in out
234
+ * @function
235
+ * @memberof Konva.Easings
236
+ */
87
237
  StrongEaseInOut(t: any, b: any, c: any, d: any): any;
238
+ /**
239
+ * linear
240
+ * @function
241
+ * @memberof Konva.Easings
242
+ */
88
243
  Linear(t: any, b: any, c: any, d: any): any;
89
244
  };
90
245
  export {};
package/lib/Tween.js CHANGED
@@ -2,14 +2,19 @@ import { Util } from "./Util.js";
2
2
  import { Animation } from "./Animation.js";
3
3
  import { Node } from "./Node.js";
4
4
  import { Konva } from "./Global.js";
5
+ // every config key that is not an attribute to tween
5
6
  const blacklist = {
6
7
  node: 1,
7
8
  duration: 1,
8
9
  easing: 1,
9
10
  onFinish: 1,
11
+ onUpdate: 1,
12
+ onReset: 1,
10
13
  yoyo: 1,
11
14
  }, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
12
15
  let idCounter = 0;
16
+ // the diff below reads r/g/b/a directly, so a color we can not parse must fail
17
+ // with its own message instead of "Cannot read properties of undefined"
13
18
  function colorToRGBA(color) {
14
19
  return (Util.colorToRGBA(color) ||
15
20
  Util.throw('can not tween the color "' +
@@ -127,9 +132,36 @@ class TweenEngine {
127
132
  this.fire('onPause');
128
133
  }
129
134
  getTimer() {
130
- return new Date().getTime();
135
+ return Date.now();
131
136
  }
132
137
  }
138
+ /**
139
+ * Tween constructor. Tweens enable you to animate a node between the current state and a new state.
140
+ * You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
141
+ * a linear easing. For more tweening options, check out {@link Konva.Easings}
142
+ * @constructor
143
+ * @memberof Konva
144
+ * @example
145
+ * // instantiate new tween which fully rotates a node in 1 second
146
+ * var tween = new Konva.Tween({
147
+ * // list of tween specific properties
148
+ * node: node,
149
+ * duration: 1,
150
+ * easing: Konva.Easings.EaseInOut,
151
+ * yoyo: false, // play back and forth
152
+ * onUpdate: () => console.log('node attrs updated'),
153
+ * onFinish: () => console.log('finished'),
154
+ * // set new values for any attributes of a passed node
155
+ * rotation: 360,
156
+ * fill: 'red'
157
+ * });
158
+ *
159
+ * // play tween
160
+ * tween.play();
161
+ *
162
+ * // pause tween
163
+ * tween.pause();
164
+ */
133
165
  export class Tween {
134
166
  constructor(config) {
135
167
  const that = this, node = config.node, nodeId = node._id, easing = config.easing || Easings.Linear, yoyo = !!config.yoyo;
@@ -138,6 +170,7 @@ export class Tween {
138
170
  duration = 0.3;
139
171
  }
140
172
  else if (config.duration === 0) {
173
+ // zero is bad value for duration
141
174
  duration = 0.001;
142
175
  }
143
176
  else {
@@ -157,12 +190,14 @@ export class Tween {
157
190
  that._tweenFunc(i);
158
191
  }, easing, 0, 1, duration * 1000, yoyo);
159
192
  this._addListeners();
193
+ // init attrs map
160
194
  if (!Tween.attrs[nodeId]) {
161
195
  Tween.attrs[nodeId] = {};
162
196
  }
163
197
  if (!Tween.attrs[nodeId][this._id]) {
164
198
  Tween.attrs[nodeId][this._id] = {};
165
199
  }
200
+ // init tweens map
166
201
  if (!Tween.tweens[nodeId]) {
167
202
  Tween.tweens[nodeId] = {};
168
203
  }
@@ -172,27 +207,45 @@ export class Tween {
172
207
  }
173
208
  }
174
209
  this.reset();
210
+ // callbacks
175
211
  this.onFinish = config.onFinish;
176
212
  this.onReset = config.onReset;
177
213
  this.onUpdate = config.onUpdate;
178
214
  }
179
215
  _addAttr(key, end) {
216
+ // a component attribute ({x, y} of scale, offset, a gradient point...)
217
+ // is tweened through its components: scale -> scaleX, scaleY
218
+ if (Util._isPlainObject(end)) {
219
+ for (const component in end) {
220
+ this._addAttr(key + Util._capitalize(component), end[component]);
221
+ }
222
+ return;
223
+ }
180
224
  const node = this.node, nodeId = node._id;
181
225
  let diff, len, trueEnd, trueStart, endRGBA;
226
+ // remove conflict from tween map if it exists
182
227
  const tweenId = Tween.tweens[nodeId][key];
183
- if (tweenId) {
228
+ if (tweenId !== undefined) {
184
229
  delete Tween.attrs[nodeId][tweenId][key];
185
230
  }
231
+ // add to tween map
186
232
  let start = node.getAttr(key);
187
233
  if (Util._isArray(end)) {
188
234
  diff = [];
235
+ // an attribute the node does not have yet starts from zeros. A copy,
236
+ // as the colour stops are replaced by RGBA objects below
237
+ start = (start || []).slice();
189
238
  len = Math.max(end.length, start.length);
190
239
  if (key === 'points' && end.length !== start.length) {
240
+ // before tweening points we need to make sure that start.length === end.length
241
+ // Util._prepareArrayForTween thinking that end.length > start.length
191
242
  if (end.length > start.length) {
243
+ // so in this case we will increase number of starting points
192
244
  trueStart = start;
193
245
  start = Util._prepareArrayForTween(start, end, node.closed());
194
246
  }
195
247
  else {
248
+ // in this case we will increase number of eding points
196
249
  trueEnd = end;
197
250
  end = Util._prepareArrayForTween(end, start, node.closed());
198
251
  }
@@ -200,7 +253,7 @@ export class Tween {
200
253
  if (key.indexOf('fill') === 0) {
201
254
  for (let n = 0; n < len; n++) {
202
255
  if (n % 2 === 0) {
203
- diff.push(end[n] - start[n]);
256
+ diff.push(end[n] - (start[n] || 0));
204
257
  }
205
258
  else {
206
259
  const startRGBA = colorToRGBA(start[n]);
@@ -217,7 +270,7 @@ export class Tween {
217
270
  }
218
271
  else {
219
272
  for (let n = 0; n < len; n++) {
220
- diff.push(end[n] - start[n]);
273
+ diff.push(end[n] - (start[n] || 0));
221
274
  }
222
275
  }
223
276
  }
@@ -297,17 +350,25 @@ export class Tween {
297
350
  }
298
351
  }
299
352
  _addListeners() {
300
- this.tween.onPlay = () => {
301
- this.anim.start();
302
- };
303
- this.tween.onReverse = () => {
353
+ // a running tween is destroyed with its node (the animation loop would
354
+ // keep both alive); a stopped one is not held by the node at all.
355
+ // The namespace contains "konva" so clone() does not copy the listener
356
+ const destroyEvent = `destroy.konva-tween${this._id}`;
357
+ const onDestroy = () => this.destroy();
358
+ const start = () => {
359
+ this.node.off(destroyEvent).on(destroyEvent, onDestroy);
304
360
  this.anim.start();
305
361
  };
362
+ this.tween.onPlay = start;
363
+ this.tween.onReverse = start;
364
+ // stop listeners
306
365
  this.tween.onPause = () => {
366
+ this.node.off(destroyEvent);
307
367
  this.anim.stop();
308
368
  };
309
369
  this.tween.onFinish = () => {
310
370
  const node = this.node;
371
+ // after tweening points of line we need to set original end
311
372
  const attrs = Tween.attrs[node._id][this._id];
312
373
  if (attrs.points && attrs.points.trueEnd) {
313
374
  node.setAttr('points', attrs.points.trueEnd);
@@ -318,6 +379,7 @@ export class Tween {
318
379
  };
319
380
  this.tween.onReset = () => {
320
381
  const node = this.node;
382
+ // after tweening points of line we need to set original start
321
383
  const attrs = Tween.attrs[node._id][this._id];
322
384
  if (attrs.points && attrs.points.trueStart) {
323
385
  node.points(attrs.points.trueStart);
@@ -332,44 +394,91 @@ export class Tween {
332
394
  }
333
395
  };
334
396
  }
397
+ /**
398
+ * play
399
+ * @method
400
+ * @name Konva.Tween#play
401
+ * @returns {Tween}
402
+ */
335
403
  play() {
336
404
  this.tween.play();
337
405
  return this;
338
406
  }
407
+ /**
408
+ * reverse
409
+ * @method
410
+ * @name Konva.Tween#reverse
411
+ * @returns {Tween}
412
+ */
339
413
  reverse() {
340
414
  this.tween.reverse();
341
415
  return this;
342
416
  }
417
+ /**
418
+ * reset
419
+ * @method
420
+ * @name Konva.Tween#reset
421
+ * @returns {Tween}
422
+ */
343
423
  reset() {
344
424
  this.tween.reset();
345
425
  return this;
346
426
  }
427
+ /**
428
+ * seek
429
+ * @method
430
+ * @name Konva.Tween#seek
431
+ * @param {Number} t time in seconds between 0 and the duration
432
+ * @returns {Tween}
433
+ */
347
434
  seek(t) {
348
435
  this.tween.seek(t * 1000);
349
436
  return this;
350
437
  }
438
+ /**
439
+ * pause
440
+ * @method
441
+ * @name Konva.Tween#pause
442
+ * @returns {Tween}
443
+ */
351
444
  pause() {
352
445
  this.tween.pause();
353
446
  return this;
354
447
  }
448
+ /**
449
+ * finish
450
+ * @method
451
+ * @name Konva.Tween#finish
452
+ * @returns {Tween}
453
+ */
355
454
  finish() {
356
455
  this.tween.finish();
357
456
  return this;
358
457
  }
458
+ /**
459
+ * destroy
460
+ * @method
461
+ * @name Konva.Tween#destroy
462
+ */
359
463
  destroy() {
360
- const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
464
+ var _a;
465
+ const nodeId = this.node._id, thisId = this._id, owned = (_a = Tween.attrs[nodeId]) === null || _a === void 0 ? void 0 : _a[thisId], owners = Tween.tweens[nodeId];
361
466
  this.pause();
362
467
  if (this.anim) {
363
468
  this.anim.stop();
364
469
  }
365
- for (const key in attrs) {
366
- delete Tween.tweens[nodeId][key];
367
- }
368
- delete Tween.attrs[nodeId][thisId];
369
- if (Tween.tweens[nodeId]) {
370
- if (Object.keys(Tween.tweens[nodeId]).length === 0) {
371
- delete Tween.tweens[nodeId];
470
+ // release only the attributes this tween still owns, other tweens on
471
+ // the node keep theirs (nothing left to do when destroyed twice)
472
+ if (owned) {
473
+ if (owners) {
474
+ for (const key in owned) {
475
+ delete owners[key];
476
+ }
477
+ if (Object.keys(owners).length === 0) {
478
+ delete Tween.tweens[nodeId];
479
+ }
372
480
  }
481
+ delete Tween.attrs[nodeId][thisId];
373
482
  if (Object.keys(Tween.attrs[nodeId]).length === 0) {
374
483
  delete Tween.attrs[nodeId];
375
484
  }
@@ -378,27 +487,69 @@ export class Tween {
378
487
  }
379
488
  Tween.attrs = {};
380
489
  Tween.tweens = {};
490
+ /**
491
+ * Tween node properties. Shorter usage of {@link Konva.Tween} object.
492
+ *
493
+ * @method Konva.Node#to
494
+ * @param {Object} [params] tween params
495
+ * @returns {Konva.Tween}
496
+ * @example
497
+ *
498
+ * circle.to({
499
+ * x : 50,
500
+ * duration : 0.5,
501
+ * onUpdate: () => console.log('props updated'),
502
+ * onFinish: () => console.log('finished'),
503
+ * });
504
+ */
381
505
  Node.prototype.to = function (params) {
382
506
  const onFinish = params.onFinish;
383
- params.node = this;
384
- params.onFinish = function () {
385
- this.destroy();
386
- if (onFinish) {
387
- onFinish();
388
- }
389
- };
390
- const tween = new Tween(params);
507
+ // params stay untouched, so the same object can animate several nodes
508
+ const tween = new Tween({
509
+ ...params,
510
+ node: this,
511
+ onFinish() {
512
+ tween.destroy();
513
+ if (onFinish) {
514
+ onFinish();
515
+ }
516
+ },
517
+ });
391
518
  tween.play();
519
+ return tween;
392
520
  };
521
+ /*
522
+ * These eases were ported from an Adobe Flash tweening library to JavaScript
523
+ * by Xaric
524
+ */
525
+ /**
526
+ * @namespace Easings
527
+ * @memberof Konva
528
+ */
393
529
  export const Easings = {
530
+ /**
531
+ * back ease in
532
+ * @function
533
+ * @memberof Konva.Easings
534
+ */
394
535
  BackEaseIn(t, b, c, d) {
395
536
  const s = 1.70158;
396
537
  return c * (t /= d) * t * ((s + 1) * t - s) + b;
397
538
  },
539
+ /**
540
+ * back ease out
541
+ * @function
542
+ * @memberof Konva.Easings
543
+ */
398
544
  BackEaseOut(t, b, c, d) {
399
545
  const s = 1.70158;
400
546
  return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
401
547
  },
548
+ /**
549
+ * back ease in out
550
+ * @function
551
+ * @memberof Konva.Easings
552
+ */
402
553
  BackEaseInOut(t, b, c, d) {
403
554
  let s = 1.70158;
404
555
  if ((t /= d / 2) < 1) {
@@ -406,7 +557,13 @@ export const Easings = {
406
557
  }
407
558
  return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
408
559
  },
560
+ /**
561
+ * elastic ease in
562
+ * @function
563
+ * @memberof Konva.Easings
564
+ */
409
565
  ElasticEaseIn(t, b, c, d, a, p) {
566
+ // added s = 0
410
567
  let s = 0;
411
568
  if (t === 0) {
412
569
  return b;
@@ -428,7 +585,13 @@ export const Easings = {
428
585
  Math.pow(2, 10 * (t -= 1)) *
429
586
  Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b);
430
587
  },
588
+ /**
589
+ * elastic ease out
590
+ * @function
591
+ * @memberof Konva.Easings
592
+ */
431
593
  ElasticEaseOut(t, b, c, d, a, p) {
594
+ // added s = 0
432
595
  let s = 0;
433
596
  if (t === 0) {
434
597
  return b;
@@ -450,7 +613,13 @@ export const Easings = {
450
613
  c +
451
614
  b);
452
615
  },
616
+ /**
617
+ * elastic ease in out
618
+ * @function
619
+ * @memberof Konva.Easings
620
+ */
453
621
  ElasticEaseInOut(t, b, c, d, a, p) {
622
+ // added s = 0
454
623
  let s = 0;
455
624
  if (t === 0) {
456
625
  return b;
@@ -482,6 +651,11 @@ export const Easings = {
482
651
  c +
483
652
  b);
484
653
  },
654
+ /**
655
+ * bounce ease out
656
+ * @function
657
+ * @memberof Konva.Easings
658
+ */
485
659
  BounceEaseOut(t, b, c, d) {
486
660
  if ((t /= d) < 1 / 2.75) {
487
661
  return c * (7.5625 * t * t) + b;
@@ -496,9 +670,19 @@ export const Easings = {
496
670
  return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b;
497
671
  }
498
672
  },
673
+ /**
674
+ * bounce ease in
675
+ * @function
676
+ * @memberof Konva.Easings
677
+ */
499
678
  BounceEaseIn(t, b, c, d) {
500
679
  return c - Easings.BounceEaseOut(d - t, 0, c, d) + b;
501
680
  },
681
+ /**
682
+ * bounce ease in out
683
+ * @function
684
+ * @memberof Konva.Easings
685
+ */
502
686
  BounceEaseInOut(t, b, c, d) {
503
687
  if (t < d / 2) {
504
688
  return Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
@@ -507,30 +691,65 @@ export const Easings = {
507
691
  return Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
508
692
  }
509
693
  },
694
+ /**
695
+ * ease in
696
+ * @function
697
+ * @memberof Konva.Easings
698
+ */
510
699
  EaseIn(t, b, c, d) {
511
700
  return c * (t /= d) * t + b;
512
701
  },
702
+ /**
703
+ * ease out
704
+ * @function
705
+ * @memberof Konva.Easings
706
+ */
513
707
  EaseOut(t, b, c, d) {
514
708
  return -c * (t /= d) * (t - 2) + b;
515
709
  },
710
+ /**
711
+ * ease in out
712
+ * @function
713
+ * @memberof Konva.Easings
714
+ */
516
715
  EaseInOut(t, b, c, d) {
517
716
  if ((t /= d / 2) < 1) {
518
717
  return (c / 2) * t * t + b;
519
718
  }
520
719
  return (-c / 2) * (--t * (t - 2) - 1) + b;
521
720
  },
721
+ /**
722
+ * strong ease in
723
+ * @function
724
+ * @memberof Konva.Easings
725
+ */
522
726
  StrongEaseIn(t, b, c, d) {
523
727
  return c * (t /= d) * t * t * t * t + b;
524
728
  },
729
+ /**
730
+ * strong ease out
731
+ * @function
732
+ * @memberof Konva.Easings
733
+ */
525
734
  StrongEaseOut(t, b, c, d) {
526
735
  return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
527
736
  },
737
+ /**
738
+ * strong ease in out
739
+ * @function
740
+ * @memberof Konva.Easings
741
+ */
528
742
  StrongEaseInOut(t, b, c, d) {
529
743
  if ((t /= d / 2) < 1) {
530
744
  return (c / 2) * t * t * t * t * t + b;
531
745
  }
532
746
  return (c / 2) * ((t -= 2) * t * t * t * t + 2) + b;
533
747
  },
748
+ /**
749
+ * linear
750
+ * @function
751
+ * @memberof Konva.Easings
752
+ */
534
753
  Linear(t, b, c, d) {
535
754
  return (c * t) / d + b;
536
755
  },