-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
119 lines (93 loc) · 3.42 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
export type TEasing = (time: number) => number;
export interface IEasingMap {
linear: TEasing;
quadratic: TEasing;
cubic: TEasing;
elastic: TEasing;
inQuad: TEasing;
outQuad: TEasing;
inOutQuad: TEasing;
inCubic: TEasing;
outCubic: TEasing;
inOutCubic: TEasing;
inQuart: TEasing;
outQuart: TEasing;
inOutQuart: TEasing;
inQuint: TEasing;
outQuint: TEasing;
inOutQuint: TEasing;
inSine: TEasing;
outSine: TEasing;
inOutSine: TEasing;
inExpo: TEasing;
outExpo: TEasing;
inOutExpo: TEasing;
inCirc: TEasing;
outCirc: TEasing;
inOutCirc: TEasing;
}
export const easing: IEasingMap = {
// No easing, no acceleration
linear: (t) => t,
// Accelerates fast, then slows quickly towards end.
quadratic: (t) => t * (-(t * t) * t + 4 * t * t - 6 * t + 4),
// Overshoots over 1 and then returns to 1 towards end.
cubic: (t) => t * (4 * t * t - 9 * t + 6),
// Overshoots over 1 multiple times - wiggles around 1.
elastic: (t) => t * (33 * t * t * t * t - 106 * t * t * t + 126 * t * t - 67 * t + 15),
// Accelerating from zero velocity
inQuad: (t) => t * t,
// Decelerating to zero velocity
outQuad: (t) => t * (2 - t),
// Acceleration until halfway, then deceleration
inOutQuad: (t) => t <.5 ? 2 * t * t : -1 + (4 - 2 * t) * t,
// Accelerating from zero velocity
inCubic: (t) => t * t * t,
// Decelerating to zero velocity
outCubic: (t) => (--t) * t * t + 1,
// Acceleration until halfway, then deceleration
inOutCubic: (t) => t <.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1,
// Accelerating from zero velocity
inQuart: (t) => t * t * t * t,
// Decelerating to zero velocity
outQuart: (t) => 1 - (--t) * t * t * t,
// Acceleration until halfway, then deceleration
inOutQuart: (t) => t <.5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t,
// Accelerating from zero velocity
inQuint: (t) => t * t * t * t * t,
// Decelerating to zero velocity
outQuint: (t) => 1 + (--t) * t * t * t * t,
// Acceleration until halfway, then deceleration
inOutQuint: (t) => t < .5 ? 16 * t * t * t * t * t : 1 + 16 * (--t) * t * t * t * t,
// Accelerating from zero velocity
inSine: (t) => -Math.cos(t * (Math.PI / 2)) + 1,
// Decelerating to zero velocity
outSine: (t) => Math.sin(t * (Math.PI / 2)),
// Accelerating until halfway, then decelerating
inOutSine: (t) => -(Math.cos(Math.PI * t) - 1) / 2,
// Exponential accelerating from zero velocity
inExpo: (t) => Math.pow(2, 10 * (t - 1)),
// Exponential decelerating to zero velocity
outExpo: (t) => -Math.pow(2, -10 * t) + 1,
// Exponential accelerating until halfway, then decelerating
inOutExpo: (t) => {
t /= .5;
if (t < 1) return Math.pow(2, 10 * (t - 1)) / 2;
t--;
return (-Math.pow( 2, -10 * t) + 2) / 2;
},
// Circular accelerating from zero velocity
inCirc: (t) => -Math.sqrt(1 - t * t) + 1,
// Circular decelerating to zero velocity Moves VERY fast at the beginning and
// then quickly slows down in the middle. This tween can actually be used
// in continuous transitions where target value changes all the time,
// because of the very quick start, it hides the jitter between target value changes.
outCirc: (t) => Math.sqrt(1 - (t = t - 1) * t),
// Circular acceleration until halfway, then deceleration
inOutCirc: (t) => {
t /= .5;
if (t < 1) return -(Math.sqrt(1 - t * t) - 1) / 2;
t -= 2;
return (Math.sqrt(1 - t * t) + 1) / 2;
}
};