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