|
|
import { raf, Rafz } from '@react-spring/rafz' |
|
|
import { |
|
|
OneOrMore, |
|
|
InterpolatorConfig, |
|
|
InterpolatorArgs, |
|
|
} from '@react-spring/types' |
|
|
|
|
|
import { FluidValue } from './fluids' |
|
|
import type { OpaqueAnimation } from './FrameLoop' |
|
|
import { noop } from './helpers' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export let createStringInterpolator: ( |
|
|
config: InterpolatorConfig<string> |
|
|
) => (input: number) => string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export let to: <Input, Output>( |
|
|
source: OneOrMore<FluidValue>, |
|
|
args: InterpolatorArgs<Input, Output> |
|
|
) => FluidValue<Output> |
|
|
|
|
|
export let colors = null as { [key: string]: number } | null |
|
|
|
|
|
export let skipAnimation = false as boolean |
|
|
|
|
|
export let willAdvance: (animation: OpaqueAnimation) => void = noop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface AnimatedGlobals { |
|
|
|
|
|
to?: typeof to |
|
|
|
|
|
now?: typeof raf.now |
|
|
|
|
|
colors?: typeof colors |
|
|
|
|
|
skipAnimation?: typeof skipAnimation |
|
|
|
|
|
createStringInterpolator?: typeof createStringInterpolator |
|
|
|
|
|
requestAnimationFrame?: (cb: () => void) => void |
|
|
|
|
|
batchedUpdates?: typeof raf.batchedUpdates |
|
|
|
|
|
willAdvance?: typeof willAdvance |
|
|
|
|
|
frameLoop?: Rafz['frameLoop'] |
|
|
} |
|
|
|
|
|
export const assign = (globals: AnimatedGlobals) => { |
|
|
if (globals.to) to = globals.to |
|
|
if (globals.now) raf.now = globals.now |
|
|
if (globals.colors !== undefined) colors = globals.colors |
|
|
if (globals.skipAnimation != null) skipAnimation = globals.skipAnimation |
|
|
if (globals.createStringInterpolator) |
|
|
createStringInterpolator = globals.createStringInterpolator |
|
|
if (globals.requestAnimationFrame) raf.use(globals.requestAnimationFrame) |
|
|
if (globals.batchedUpdates) raf.batchedUpdates = globals.batchedUpdates |
|
|
if (globals.willAdvance) willAdvance = globals.willAdvance |
|
|
if (globals.frameLoop) raf.frameLoop = globals.frameLoop |
|
|
} |
|
|
|