/**
 * requestAnimationFrame polyfill
 */ import { isServer } from '..' ; let prev = Date . now ( ) ; function fallback ( fn ) { const curr = Date . now ( ) ; const ms = Math . max ( 0 , 16 - ( curr - prev ) ) ; const id = setTimeout ( fn , ms ) ; prev = curr + ms ; return id as any ; } const root = ( isServer ? global : window ) as Window ; const iCancel = root . cancelAnimationFrame || root . clearTimeout ; export function raf ( fn ) { return ( root . requestAnimationFrame || fallback ) . call ( root , fn ) ; } export function doubleRaf ( fn ) { raf ( ( ) => { raf ( fn ) ; } ) ; } export function cancelRaf ( id ) { iCancel . call ( root , id ) ; }