2022-11-28 22:48:42 +00:00
|
|
|
/* Here are event types */
|
|
|
|
/**
|
|
|
|
* A base event type for input handlers
|
|
|
|
*
|
|
|
|
* @typedef InputEvent
|
|
|
|
* @property {HTMLElement} target The target for the event
|
|
|
|
* @property {MouseEvent | KeyboardEvent} evn An input event
|
|
|
|
* @property {number} timestamp The time an event was emmited
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A base event type for input
|
|
|
|
*/
|
|
|
|
// TODO: Implement event typing
|
|
|
|
/**
|
|
|
|
* An object for mouse event listeners
|
|
|
|
*
|
|
|
|
* @typedef OnClickEvent
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Here are mouse context types */
|
|
|
|
/**
|
|
|
|
* An object for mouse button event listeners.
|
|
|
|
*
|
|
|
|
* Drag events are use timing and radius to determine if they will be triggered
|
|
|
|
* Paint events are triggered on any mousedown, mousemove and mouseup circunstances
|
|
|
|
*
|
|
|
|
* @typedef MouseListenerBtnContext
|
|
|
|
* @property {Observer} onclick A click handler
|
|
|
|
* @property {Observer} ondclick A double click handler
|
|
|
|
*
|
|
|
|
* @property {Observer} ondragstart A drag start handler
|
|
|
|
* @property {Observer} ondrag A drag handler
|
|
|
|
* @property {Observer} ondragend A drag end handler
|
|
|
|
*
|
|
|
|
* @property {Observer} onpaintstart A paint start handler
|
|
|
|
* @property {Observer} onpaint A paint handler
|
|
|
|
* @property {Observer} onpaintend A paint end handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object for mouse event listeners
|
|
|
|
*
|
|
|
|
* @typedef MouseListenerContext
|
2022-12-21 21:29:11 +00:00
|
|
|
* @property {Observer} onany A listener for any mouse events
|
2022-11-28 22:48:42 +00:00
|
|
|
* @property {Observer} onmousemove A mouse move handler
|
|
|
|
* @property {Observer} onwheel A mouse wheel handler
|
2022-11-29 20:55:25 +00:00
|
|
|
* @property {Record<string, MouseListenerBtnContext>} btn Button handlers
|
2022-11-28 22:48:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This callback defines how event coordinateswill be transformed
|
|
|
|
* for this context. This function should set ctx.coords appropriately.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @callback ContextMoveTransformer
|
|
|
|
* @param {MouseEvent} evn The mousemove event to be transformed
|
|
|
|
* @param {MouseContext} ctx The context object we are currently in
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A context for handling mouse coordinates and events
|
|
|
|
*
|
|
|
|
* @typedef MouseContext
|
|
|
|
* @property {string} id A unique identifier
|
|
|
|
* @property {string} name The key name
|
|
|
|
* @property {ContextMoveTransformer} onmove The coordinate transform callback
|
2022-11-29 20:55:25 +00:00
|
|
|
* @property {(evn) => void} onany A function to be run on any event
|
2022-11-28 22:48:42 +00:00
|
|
|
* @property {?HTMLElement} target The target
|
2022-12-21 21:29:11 +00:00
|
|
|
* @property {(evn) => boolean} validate A function to be check if we will process an event
|
2022-11-29 20:55:25 +00:00
|
|
|
* @property {MouseCoordContext} coords Coordinates object
|
|
|
|
* @property {MouseListenerContext} listen Listeners object
|
2022-11-28 22:48:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object for storing dragging information
|
|
|
|
*
|
|
|
|
* @typedef MouseCoordContextDragInfo
|
|
|
|
* @property {number} x X coordinate of drag start
|
|
|
|
* @property {number} y Y coordinate of drag start
|
|
|
|
* @property {HTMLElement} target Original element of drag
|
|
|
|
* @property {boolean} drag If we are in a drag
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An object for storing mouse coordinates in a context
|
|
|
|
*
|
|
|
|
* @typedef MouseCoordContext
|
|
|
|
* @property {{[key: string]: MouseCoordContextDragInfo}} dragging Information about mouse button drags
|
2022-12-15 12:43:26 +00:00
|
|
|
* @property {Point} prev Previous mouse position
|
|
|
|
* @property {Point} pos Current mouse position
|
2022-11-28 22:48:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Here are keyboard-related types */
|
|
|
|
/**
|
|
|
|
* Stores key states
|
|
|
|
*
|
|
|
|
* @typedef KeyboardKeyState
|
|
|
|
* @property {boolean} pressed If the key is currently pressed or not
|
|
|
|
* @property {boolean} held If the key is currently held or not
|
|
|
|
* @property {?number} _hold_to A timeout for detecting key holding status
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Here are the shortcut types */
|
|
|
|
/**
|
|
|
|
* Keyboard shortcut callback
|
|
|
|
*
|
|
|
|
* @callback KeyboardShortcutCallback
|
|
|
|
* @param {KeyboardEvent} evn The keyboard event that triggered this shorcut
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut information
|
|
|
|
*
|
|
|
|
* @typedef KeyboardShortcut
|
|
|
|
* @property {string} id A unique identifier for this shortcut
|
|
|
|
*
|
|
|
|
* @property {boolean} ctrl Shortcut ctrl key state
|
|
|
|
* @property {boolean} alt Shortcut alt key state
|
|
|
|
* @property {boolean} shift Shortcut shift key state
|
|
|
|
*
|
|
|
|
* @property {KeyboardShortcutCallback} callback If the key is currently held or not
|
|
|
|
*/
|