const TAB_KEY_CODE = 9 ; /**
 * A nifty little class that maintains event handlers to add a class to the container element
 * when entering "mouse mode" (on a `mousedown` event) and remove it when entering "keyboard mode"
 * (on a `tab` key `keydown` event).
 */ export class InteractionModeEngine { private isRunning = false ; constructor ( private container , private className ) { } /** Returns whether the engine is currently running. */ public isActive ( ) { return this . isRunning ; } /** Enable behavior which applies the given className when in mouse mode. */ public start ( ) { this . container . addEventListener ( "mousedown" , this . handleMouseDown ) ; this . isRunning = true ; } /** Disable interaction mode behavior and remove className from container. */ public stop ( ) { this . reset ( ) ; this . isRunning = false ; } private reset ( ) { this . container . classList . remove ( this . className ) ; this . container . removeEventListener ( "keydown" , this . handleKeyDown as EventListener ) ; this . container . removeEventListener ( "mousedown" , this . handleMouseDown ) ; } private handleKeyDown = ( e ) => { if ( e . which === TAB_KEY_CODE ) { this . reset ( ) ; this . container . addEventListener ( "mousedown" , this . handleMouseDown ) ; } } ; private handleMouseDown = ( ) => { this . reset ( ) ; this . container . classList . add ( this . className ) ; this . container . addEventListener ( "keydown" , this . handleKeyDown as EventListener ) ; } ; }