( range: readonly number[] | InterpolatorFn<any, any> | InterpolatorConfig<any>, output?: readonly Animatable[], extrapolate?: ExtrapolateType )
| 10 | } from '@react-spring/types' |
| 11 | |
| 12 | export const createInterpolator: InterpolatorFactory = ( |
| 13 | range: readonly number[] | InterpolatorFn<any, any> | InterpolatorConfig<any>, |
| 14 | output?: readonly Animatable[], |
| 15 | extrapolate?: ExtrapolateType |
| 16 | ) => { |
| 17 | if (is.fun(range)) { |
| 18 | return range |
| 19 | } |
| 20 | |
| 21 | if (is.arr(range)) { |
| 22 | return createInterpolator({ |
| 23 | range, |
| 24 | output: output!, |
| 25 | extrapolate, |
| 26 | }) |
| 27 | } |
| 28 | |
| 29 | if (is.str(range.output[0])) { |
| 30 | return G.createStringInterpolator(range as any) as any |
| 31 | } |
| 32 | |
| 33 | const config = range as InterpolatorConfig<number> |
| 34 | const outputRange = config.output |
| 35 | const inputRange = config.range || [0, 1] |
| 36 | |
| 37 | const extrapolateLeft = |
| 38 | config.extrapolateLeft || config.extrapolate || 'extend' |
| 39 | const extrapolateRight = |
| 40 | config.extrapolateRight || config.extrapolate || 'extend' |
| 41 | const easing = config.easing || (t => t) |
| 42 | |
| 43 | return (input: number) => { |
| 44 | const range = findRange(input, inputRange) |
| 45 | return interpolate( |
| 46 | input, |
| 47 | inputRange[range], |
| 48 | inputRange[range + 1], |
| 49 | outputRange[range], |
| 50 | outputRange[range + 1], |
| 51 | easing, |
| 52 | extrapolateLeft, |
| 53 | extrapolateRight, |
| 54 | config.map |
| 55 | ) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | function interpolate( |
| 60 | input: number, |
no test coverage detected
searching dependent graphs…