@ue-too/board
Version:
<h1 align="center"> uē-tôo </h1> <p align="center"> pan, zoom, rotate, and more with your html canvas. </p>
102 lines (101 loc) • 3.57 kB
TypeScript
import { TouchInputStateMachine } from "../../input-interpretation/input-state-machine/touch-input-state-machine";
import type { InputOrchestrator } from "../input-orchestrator";
/**
* Interface for touch event parsers.
*
* @remarks
* Touch event parsers bridge DOM TouchEvents and the touch state machine.
* They provide granular control over which gesture types are enabled.
*
* @category Raw Input Parser
*/
export interface TouchEventParser {
/** Whether all touch input is disabled */
disabled: boolean;
/** Initializes event listeners */
setUp(): void;
/** Removes event listeners and cleans up */
tearDown(): void;
/** Attaches to a new canvas element */
attach(canvas: HTMLCanvasElement): void;
/** Disables the parser; the event listeners are still attached just not processing any events*/
disable(): void;
/** Enables the parser */
enable(): void;
}
/**
* DOM event parser for touch input.
*
* @remarks
* This parser converts raw DOM TouchEvents into state machine events and coordinates
* with the orchestrator to process outputs. It serves as the entry point for all touch
* input in the input interpretation pipeline.
*
* **Event Flow**:
* ```
* DOM TouchEvents → Parser → State Machine → Parser → Orchestrator → Camera/Observers
* ```
*
* **Responsibilities**:
* 1. Listen for DOM touch events (touchstart/move/end/cancel)
* 2. Extract touch point data (identifier, x, y)
* 3. Convert to state machine event format
* 4. Send events to the state machine
* 5. Forward state machine outputs to the orchestrator
*
* **Touch Point Extraction**:
* - touchstart/touchend: Uses `changedTouches` (only new/removed touches)
* - touchmove: Uses `targetTouches` (all touches on the canvas)
*
* **Gesture Control**:
* Individual gesture types (pan, zoom, rotate) can be disabled independently,
* though currently the state machine outputs are filtered by the orchestrator
* rather than the parser.
*
* The parser prevents default touch behavior to avoid browser scroll/zoom
* interfering with canvas gestures.
*
* @category Raw Input Parser
*
* @example
* ```typescript
* const canvasElement = document.getElementById("canvas");
* const stateMachine = createTouchInputStateMachine(context);
* const orchestrator = new InputOrchestrator(cameraMux, cameraRig, publisher);
* const parser = new VanillaTouchEventParser(stateMachine, orchestrator, canvasElement);
*
* parser.setUp(); // Starts listening for touch events
*
* // Disable zoom gestures temporarily
* parser.zoomDisabled = true;
*
* // Cleanup when done
* parser.tearDown();
* ```
*/
export declare class VanillaTouchEventParser implements TouchEventParser {
private _canvas?;
private _disabled;
private _panDisabled;
private _zoomDisabled;
private _rotateDisabled;
private _stateMachine;
private _orchestrator;
private _abortController;
constructor(touchInputStateMachine: TouchInputStateMachine, orchestrator: InputOrchestrator, canvas?: HTMLCanvasElement | SVGSVGElement);
get orchestrator(): InputOrchestrator;
bindListeners(): void;
enableStrategy(): void;
disableStrategy(): void;
setUp(): void;
tearDown(): void;
get disabled(): boolean;
disable(): void;
enable(): void;
private processEvent;
touchstartHandler(e: TouchEvent): void;
touchcancelHandler(e: TouchEvent): void;
touchendHandler(e: TouchEvent): void;
touchmoveHandler(e: TouchEvent): void;
attach(canvas: HTMLCanvasElement): void;
}