import * as ui from "./ui/ui.js" ; import { repo as commandRepo , Key } from "./command/command.js" ; type EventProp = keyof KeyboardEvent ; function handleEvent ( e ) { if ( ui . isActive ( ) ) { return ; } let command = [ ... commandRepo . values ( ) ] . find ( command => { if ( ! command . isValid ) { return false ; } return command . keys . find ( key => keyOK ( key , e ) ) ; } ) ; if ( command ) { e . preventDefault ( ) ; command . execute ( e ) ; } } export function init ( ) { window . addEventListener ( "keydown" , handleEvent ) ; } function keyOK ( key , e ) { return Object . entries ( key ) . every ( ( [ key , value ] ) => e [ key as EventProp ] == value ) ; }