import { createEvents } from '../shared/utils' ; import { EventManager } from '../types' ; /**
 * Base DOM events and their JSX keys with passive args.
 */ export const EVENTS = { click : [ 'onClick' , false ] , pointerup : [ 'onPointerUp' , true ] , pointerdown : [ 'onPointerDown' , true ] , pointermove : [ 'onPointerMove' , true ] , } as const ; /**
 * DOM OGL events manager.
 */ export const events = { connected : false , /**
     * Creates and registers event listeners on our canvas.
     */ connect ( canvas , state ) { state . events ?. disconnect ?. ( canvas , state ) ; const { handleEvent } = createEvents ( state ) ; state . events . handlers = Object . entries ( EVENTS ) . reduce ( ( acc , [ name , [ type ] ] ) => ( { ... acc , [ name ] : ( event ) => handleEvent ( event , type ) , } ) , { } ) ; Object . entries ( state . events . handlers ?? [ ] ) . forEach ( ( [ name , handler ] ) => { const [ , passive ] = EVENTS [ name ] ; canvas . addEventListener ( name , handler as any , { passive } ) ; } ) ; state . events . connected = true ; } , /**
     * Deletes and disconnects event listeners from canvas.
     */ disconnect ( canvas , state ) { Object . entries ( state . events ?. handlers ?? [ ] ) . forEach ( ( [ name , handler ] ) => { canvas . removeEventListener ( name , handler as any ) ; } ) ; state . events . connected = false ; } , } ;