30 lines
		
	
	
		
			854 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			30 lines
		
	
	
		
			854 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { spring } from '../generators/spring.mjs';
 | |
| import { keyframes } from '../generators/keyframes.mjs';
 | |
| import { decay } from '../generators/decay.mjs';
 | |
| 
 | |
| const types = { keyframes, spring, decay };
 | |
| function detectAnimationFromOptions(config) {
 | |
|     if (Array.isArray(config.to)) {
 | |
|         return keyframes;
 | |
|     }
 | |
|     else if (types[config.type]) {
 | |
|         return types[config.type];
 | |
|     }
 | |
|     const keys = new Set(Object.keys(config));
 | |
|     if (keys.has("ease") ||
 | |
|         (keys.has("duration") && !keys.has("dampingRatio"))) {
 | |
|         return keyframes;
 | |
|     }
 | |
|     else if (keys.has("dampingRatio") ||
 | |
|         keys.has("stiffness") ||
 | |
|         keys.has("mass") ||
 | |
|         keys.has("damping") ||
 | |
|         keys.has("restSpeed") ||
 | |
|         keys.has("restDelta")) {
 | |
|         return spring;
 | |
|     }
 | |
|     return keyframes;
 | |
| }
 | |
| 
 | |
| export { detectAnimationFromOptions };
 | 
