MCPcopy
hub / github.com/animatedjs/animated / create

Method create

src/Interpolation.js:36–89  ·  view source on GitHub ↗
(config: InterpolationConfigType)

Source from the content-addressed store, hash-verified

34 */
35class Interpolation {
36 static create(config: InterpolationConfigType): (input: number) => number | string {
37
38 if (config.outputRange && typeof config.outputRange[0] === 'string') {
39 return createInterpolationFromStringOutputRange(config);
40 }
41
42 var outputRange: Array<number> = (config.outputRange: any);
43 checkInfiniteRange('outputRange', outputRange);
44
45 var inputRange = config.inputRange;
46 checkInfiniteRange('inputRange', inputRange);
47 checkValidInputRange(inputRange);
48
49 invariant(
50 inputRange.length === outputRange.length,
51 'inputRange (' + inputRange.length + ') and outputRange (' +
52 outputRange.length + ') must have the same length'
53 );
54
55 var easing = config.easing || linear;
56
57 var extrapolateLeft: ExtrapolateType = 'extend';
58 if (config.extrapolateLeft !== undefined) {
59 extrapolateLeft = config.extrapolateLeft;
60 } else if (config.extrapolate !== undefined) {
61 extrapolateLeft = config.extrapolate;
62 }
63
64 var extrapolateRight: ExtrapolateType = 'extend';
65 if (config.extrapolateRight !== undefined) {
66 extrapolateRight = config.extrapolateRight;
67 } else if (config.extrapolate !== undefined) {
68 extrapolateRight = config.extrapolate;
69 }
70
71 return (input) => {
72 invariant(
73 typeof input === 'number',
74 'Cannot interpolation an input which is not a number'
75 );
76
77 var range = findRange(input, inputRange);
78 return interpolate(
79 input,
80 inputRange[range],
81 inputRange[range + 1],
82 outputRange[range],
83 outputRange[range + 1],
84 easing,
85 extrapolateLeft,
86 extrapolateRight,
87 );
88 };
89 }
90}
91
92function interpolate(

Callers 7

interpolateMethod · 0.80
interpolateMethod · 0.80
interpolateMethod · 0.80
interpolateMethod · 0.80
interpolateMethod · 0.80

Calls 5

checkInfiniteRangeFunction · 0.85
checkValidInputRangeFunction · 0.85
findRangeFunction · 0.85
interpolateFunction · 0.85

Tested by

no test coverage detected