konva 8.4.3 → 9.0.1

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 (192) hide show
  1. package/README.md +1 -9
  2. package/konva.js +17691 -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.d.ts +1 -0
  20. package/lib/Node.js +105 -104
  21. package/lib/PointerEvents.js +15 -7
  22. package/lib/Shape.js +90 -86
  23. package/lib/Stage.js +51 -47
  24. package/lib/Tween.js +26 -22
  25. package/lib/Util.js +29 -25
  26. package/lib/Validators.js +58 -44
  27. package/lib/_CoreInternals.js +36 -33
  28. package/lib/_FullInternals.js +78 -75
  29. package/lib/filters/Blur.js +9 -5
  30. package/lib/filters/Brighten.js +9 -5
  31. package/lib/filters/Contrast.js +9 -5
  32. package/lib/filters/Emboss.js +14 -10
  33. package/lib/filters/Enhance.js +9 -5
  34. package/lib/filters/Grayscale.js +5 -1
  35. package/lib/filters/HSL.js +11 -7
  36. package/lib/filters/HSV.js +11 -7
  37. package/lib/filters/Invert.js +5 -1
  38. package/lib/filters/Kaleidoscope.js +13 -9
  39. package/lib/filters/Mask.js +9 -5
  40. package/lib/filters/Noise.js +9 -5
  41. package/lib/filters/Pixelate.js +11 -7
  42. package/lib/filters/Posterize.js +9 -5
  43. package/lib/filters/RGB.js +11 -7
  44. package/lib/filters/RGBA.js +12 -8
  45. package/lib/filters/Sepia.js +5 -1
  46. package/lib/filters/Solarize.js +5 -1
  47. package/lib/filters/Threshold.js +9 -5
  48. package/lib/index-node.js +7 -5
  49. package/lib/index.js +4 -2
  50. package/lib/shapes/Arc.js +17 -13
  51. package/lib/shapes/Arrow.js +17 -13
  52. package/lib/shapes/Circle.js +11 -7
  53. package/lib/shapes/Ellipse.js +13 -9
  54. package/lib/shapes/Image.js +21 -17
  55. package/lib/shapes/Label.js +18 -13
  56. package/lib/shapes/Line.js +14 -10
  57. package/lib/shapes/Path.d.ts +5 -2
  58. package/lib/shapes/Path.js +44 -43
  59. package/lib/shapes/Rect.js +13 -9
  60. package/lib/shapes/RegularPolygon.js +12 -8
  61. package/lib/shapes/Ring.js +12 -8
  62. package/lib/shapes/Sprite.js +19 -15
  63. package/lib/shapes/Star.js +13 -9
  64. package/lib/shapes/Text.js +31 -26
  65. package/lib/shapes/TextPath.d.ts +5 -1
  66. package/lib/shapes/TextPath.js +82 -188
  67. package/lib/shapes/Transformer.d.ts +2 -0
  68. package/lib/shapes/Transformer.js +97 -82
  69. package/lib/shapes/Wedge.js +16 -12
  70. package/lib/types.d.ts +6 -0
  71. package/lib/types.js +5 -2
  72. package/package.json +13 -42
  73. package/cmj/Animation.d.ts +0 -24
  74. package/cmj/Animation.js +0 -145
  75. package/cmj/Canvas.d.ts +0 -32
  76. package/cmj/Canvas.js +0 -114
  77. package/cmj/Container.d.ts +0 -47
  78. package/cmj/Container.js +0 -325
  79. package/cmj/Context.d.ts +0 -85
  80. package/cmj/Context.js +0 -538
  81. package/cmj/Core.d.ts +0 -3
  82. package/cmj/Core.js +0 -7
  83. package/cmj/DragAndDrop.d.ts +0 -17
  84. package/cmj/DragAndDrop.js +0 -111
  85. package/cmj/Factory.d.ts +0 -11
  86. package/cmj/Factory.js +0 -125
  87. package/cmj/FastLayer.d.ts +0 -4
  88. package/cmj/FastLayer.js +0 -16
  89. package/cmj/Global.d.ts +0 -34
  90. package/cmj/Global.js +0 -61
  91. package/cmj/Group.d.ts +0 -8
  92. package/cmj/Group.js +0 -17
  93. package/cmj/Layer.d.ts +0 -61
  94. package/cmj/Layer.js +0 -309
  95. package/cmj/Node.d.ts +0 -328
  96. package/cmj/Node.js +0 -1420
  97. package/cmj/PointerEvents.d.ts +0 -11
  98. package/cmj/PointerEvents.js +0 -45
  99. package/cmj/Shape.d.ts +0 -186
  100. package/cmj/Shape.js +0 -521
  101. package/cmj/Stage.d.ts +0 -85
  102. package/cmj/Stage.js +0 -692
  103. package/cmj/Tween.d.ts +0 -86
  104. package/cmj/Tween.js +0 -520
  105. package/cmj/Util.d.ts +0 -91
  106. package/cmj/Util.js +0 -801
  107. package/cmj/Validators.d.ts +0 -11
  108. package/cmj/Validators.js +0 -192
  109. package/cmj/_CoreInternals.d.ts +0 -152
  110. package/cmj/_CoreInternals.js +0 -37
  111. package/cmj/_FullInternals.d.ts +0 -196
  112. package/cmj/_FullInternals.js +0 -81
  113. package/cmj/filters/Blur.d.ts +0 -2
  114. package/cmj/filters/Blur.js +0 -701
  115. package/cmj/filters/Brighten.d.ts +0 -2
  116. package/cmj/filters/Brighten.js +0 -16
  117. package/cmj/filters/Contrast.d.ts +0 -2
  118. package/cmj/filters/Contrast.js +0 -38
  119. package/cmj/filters/Emboss.d.ts +0 -2
  120. package/cmj/filters/Emboss.js +0 -106
  121. package/cmj/filters/Enhance.d.ts +0 -2
  122. package/cmj/filters/Enhance.js +0 -87
  123. package/cmj/filters/Grayscale.d.ts +0 -2
  124. package/cmj/filters/Grayscale.js +0 -13
  125. package/cmj/filters/HSL.d.ts +0 -2
  126. package/cmj/filters/HSL.js +0 -28
  127. package/cmj/filters/HSV.d.ts +0 -2
  128. package/cmj/filters/HSV.js +0 -28
  129. package/cmj/filters/Invert.d.ts +0 -2
  130. package/cmj/filters/Invert.js +0 -12
  131. package/cmj/filters/Kaleidoscope.d.ts +0 -2
  132. package/cmj/filters/Kaleidoscope.js +0 -137
  133. package/cmj/filters/Mask.d.ts +0 -2
  134. package/cmj/filters/Mask.js +0 -144
  135. package/cmj/filters/Noise.d.ts +0 -2
  136. package/cmj/filters/Noise.js +0 -16
  137. package/cmj/filters/Pixelate.d.ts +0 -2
  138. package/cmj/filters/Pixelate.js +0 -64
  139. package/cmj/filters/Posterize.d.ts +0 -2
  140. package/cmj/filters/Posterize.js +0 -14
  141. package/cmj/filters/RGB.d.ts +0 -2
  142. package/cmj/filters/RGB.js +0 -43
  143. package/cmj/filters/RGBA.d.ts +0 -2
  144. package/cmj/filters/RGBA.js +0 -53
  145. package/cmj/filters/Sepia.d.ts +0 -2
  146. package/cmj/filters/Sepia.js +0 -15
  147. package/cmj/filters/Solarize.d.ts +0 -2
  148. package/cmj/filters/Solarize.js +0 -29
  149. package/cmj/filters/Threshold.d.ts +0 -2
  150. package/cmj/filters/Threshold.js +0 -14
  151. package/cmj/index-node.d.ts +0 -2
  152. package/cmj/index-node.js +0 -21
  153. package/cmj/index-types.d.ts +0 -181
  154. package/cmj/index.d.ts +0 -2
  155. package/cmj/index.js +0 -4
  156. package/cmj/package.json +0 -6
  157. package/cmj/shapes/Arc.d.ts +0 -26
  158. package/cmj/shapes/Arc.js +0 -59
  159. package/cmj/shapes/Arrow.d.ts +0 -26
  160. package/cmj/shapes/Arrow.js +0 -103
  161. package/cmj/shapes/Circle.d.ts +0 -14
  162. package/cmj/shapes/Circle.js +0 -37
  163. package/cmj/shapes/Ellipse.d.ts +0 -17
  164. package/cmj/shapes/Ellipse.js +0 -41
  165. package/cmj/shapes/Image.d.ts +0 -25
  166. package/cmj/shapes/Image.js +0 -117
  167. package/cmj/shapes/Label.d.ts +0 -36
  168. package/cmj/shapes/Label.js +0 -178
  169. package/cmj/shapes/Line.d.ts +0 -28
  170. package/cmj/shapes/Line.js +0 -159
  171. package/cmj/shapes/Path.d.ts +0 -37
  172. package/cmj/shapes/Path.js +0 -631
  173. package/cmj/shapes/Rect.d.ts +0 -10
  174. package/cmj/shapes/Rect.js +0 -26
  175. package/cmj/shapes/RegularPolygon.d.ts +0 -23
  176. package/cmj/shapes/RegularPolygon.js +0 -69
  177. package/cmj/shapes/Ring.d.ts +0 -16
  178. package/cmj/shapes/Ring.js +0 -37
  179. package/cmj/shapes/Sprite.d.ts +0 -31
  180. package/cmj/shapes/Sprite.js +0 -112
  181. package/cmj/shapes/Star.d.ts +0 -18
  182. package/cmj/shapes/Star.js +0 -42
  183. package/cmj/shapes/Text.d.ts +0 -63
  184. package/cmj/shapes/Text.js +0 -373
  185. package/cmj/shapes/TextPath.d.ts +0 -56
  186. package/cmj/shapes/TextPath.js +0 -351
  187. package/cmj/shapes/Transformer.d.ts +0 -116
  188. package/cmj/shapes/Transformer.js +0 -971
  189. package/cmj/shapes/Wedge.d.ts +0 -18
  190. package/cmj/shapes/Wedge.js +0 -42
  191. package/cmj/types.d.ts +0 -50
  192. package/cmj/types.js +0 -25
package/cmj/Tween.d.ts DELETED
@@ -1,86 +0,0 @@
1
- import { Animation } from './Animation';
2
- import { Node, NodeConfig } from './Node';
3
- declare class TweenEngine {
4
- prop: string;
5
- propFunc: Function;
6
- begin: number;
7
- _pos: number;
8
- duration: number;
9
- prevPos: number;
10
- yoyo: boolean;
11
- _time: number;
12
- _position: number;
13
- _startTime: number;
14
- _finish: number;
15
- func: Function;
16
- _change: number;
17
- state: number;
18
- onPlay: Function;
19
- onReverse: Function;
20
- onPause: Function;
21
- onReset: Function;
22
- onFinish: Function;
23
- onUpdate: Function;
24
- constructor(prop: any, propFunc: any, func: any, begin: any, finish: any, duration: any, yoyo: any);
25
- fire(str: any): void;
26
- setTime(t: any): void;
27
- getTime(): number;
28
- setPosition(p: any): void;
29
- getPosition(t: any): any;
30
- play(): void;
31
- reverse(): void;
32
- seek(t: any): void;
33
- reset(): void;
34
- finish(): void;
35
- update(): void;
36
- onEnterFrame(): void;
37
- pause(): void;
38
- getTimer(): number;
39
- }
40
- export interface TweenConfig extends NodeConfig {
41
- onFinish?: Function;
42
- onUpdate?: Function;
43
- duration?: number;
44
- node: Node;
45
- }
46
- export declare class Tween {
47
- static attrs: {};
48
- static tweens: {};
49
- node: Node;
50
- anim: Animation;
51
- tween: TweenEngine;
52
- _id: number;
53
- onFinish: Function;
54
- onReset: Function;
55
- onUpdate: Function;
56
- constructor(config: TweenConfig);
57
- _addAttr(key: any, end: any): void;
58
- _tweenFunc(i: any): void;
59
- _addListeners(): void;
60
- play(): this;
61
- reverse(): this;
62
- reset(): this;
63
- seek(t: any): this;
64
- pause(): this;
65
- finish(): this;
66
- destroy(): void;
67
- }
68
- export declare const Easings: {
69
- BackEaseIn(t: any, b: any, c: any, d: any): any;
70
- BackEaseOut(t: any, b: any, c: any, d: any): any;
71
- BackEaseInOut(t: any, b: any, c: any, d: any): any;
72
- ElasticEaseIn(t: any, b: any, c: any, d: any, a: any, p: any): any;
73
- ElasticEaseOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
74
- ElasticEaseInOut(t: any, b: any, c: any, d: any, a: any, p: any): any;
75
- BounceEaseOut(t: any, b: any, c: any, d: any): any;
76
- BounceEaseIn(t: any, b: any, c: any, d: any): any;
77
- BounceEaseInOut(t: any, b: any, c: any, d: any): any;
78
- EaseIn(t: any, b: any, c: any, d: any): any;
79
- EaseOut(t: any, b: any, c: any, d: any): any;
80
- EaseInOut(t: any, b: any, c: any, d: any): any;
81
- StrongEaseIn(t: any, b: any, c: any, d: any): any;
82
- StrongEaseOut(t: any, b: any, c: any, d: any): any;
83
- StrongEaseInOut(t: any, b: any, c: any, d: any): any;
84
- Linear(t: any, b: any, c: any, d: any): any;
85
- };
86
- export {};
package/cmj/Tween.js DELETED
@@ -1,520 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Easings = exports.Tween = void 0;
4
- const Util_1 = require("./Util");
5
- const Animation_1 = require("./Animation");
6
- const Node_1 = require("./Node");
7
- const Global_1 = require("./Global");
8
- var blacklist = {
9
- node: 1,
10
- duration: 1,
11
- easing: 1,
12
- onFinish: 1,
13
- yoyo: 1,
14
- }, PAUSED = 1, PLAYING = 2, REVERSING = 3, idCounter = 0, colorAttrs = ['fill', 'stroke', 'shadowColor'];
15
- class TweenEngine {
16
- constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
17
- this.prop = prop;
18
- this.propFunc = propFunc;
19
- this.begin = begin;
20
- this._pos = begin;
21
- this.duration = duration;
22
- this._change = 0;
23
- this.prevPos = 0;
24
- this.yoyo = yoyo;
25
- this._time = 0;
26
- this._position = 0;
27
- this._startTime = 0;
28
- this._finish = 0;
29
- this.func = func;
30
- this._change = finish - this.begin;
31
- this.pause();
32
- }
33
- fire(str) {
34
- var handler = this[str];
35
- if (handler) {
36
- handler();
37
- }
38
- }
39
- setTime(t) {
40
- if (t > this.duration) {
41
- if (this.yoyo) {
42
- this._time = this.duration;
43
- this.reverse();
44
- }
45
- else {
46
- this.finish();
47
- }
48
- }
49
- else if (t < 0) {
50
- if (this.yoyo) {
51
- this._time = 0;
52
- this.play();
53
- }
54
- else {
55
- this.reset();
56
- }
57
- }
58
- else {
59
- this._time = t;
60
- this.update();
61
- }
62
- }
63
- getTime() {
64
- return this._time;
65
- }
66
- setPosition(p) {
67
- this.prevPos = this._pos;
68
- this.propFunc(p);
69
- this._pos = p;
70
- }
71
- getPosition(t) {
72
- if (t === undefined) {
73
- t = this._time;
74
- }
75
- return this.func(t, this.begin, this._change, this.duration);
76
- }
77
- play() {
78
- this.state = PLAYING;
79
- this._startTime = this.getTimer() - this._time;
80
- this.onEnterFrame();
81
- this.fire('onPlay');
82
- }
83
- reverse() {
84
- this.state = REVERSING;
85
- this._time = this.duration - this._time;
86
- this._startTime = this.getTimer() - this._time;
87
- this.onEnterFrame();
88
- this.fire('onReverse');
89
- }
90
- seek(t) {
91
- this.pause();
92
- this._time = t;
93
- this.update();
94
- this.fire('onSeek');
95
- }
96
- reset() {
97
- this.pause();
98
- this._time = 0;
99
- this.update();
100
- this.fire('onReset');
101
- }
102
- finish() {
103
- this.pause();
104
- this._time = this.duration;
105
- this.update();
106
- this.fire('onFinish');
107
- }
108
- update() {
109
- this.setPosition(this.getPosition(this._time));
110
- this.fire('onUpdate');
111
- }
112
- onEnterFrame() {
113
- var t = this.getTimer() - this._startTime;
114
- if (this.state === PLAYING) {
115
- this.setTime(t);
116
- }
117
- else if (this.state === REVERSING) {
118
- this.setTime(this.duration - t);
119
- }
120
- }
121
- pause() {
122
- this.state = PAUSED;
123
- this.fire('onPause');
124
- }
125
- getTimer() {
126
- return new Date().getTime();
127
- }
128
- }
129
- class Tween {
130
- constructor(config) {
131
- var that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo, key;
132
- if (typeof config.duration === 'undefined') {
133
- duration = 0.3;
134
- }
135
- else if (config.duration === 0) {
136
- duration = 0.001;
137
- }
138
- else {
139
- duration = config.duration;
140
- }
141
- this.node = node;
142
- this._id = idCounter++;
143
- var layers = node.getLayer() ||
144
- (node instanceof Global_1.Konva['Stage'] ? node.getLayers() : null);
145
- if (!layers) {
146
- Util_1.Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
147
- }
148
- this.anim = new Animation_1.Animation(function () {
149
- that.tween.onEnterFrame();
150
- }, layers);
151
- this.tween = new TweenEngine(key, function (i) {
152
- that._tweenFunc(i);
153
- }, easing, 0, 1, duration * 1000, yoyo);
154
- this._addListeners();
155
- if (!Tween.attrs[nodeId]) {
156
- Tween.attrs[nodeId] = {};
157
- }
158
- if (!Tween.attrs[nodeId][this._id]) {
159
- Tween.attrs[nodeId][this._id] = {};
160
- }
161
- if (!Tween.tweens[nodeId]) {
162
- Tween.tweens[nodeId] = {};
163
- }
164
- for (key in config) {
165
- if (blacklist[key] === undefined) {
166
- this._addAttr(key, config[key]);
167
- }
168
- }
169
- this.reset();
170
- this.onFinish = config.onFinish;
171
- this.onReset = config.onReset;
172
- this.onUpdate = config.onUpdate;
173
- }
174
- _addAttr(key, end) {
175
- var node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
176
- tweenId = Tween.tweens[nodeId][key];
177
- if (tweenId) {
178
- delete Tween.attrs[nodeId][tweenId][key];
179
- }
180
- start = node.getAttr(key);
181
- if (Util_1.Util._isArray(end)) {
182
- diff = [];
183
- len = Math.max(end.length, start.length);
184
- if (key === 'points' && end.length !== start.length) {
185
- if (end.length > start.length) {
186
- trueStart = start;
187
- start = Util_1.Util._prepareArrayForTween(start, end, node.closed());
188
- }
189
- else {
190
- trueEnd = end;
191
- end = Util_1.Util._prepareArrayForTween(end, start, node.closed());
192
- }
193
- }
194
- if (key.indexOf('fill') === 0) {
195
- for (n = 0; n < len; n++) {
196
- if (n % 2 === 0) {
197
- diff.push(end[n] - start[n]);
198
- }
199
- else {
200
- var startRGBA = Util_1.Util.colorToRGBA(start[n]);
201
- endRGBA = Util_1.Util.colorToRGBA(end[n]);
202
- start[n] = startRGBA;
203
- diff.push({
204
- r: endRGBA.r - startRGBA.r,
205
- g: endRGBA.g - startRGBA.g,
206
- b: endRGBA.b - startRGBA.b,
207
- a: endRGBA.a - startRGBA.a,
208
- });
209
- }
210
- }
211
- }
212
- else {
213
- for (n = 0; n < len; n++) {
214
- diff.push(end[n] - start[n]);
215
- }
216
- }
217
- }
218
- else if (colorAttrs.indexOf(key) !== -1) {
219
- start = Util_1.Util.colorToRGBA(start);
220
- endRGBA = Util_1.Util.colorToRGBA(end);
221
- diff = {
222
- r: endRGBA.r - start.r,
223
- g: endRGBA.g - start.g,
224
- b: endRGBA.b - start.b,
225
- a: endRGBA.a - start.a,
226
- };
227
- }
228
- else {
229
- diff = end - start;
230
- }
231
- Tween.attrs[nodeId][this._id][key] = {
232
- start: start,
233
- diff: diff,
234
- end: end,
235
- trueEnd: trueEnd,
236
- trueStart: trueStart,
237
- };
238
- Tween.tweens[nodeId][key] = this._id;
239
- }
240
- _tweenFunc(i) {
241
- var node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
242
- for (key in attrs) {
243
- attr = attrs[key];
244
- start = attr.start;
245
- diff = attr.diff;
246
- end = attr.end;
247
- if (Util_1.Util._isArray(start)) {
248
- newVal = [];
249
- len = Math.max(start.length, end.length);
250
- if (key.indexOf('fill') === 0) {
251
- for (n = 0; n < len; n++) {
252
- if (n % 2 === 0) {
253
- newVal.push((start[n] || 0) + diff[n] * i);
254
- }
255
- else {
256
- newVal.push('rgba(' +
257
- Math.round(start[n].r + diff[n].r * i) +
258
- ',' +
259
- Math.round(start[n].g + diff[n].g * i) +
260
- ',' +
261
- Math.round(start[n].b + diff[n].b * i) +
262
- ',' +
263
- (start[n].a + diff[n].a * i) +
264
- ')');
265
- }
266
- }
267
- }
268
- else {
269
- for (n = 0; n < len; n++) {
270
- newVal.push((start[n] || 0) + diff[n] * i);
271
- }
272
- }
273
- }
274
- else if (colorAttrs.indexOf(key) !== -1) {
275
- newVal =
276
- 'rgba(' +
277
- Math.round(start.r + diff.r * i) +
278
- ',' +
279
- Math.round(start.g + diff.g * i) +
280
- ',' +
281
- Math.round(start.b + diff.b * i) +
282
- ',' +
283
- (start.a + diff.a * i) +
284
- ')';
285
- }
286
- else {
287
- newVal = start + diff * i;
288
- }
289
- node.setAttr(key, newVal);
290
- }
291
- }
292
- _addListeners() {
293
- this.tween.onPlay = () => {
294
- this.anim.start();
295
- };
296
- this.tween.onReverse = () => {
297
- this.anim.start();
298
- };
299
- this.tween.onPause = () => {
300
- this.anim.stop();
301
- };
302
- this.tween.onFinish = () => {
303
- var node = this.node;
304
- var attrs = Tween.attrs[node._id][this._id];
305
- if (attrs.points && attrs.points.trueEnd) {
306
- node.setAttr('points', attrs.points.trueEnd);
307
- }
308
- if (this.onFinish) {
309
- this.onFinish.call(this);
310
- }
311
- };
312
- this.tween.onReset = () => {
313
- var node = this.node;
314
- var attrs = Tween.attrs[node._id][this._id];
315
- if (attrs.points && attrs.points.trueStart) {
316
- node.points(attrs.points.trueStart);
317
- }
318
- if (this.onReset) {
319
- this.onReset();
320
- }
321
- };
322
- this.tween.onUpdate = () => {
323
- if (this.onUpdate) {
324
- this.onUpdate.call(this);
325
- }
326
- };
327
- }
328
- play() {
329
- this.tween.play();
330
- return this;
331
- }
332
- reverse() {
333
- this.tween.reverse();
334
- return this;
335
- }
336
- reset() {
337
- this.tween.reset();
338
- return this;
339
- }
340
- seek(t) {
341
- this.tween.seek(t * 1000);
342
- return this;
343
- }
344
- pause() {
345
- this.tween.pause();
346
- return this;
347
- }
348
- finish() {
349
- this.tween.finish();
350
- return this;
351
- }
352
- destroy() {
353
- var nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
354
- this.pause();
355
- for (key in attrs) {
356
- delete Tween.tweens[nodeId][key];
357
- }
358
- delete Tween.attrs[nodeId][thisId];
359
- }
360
- }
361
- exports.Tween = Tween;
362
- Tween.attrs = {};
363
- Tween.tweens = {};
364
- Node_1.Node.prototype.to = function (params) {
365
- var onFinish = params.onFinish;
366
- params.node = this;
367
- params.onFinish = function () {
368
- this.destroy();
369
- if (onFinish) {
370
- onFinish();
371
- }
372
- };
373
- var tween = new Tween(params);
374
- tween.play();
375
- };
376
- exports.Easings = {
377
- BackEaseIn(t, b, c, d) {
378
- var s = 1.70158;
379
- return c * (t /= d) * t * ((s + 1) * t - s) + b;
380
- },
381
- BackEaseOut(t, b, c, d) {
382
- var s = 1.70158;
383
- return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
384
- },
385
- BackEaseInOut(t, b, c, d) {
386
- var s = 1.70158;
387
- if ((t /= d / 2) < 1) {
388
- return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
389
- }
390
- return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
391
- },
392
- ElasticEaseIn(t, b, c, d, a, p) {
393
- var s = 0;
394
- if (t === 0) {
395
- return b;
396
- }
397
- if ((t /= d) === 1) {
398
- return b + c;
399
- }
400
- if (!p) {
401
- p = d * 0.3;
402
- }
403
- if (!a || a < Math.abs(c)) {
404
- a = c;
405
- s = p / 4;
406
- }
407
- else {
408
- s = (p / (2 * Math.PI)) * Math.asin(c / a);
409
- }
410
- return (-(a *
411
- Math.pow(2, 10 * (t -= 1)) *
412
- Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b);
413
- },
414
- ElasticEaseOut(t, b, c, d, a, p) {
415
- var s = 0;
416
- if (t === 0) {
417
- return b;
418
- }
419
- if ((t /= d) === 1) {
420
- return b + c;
421
- }
422
- if (!p) {
423
- p = d * 0.3;
424
- }
425
- if (!a || a < Math.abs(c)) {
426
- a = c;
427
- s = p / 4;
428
- }
429
- else {
430
- s = (p / (2 * Math.PI)) * Math.asin(c / a);
431
- }
432
- return (a * Math.pow(2, -10 * t) * Math.sin(((t * d - s) * (2 * Math.PI)) / p) +
433
- c +
434
- b);
435
- },
436
- ElasticEaseInOut(t, b, c, d, a, p) {
437
- var s = 0;
438
- if (t === 0) {
439
- return b;
440
- }
441
- if ((t /= d / 2) === 2) {
442
- return b + c;
443
- }
444
- if (!p) {
445
- p = d * (0.3 * 1.5);
446
- }
447
- if (!a || a < Math.abs(c)) {
448
- a = c;
449
- s = p / 4;
450
- }
451
- else {
452
- s = (p / (2 * Math.PI)) * Math.asin(c / a);
453
- }
454
- if (t < 1) {
455
- return (-0.5 *
456
- (a *
457
- Math.pow(2, 10 * (t -= 1)) *
458
- Math.sin(((t * d - s) * (2 * Math.PI)) / p)) +
459
- b);
460
- }
461
- return (a *
462
- Math.pow(2, -10 * (t -= 1)) *
463
- Math.sin(((t * d - s) * (2 * Math.PI)) / p) *
464
- 0.5 +
465
- c +
466
- b);
467
- },
468
- BounceEaseOut(t, b, c, d) {
469
- if ((t /= d) < 1 / 2.75) {
470
- return c * (7.5625 * t * t) + b;
471
- }
472
- else if (t < 2 / 2.75) {
473
- return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b;
474
- }
475
- else if (t < 2.5 / 2.75) {
476
- return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b;
477
- }
478
- else {
479
- return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b;
480
- }
481
- },
482
- BounceEaseIn(t, b, c, d) {
483
- return c - exports.Easings.BounceEaseOut(d - t, 0, c, d) + b;
484
- },
485
- BounceEaseInOut(t, b, c, d) {
486
- if (t < d / 2) {
487
- return exports.Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
488
- }
489
- else {
490
- return exports.Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
491
- }
492
- },
493
- EaseIn(t, b, c, d) {
494
- return c * (t /= d) * t + b;
495
- },
496
- EaseOut(t, b, c, d) {
497
- return -c * (t /= d) * (t - 2) + b;
498
- },
499
- EaseInOut(t, b, c, d) {
500
- if ((t /= d / 2) < 1) {
501
- return (c / 2) * t * t + b;
502
- }
503
- return (-c / 2) * (--t * (t - 2) - 1) + b;
504
- },
505
- StrongEaseIn(t, b, c, d) {
506
- return c * (t /= d) * t * t * t * t + b;
507
- },
508
- StrongEaseOut(t, b, c, d) {
509
- return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
510
- },
511
- StrongEaseInOut(t, b, c, d) {
512
- if ((t /= d / 2) < 1) {
513
- return (c / 2) * t * t * t * t * t + b;
514
- }
515
- return (c / 2) * ((t -= 2) * t * t * t * t + 2) + b;
516
- },
517
- Linear(t, b, c, d) {
518
- return (c * t) / d + b;
519
- },
520
- };
package/cmj/Util.d.ts DELETED
@@ -1,91 +0,0 @@
1
- import { Context } from './Context';
2
- import { IRect, RGB, RGBA, Vector2d } from './types';
3
- export declare class Transform {
4
- m: Array<number>;
5
- dirty: boolean;
6
- constructor(m?: number[]);
7
- reset(): void;
8
- copy(): Transform;
9
- copyInto(tr: Transform): void;
10
- point(point: Vector2d): {
11
- x: number;
12
- y: number;
13
- };
14
- translate(x: number, y: number): this;
15
- scale(sx: number, sy: number): this;
16
- rotate(rad: number): this;
17
- getTranslation(): {
18
- x: number;
19
- y: number;
20
- };
21
- skew(sx: number, sy: number): this;
22
- multiply(matrix: Transform): this;
23
- invert(): this;
24
- getMatrix(): number[];
25
- decompose(): {
26
- x: number;
27
- y: number;
28
- rotation: number;
29
- scaleX: number;
30
- scaleY: number;
31
- skewX: number;
32
- skewY: number;
33
- };
34
- }
35
- export declare const Util: {
36
- _isElement(obj: any): obj is Element;
37
- _isFunction(obj: any): boolean;
38
- _isPlainObject(obj: any): boolean;
39
- _isArray(obj: any): obj is any[];
40
- _isNumber(obj: any): obj is number;
41
- _isString(obj: any): obj is string;
42
- _isBoolean(obj: any): obj is boolean;
43
- isObject(val: any): val is Object;
44
- isValidSelector(selector: any): boolean;
45
- _sign(number: number): 1 | -1;
46
- requestAnimFrame(callback: Function): void;
47
- createCanvasElement(): HTMLCanvasElement;
48
- createImageElement(): HTMLImageElement;
49
- _isInDocument(el: any): boolean;
50
- _urlToImage(url: string, callback: Function): void;
51
- _rgbToHex(r: number, g: number, b: number): string;
52
- _hexToRgb(hex: string): RGB;
53
- getRandomColor(): string;
54
- getRGB(color: string): RGB;
55
- colorToRGBA(str: string): RGBA;
56
- _namedColorToRBA(str: string): {
57
- r: any;
58
- g: any;
59
- b: any;
60
- a: number;
61
- };
62
- _rgbColorToRGBA(str: string): RGBA;
63
- _rgbaColorToRGBA(str: string): RGBA;
64
- _hex8ColorToRGBA(str: string): RGBA;
65
- _hex6ColorToRGBA(str: string): RGBA;
66
- _hex4ColorToRGBA(str: string): RGBA;
67
- _hex3ColorToRGBA(str: string): RGBA;
68
- _hslColorToRGBA(str: string): RGBA;
69
- haveIntersection(r1: IRect, r2: IRect): boolean;
70
- cloneObject<Any>(obj: Any): Any;
71
- cloneArray(arr: Array<any>): any[];
72
- degToRad(deg: number): number;
73
- radToDeg(rad: number): number;
74
- _degToRad(deg: number): number;
75
- _radToDeg(rad: number): number;
76
- _getRotation(radians: any): any;
77
- _capitalize(str: string): string;
78
- throw(str: string): never;
79
- error(str: string): void;
80
- warn(str: string): void;
81
- each(obj: any, func: any): void;
82
- _inRange(val: any, left: any, right: any): boolean;
83
- _getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
84
- _getProjectionToLine(pt: Vector2d, line: any, isClosed: any): Vector2d;
85
- _prepareArrayForTween(startArray: any, endArray: any, isClosed: any): any[];
86
- _prepareToStringify(obj: any): any;
87
- _assign<T, U>(target: T, source: U): T & U;
88
- _getFirstPointerId(evt: any): any;
89
- releaseCanvas(...canvases: HTMLCanvasElement[]): void;
90
- drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
91
- };