forked from 15001217168/mojs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasing.js
More file actions
274 lines (271 loc) · 10.8 KB
/
Copy patheasing.js
File metadata and controls
274 lines (271 loc) · 10.8 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
(function() {
var easing;
easing = mojs.easing;
describe('easing ->', function() {
describe('Linear ->', function() {
return it('should have None', function() {
return expect(easing.linear.none(.5)).toBe(.5);
});
});
describe('ease ->', function() {
it('should have In', function() {
return expect(easing.ease["in"].toStr()).toBe('bezier(0.42,0,1,1)');
});
it('should have Out', function() {
return expect(easing.ease.out.toStr()).toBe('bezier(0,0,0.58,1)');
});
return it('should have InOut', function() {
return expect(easing.ease.inout.toStr()).toBe('bezier(0.42,0,0.58,1)');
});
});
describe('quad ->', function() {
it('should have In', function() {
return expect(easing.quad["in"](.5)).toBe(.5 * .5);
});
it('should have Out', function() {
return expect(easing.quad.out(.5)).toBe(.5 * (2 - .5));
});
return it('should have InOut', function() {
expect(easing.quad.inout(.5)).toBe(.5);
return expect(easing.quad.inout(.25)).toBe(.125);
});
});
describe('cubic ->', function() {
it('should have In', function() {
return expect(easing.cubic["in"](.5)).toBe(.5 * .5 * .5);
});
it('should have Out', function() {
return expect(easing.cubic.out(.5)).toBe(.875);
});
return it('should have InOut', function() {
expect(easing.cubic.inout(.5)).toBe(.5);
return expect(easing.cubic.inout(.25)).toBe(.0625);
});
});
describe('quart ->', function() {
it('should have In', function() {
return expect(easing.quart["in"](.5)).toBe(.5 * .5 * .5 * .5);
});
it('should have Out', function() {
return expect(easing.quart.out(.5)).toBe(.9375);
});
return it('should have InOut', function() {
expect(easing.quart.inout(.5)).toBe(.5);
return expect(easing.quart.inout(.25)).toBe(.03125);
});
});
describe('quint ->', function() {
it('should have In', function() {
return expect(easing.quint["in"](.5)).toBe(.5 * .5 * .5 * .5 * .5);
});
it('should have Out', function() {
return expect(easing.quint.out(.5)).toBe(.96875);
});
return it('should have InOut', function() {
expect(easing.quint.inout(.5)).toBe(.5);
return expect(easing.quint.inout(.25)).toBe(.015625);
});
});
describe('sin ->', function() {
it('should have In', function() {
return expect(easing.sin["in"](.5)).toBe(1 - Math.cos(.5 * Math.PI / 2));
});
it('should have Out', function() {
return expect(easing.sin.out(.5)).toBe(Math.sin(.5 * Math.PI / 2));
});
return it('should have InOut', function() {
var result;
result = 0.5 * (1 - Math.cos(Math.PI * .5));
return expect(easing.sin.inout(.5)).toBe(result);
});
});
describe('expo ->', function() {
it('should have In', function() {
expect(easing.expo["in"](0)).toBe(0);
return expect(easing.expo["in"](.5)).toBe(Math.pow(1024, .5 - 1));
});
it('should have Out', function() {
expect(easing.expo.out(1)).toBe(1);
return expect(easing.expo.out(.5)).toBe(1 - Math.pow(2, -10 * .5));
});
return it('should have InOut', function() {
expect(easing.expo.inout(0)).toBe(0);
expect(easing.expo.inout(1)).toBe(1);
expect(easing.expo.inout(.25)).toBe(0.5 * Math.pow(1024, .5 - 1));
return expect(easing.expo.inout(.5)).toBe(.5);
});
});
describe('circ ->', function() {
it('should have In', function() {
return expect(easing.circ["in"](.5)).toBe(1 - Math.sqrt(1 - .5 * .5));
});
it('should have Out', function() {
var k;
k = .5;
return expect(easing.circ.out(k)).toBe(Math.sqrt(1 - (--k * k)));
});
return it('should have InOut', function() {
expect(easing.circ.inout(.25).toFixed(2)).toBe('0.07');
return expect(easing.circ.inout(.6).toFixed(2)).toBe('0.80');
});
});
describe('elastic ->', function() {
it('should have In', function() {
expect(easing.elastic["in"](0)).toBe(0);
expect(easing.elastic["in"](1)).toBe(1);
expect(easing.elastic["in"](.75).toFixed(5)).toBe('-0.12500');
return expect(easing.elastic["in"](.1).toFixed(2)).toBe('0.00');
});
it('should have Out', function() {
expect(easing.elastic.out(0)).toBe(0);
expect(easing.elastic.out(1)).toBe(1);
return expect(easing.elastic.out(.75).toFixed(2)).toBe('1.00');
});
return it('should have InOut', function() {
expect(easing.elastic.inout(0)).toBe(0);
expect(easing.elastic.inout(1)).toBe(1);
expect(easing.elastic.inout(.25).toFixed(2)).toBe('0.00');
return expect(easing.elastic.inout(.75).toFixed(2)).toBe('1.00');
});
});
describe('back ->', function() {
it('should have In', function() {
return expect(easing.back["in"](.75).toFixed(2)).toBe('0.18');
});
it('should have Out', function() {
return expect(easing.back.out(.75).toFixed(2)).toBe('1.06');
});
return it('should have InOut', function() {
expect(easing.back.inout(.25).toFixed(2)).toBe('-0.10');
return expect(easing.back.inout(.75).toFixed(2)).toBe('1.10');
});
});
describe('bounce ->', function() {
it('should have In', function() {
return expect(easing.bounce["in"](.75).toFixed(2)).toBe('0.53');
});
it('should have Out', function() {
expect(easing.bounce.out(.1).toFixed(2)).toBe('0.08');
expect(easing.bounce.out(.25).toFixed(2)).toBe('0.47');
expect(easing.bounce.out(.75).toFixed(2)).toBe('0.97');
return expect(easing.bounce.out(.99).toFixed(2)).toBe('0.99');
});
return it('should have InOut', function() {
expect(easing.bounce.inout(.25).toFixed(2)).toBe('0.12');
return expect(easing.bounce.inout(.75).toFixed(2)).toBe('0.88');
});
});
describe('bezier ->', function() {
return it('should have bezier constructor', function() {
return expect(typeof easing.bezier).toBe('function');
});
});
describe('path ->', function() {
return it('should have path constructor', function() {
return expect(typeof easing.path).toBe('function');
});
});
describe('PathEasing ->', function() {
return it('should have PathEasing constructor', function() {
return expect(typeof easing.PathEasing).toBe('function');
});
});
describe('inverse method ->', function() {
return it('should inverse passed value', function() {
expect(easing.inverse(-2)).toBeCloseTo(3, 4);
expect(easing.inverse(-1)).toBeCloseTo(2, 4);
expect(easing.inverse(0)).toBeCloseTo(1, 4);
expect(easing.inverse(.2)).toBeCloseTo(.8, 4);
expect(easing.inverse(.5)).toBeCloseTo(.5, 4);
expect(easing.inverse(.7)).toBeCloseTo(.3, 4);
expect(easing.inverse(1)).toBeCloseTo(0, 4);
expect(easing.inverse(2)).toBeCloseTo(-1, 4);
return expect(easing.inverse(3)).toBeCloseTo(-2, 4);
});
});
describe('mix method ->', function() {
return it('should be definede', function() {
return expect(typeof easing.mix).toBe('function');
});
});
describe('parseEasing method ->', function() {
it('should parse function easing', function() {
var fun;
fun = function() {};
expect(easing.parseEasing(fun)).toBe(fun);
return expect(typeof easing.parseEasing(fun)).toBe('function');
});
it('should parse null/undefined to liner.none', function() {
var fun;
fun = easing.parseEasing(null);
return expect(fun).toBe(mojs.easing.linear.none);
});
return describe('easing name option ->', function() {
it('should parse string easing', function() {
return expect(typeof easing.parseEasing('cubic.in')).toBe('function');
});
it('should error if easing was not found and fallback to linear one', function() {
var fun;
spyOn(mojs.h, 'error');
fun = easing.parseEasing('sinusoidal.in');
expect(mojs.h.error).toHaveBeenCalled();
return expect(fun).toBe(mojs.easing.linear.none);
});
describe('SVG path option ->', function() {
it('should parse SVG path easing', function() {
return expect(typeof easing.parseEasing('M0,100 L100,0')).toBe('function');
});
return it('should call easing.path method', function() {
spyOn(window.mojs.easing, 'path');
easing.parseEasing('M0,100 L100,0');
return expect(window.mojs.easing.path).toHaveBeenCalled();
});
});
return describe('bezier option ->', function() {
it('should parse bezier easing', function() {
return expect(typeof easing.parseEasing([0.42, 0, 1, 1])).toBe('function');
});
return it('should call bezier method', function() {
spyOn(window.mojs.easing, 'bezier');
easing.parseEasing([0.42, 0, 1, 1]);
return expect(window.mojs.easing.bezier).toHaveBeenCalled();
});
});
});
});
describe('splitEasing method ->', function() {
it('should split easing string to array', function() {
expect(easing._splitEasing('Linear.None')[0]).toBe('linear');
return expect(easing._splitEasing('Linear.None')[1]).toBe('none');
});
it('should return default easing Linear.None if argument is bad', function() {
expect(easing._splitEasing(4)[0]).toBe('linear');
return expect(easing._splitEasing(4)[1]).toBe('none');
});
it('should return default easing Linear.None if argument is bad #2', function() {
expect(easing._splitEasing('')[0]).toBe('linear');
return expect(easing._splitEasing('')[1]).toBe('none');
});
it('should return default easing Linear.None if argument is bad #3', function() {
expect(easing._splitEasing('Linear..None')[0]).toBe('linear');
return expect(easing._splitEasing('Linear..None')[1]).toBe('none');
});
it('should work with lovercase easing', function() {
expect(easing._splitEasing('linear..none')[0]).toBe('linear');
return expect(easing._splitEasing('linear..none')[1]).toBe('none');
});
return it('should work with function easing', function() {
var fun;
fun = function() {
return console.log('function');
};
return expect(easing._splitEasing(fun) + '').toBe(fun + '');
});
});
return describe('approximate object', function() {
return it('should de defined', function() {
return expect(easing.approximate).toBeDefined();
});
});
});
}).call(this);