import { SpringConfig } from './presets' ; export const isClient = typeof window !== 'undefined' ; export const raf = isClient ? window . requestAnimationFrame . bind ( window ) : ( ) => { } ; export const cancelRaf = isClient ? window . cancelAnimationFrame . bind ( window ) : ( ) => { } ; export const now = typeof performance !== 'undefined' ? performance . now . bind ( performance ) : Date . now . bind ( Date ) ; export const isArray = Array . isArray . bind ( Array ) ; export const isObject = ( value ) : value is object => value != null && typeof value === 'object' ; export const isFunction = ( value ) : value is Function => typeof value === 'function' ; const reusedTuple = [ 0 , 0 ] ; export function stepper ( secondPerFrame , x , v , destX , spring ) { const Fspring = - spring . tension * ( x - destX ) ; const Fdamper = - spring . friction * v ; const a = ( Fspring + Fdamper ) / ( spring . mass || 1 ) ; const newV = v + a * secondPerFrame ; const newX = x + newV * secondPerFrame ; const precision = spring . precision || 0.01 ; if ( Math . abs ( newV ) < precision && Math . abs ( newX - destX ) < precision ) { reusedTuple [ 0 ] = destX ; reusedTuple [ 1 ] = 0 ; return reusedTuple ; } reusedTuple [ 0 ] = newX ; reusedTuple [ 1 ] = newV ; return reusedTuple ; }