license /**
 * AnimationFrame provides a user-friendly abstraction around requesting
 * and canceling animation frames.
 */ export class AnimationFrame { private readonly rafIDs = new Map < string , number > ( ) ; param { string } key param { FrameRequestCallback } callback request ( key , callback ) { this . cancel ( key ) ; const frameID = requestAnimationFrame ( ( frame ) => { this . rafIDs . delete ( key ) ; callback ( frame ) ; } ) ; this . rafIDs . set ( key , frameID ) ; } param { string } key cancel ( key ) { const rafID = this . rafIDs . get ( key ) ; if ( rafID ) { cancelAnimationFrame ( rafID ) ; this . rafIDs . delete ( key ) ; } } /**
     * Cancels all queued callback.
     */ cancelAll ( ) { this . rafIDs . forEach ( ( _ , key ) => { this . cancel ( key ) ; } ) ; } /**
     * Returns the queue of unexecuted callback keys.
     */ getQueue ( ) { const queue = [ ] ; this . rafIDs . forEach ( ( _ , key ) => { queue . push ( key ) ; } ) ; return queue ; } }