UNPKG

4.6 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var internal = require('../internal');
6
7/*
8Adapted from https://github.com/mattdesl
9Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md
10*/
11function backInOut(t) {
12 const s = 1.70158 * 1.525;
13 if ((t *= 2) < 1)
14 return 0.5 * (t * t * ((s + 1) * t - s));
15 return 0.5 * ((t -= 2) * t * ((s + 1) * t + s) + 2);
16}
17function backIn(t) {
18 const s = 1.70158;
19 return t * t * ((s + 1) * t - s);
20}
21function backOut(t) {
22 const s = 1.70158;
23 return --t * t * ((s + 1) * t + s) + 1;
24}
25function bounceOut(t) {
26 const a = 4.0 / 11.0;
27 const b = 8.0 / 11.0;
28 const c = 9.0 / 10.0;
29 const ca = 4356.0 / 361.0;
30 const cb = 35442.0 / 1805.0;
31 const cc = 16061.0 / 1805.0;
32 const t2 = t * t;
33 return t < a
34 ? 7.5625 * t2
35 : t < b
36 ? 9.075 * t2 - 9.9 * t + 3.4
37 : t < c
38 ? ca * t2 - cb * t + cc
39 : 10.8 * t * t - 20.52 * t + 10.72;
40}
41function bounceInOut(t) {
42 return t < 0.5
43 ? 0.5 * (1.0 - bounceOut(1.0 - t * 2.0))
44 : 0.5 * bounceOut(t * 2.0 - 1.0) + 0.5;
45}
46function bounceIn(t) {
47 return 1.0 - bounceOut(1.0 - t);
48}
49function circInOut(t) {
50 if ((t *= 2) < 1)
51 return -0.5 * (Math.sqrt(1 - t * t) - 1);
52 return 0.5 * (Math.sqrt(1 - (t -= 2) * t) + 1);
53}
54function circIn(t) {
55 return 1.0 - Math.sqrt(1.0 - t * t);
56}
57function circOut(t) {
58 return Math.sqrt(1 - --t * t);
59}
60function cubicInOut(t) {
61 return t < 0.5 ? 4.0 * t * t * t : 0.5 * Math.pow(2.0 * t - 2.0, 3.0) + 1.0;
62}
63function cubicIn(t) {
64 return t * t * t;
65}
66function cubicOut(t) {
67 const f = t - 1.0;
68 return f * f * f + 1.0;
69}
70function elasticInOut(t) {
71 return t < 0.5
72 ? 0.5 *
73 Math.sin(((+13.0 * Math.PI) / 2) * 2.0 * t) *
74 Math.pow(2.0, 10.0 * (2.0 * t - 1.0))
75 : 0.5 *
76 Math.sin(((-13.0 * Math.PI) / 2) * (2.0 * t - 1.0 + 1.0)) *
77 Math.pow(2.0, -10.0 * (2.0 * t - 1.0)) +
78 1.0;
79}
80function elasticIn(t) {
81 return Math.sin((13.0 * t * Math.PI) / 2) * Math.pow(2.0, 10.0 * (t - 1.0));
82}
83function elasticOut(t) {
84 return (Math.sin((-13.0 * (t + 1.0) * Math.PI) / 2) * Math.pow(2.0, -10.0 * t) + 1.0);
85}
86function expoInOut(t) {
87 return t === 0.0 || t === 1.0
88 ? t
89 : t < 0.5
90 ? +0.5 * Math.pow(2.0, 20.0 * t - 10.0)
91 : -0.5 * Math.pow(2.0, 10.0 - t * 20.0) + 1.0;
92}
93function expoIn(t) {
94 return t === 0.0 ? t : Math.pow(2.0, 10.0 * (t - 1.0));
95}
96function expoOut(t) {
97 return t === 1.0 ? t : 1.0 - Math.pow(2.0, -10.0 * t);
98}
99function quadInOut(t) {
100 t /= 0.5;
101 if (t < 1)
102 return 0.5 * t * t;
103 t--;
104 return -0.5 * (t * (t - 2) - 1);
105}
106function quadIn(t) {
107 return t * t;
108}
109function quadOut(t) {
110 return -t * (t - 2.0);
111}
112function quartInOut(t) {
113 return t < 0.5
114 ? +8.0 * Math.pow(t, 4.0)
115 : -8.0 * Math.pow(t - 1.0, 4.0) + 1.0;
116}
117function quartIn(t) {
118 return Math.pow(t, 4.0);
119}
120function quartOut(t) {
121 return Math.pow(t - 1.0, 3.0) * (1.0 - t) + 1.0;
122}
123function quintInOut(t) {
124 if ((t *= 2) < 1)
125 return 0.5 * t * t * t * t * t;
126 return 0.5 * ((t -= 2) * t * t * t * t + 2);
127}
128function quintIn(t) {
129 return t * t * t * t * t;
130}
131function quintOut(t) {
132 return --t * t * t * t * t + 1;
133}
134function sineInOut(t) {
135 return -0.5 * (Math.cos(Math.PI * t) - 1);
136}
137function sineIn(t) {
138 const v = Math.cos(t * Math.PI * 0.5);
139 if (Math.abs(v) < 1e-14)
140 return 1;
141 else
142 return 1 - v;
143}
144function sineOut(t) {
145 return Math.sin((t * Math.PI) / 2);
146}
147
148exports.linear = internal.identity;
149exports.backInOut = backInOut;
150exports.backIn = backIn;
151exports.backOut = backOut;
152exports.bounceOut = bounceOut;
153exports.bounceInOut = bounceInOut;
154exports.bounceIn = bounceIn;
155exports.circInOut = circInOut;
156exports.circIn = circIn;
157exports.circOut = circOut;
158exports.cubicInOut = cubicInOut;
159exports.cubicIn = cubicIn;
160exports.cubicOut = cubicOut;
161exports.elasticInOut = elasticInOut;
162exports.elasticIn = elasticIn;
163exports.elasticOut = elasticOut;
164exports.expoInOut = expoInOut;
165exports.expoIn = expoIn;
166exports.expoOut = expoOut;
167exports.quadInOut = quadInOut;
168exports.quadIn = quadIn;
169exports.quadOut = quadOut;
170exports.quartInOut = quartInOut;
171exports.quartIn = quartIn;
172exports.quartOut = quartOut;
173exports.quintInOut = quintInOut;
174exports.quintIn = quintIn;
175exports.quintOut = quintOut;
176exports.sineInOut = sineInOut;
177exports.sineIn = sineIn;
178exports.sineOut = sineOut;