forked from 15001217168/mojs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-easing.babel.js
More file actions
60 lines (52 loc) · 1.63 KB
/
Copy pathparse-easing.babel.js
File metadata and controls
60 lines (52 loc) · 1.63 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
import {
defaultEasing,
defaultEasingString,
consoleName,
} from '../constants.babel.js';
import { easing } from './easing.babel.js';
import { path } from './path.babel.js';
/**
* parseEasing - function to parse all easing values to a function.
*
* @param {String, Function, Array} Easing representation.
* @return {Function} Parsed Easing.
*/
const parseEasing = (ease = defaultEasingString) => {
const type = typeof ease;
switch (type) {
case 'function': {
return ease;
}
case 'string': {
// path easing
if (ease[0].toLowerCase() === 'm') {
return path(ease);
}
ease = ease.toLowerCase().split('.');
const easeParent = easing[ease[0]];
if (!easeParent) {
console.error(`${consoleName} Easing with name "${ease[0]}" wasn't found, fallback to "${defaultEasingString}" instead.`, easing); // eslint-disable-line no-console
return easing[defaultEasing[0]][defaultEasing[1]];
}
return easeParent[ease[1]];
}
default:
console.error(`${consoleName} Only strings and function supported atm.`, ease); // eslint-disable-line no-console
// // comming soon:
// // - if array passed - parse as `bezier` function
// // ---
// case 'object' {
// if (easing instanceof Array) {
// return this.bezier.apply(this, easing);
// } else {
// console.error(
// `:mojs: Failed to parse easing value of `,
// easing,
// ` fallback to "linear.none" instead`
// );
// return easing[defaultEasing[0]][defaultEasing[1]];
// }
// }
}
};
export { parseEasing };