MCPcopy
hub / github.com/pmndrs/react-spring / createInterpolator

Function createInterpolator

packages/shared/src/createInterpolator.ts:12–57  ·  view source on GitHub ↗
(
  range: readonly number[] | InterpolatorFn<any, any> | InterpolatorConfig<any>,
  output?: readonly Animatable[],
  extrapolate?: ExtrapolateType
)

Source from the content-addressed store, hash-verified

10} from '@react-spring/types'
11
12export 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
59function interpolate(
60 input: number,

Callers 6

constructorMethod · 0.90
createStringInterpolatorFunction · 0.90
constructorMethod · 0.90
resetMethod · 0.90
AppFunction · 0.85

Calls 2

findRangeFunction · 0.85
interpolateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…