import { GestureResponderEvent } from 'react-native' ; import Pressability from 'react-native/Libraries/Pressability/Pressability' ; import { createEvents } from '../shared/utils' ; import { EventHandlers , EventManager } from '../types' ; /**
 * Base Pressability events and their JSX keys for native & web.
 */ export const EVENTS = { onPress : 'onClick' , onPressIn : 'onPointerDown' , onPressOut : 'onPointerUp' , onPressMove : 'onPointerMove' , } 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 ) ; const handleTouch = ( event , type ) => { event . persist ( ) ; ( event . nativeEvent as any ) . offsetX = event . nativeEvent . pageX ; ( event . nativeEvent as any ) . offsetY = event . nativeEvent . pageY ; return handleEvent ( event . nativeEvent as unknown as PointerEvent , type ) ; } ; state . events . handlers = Object . entries ( EVENTS ) . reduce ( ( acc , [ name , type ] ) => ( { ... acc , [ name ] : ( event ) => handleTouch ( event , type ) , } ) , { } ) ; const manager = new Pressability ( state . events . handlers ) ; state . events . connected = manager . getEventHandlers ( ) ; } , /**
     * Deletes and disconnects event listeners from canvas.
     */ disconnect ( _ , state ) { if ( ! state . events ?. connected ) return ; ( state . events . connected as any ) . reset ?. ( ) ; state . events . connected = false ; } , } ;