/** * EventRouter - Centralized Event Management * * Consolidates keyboard, pointer, and wheel event handling from * DrawToolCore.ts and DragOperator.ts into a single unified system. * * Features: * - Single point of event registration/cleanup * - Mode-based event routing (draw, drag, contrast, crosshair, etc.) * - Prevents memory leaks through proper handler cleanup * - Eliminates duplicate keyboard listeners between DrawToolCore and DragOperator */ import type { InteractionMode, GuiTool, KeyboardHandler, PointerHandler, WheelHandler, ModeChangeCallback, EventRouterConfig, KeyboardSettings, InteractionState } from './types'; export declare class EventRouter { private container; private canvas; private mode; /** Mode to restore after a right-drag pan ends (so pan doesn't drop aiAssist). */ private modeBeforePan; private guiTool; private state; private keyboardSettings; /** When false, contrast key (Ctrl/Meta) is ignored for mode switching. */ private contrastEnabled; private onModeChange?; private modeChangeSubscribers; private keydownHandler?; private keyupHandler?; private pointerDownHandler?; private pointerMoveHandler?; private pointerUpHandler?; private pointerLeaveHandler?; private wheelHandler?; private boundKeyDown; private boundKeyUp; private boundPointerDown; private boundPointerMove; private boundPointerUp; private boundPointerLeave; private boundWheel; private boundContextMenu; private isBound; constructor(config: EventRouterConfig); /** * Bind all event listeners to DOM elements. * Call this after setting handlers. */ bindAll(): void; /** * Remove all event listeners from DOM elements. * Call this on cleanup to prevent memory leaks. */ unbindAll(): void; /** * Get the current interaction mode. */ getMode(): InteractionMode; /** * Set the interaction mode directly. */ setMode(mode: InteractionMode): void; /** * Subscribe to mode change events. * Returns an unsubscribe function. */ subscribeModeChange(callback: ModeChangeCallback): () => void; /** * Get the current GUI tool selection. */ getGuiTool(): GuiTool; /** * Set the GUI tool (from UI buttons). */ setGuiTool(tool: GuiTool): void; /** * Toggle crosshair mode. * Allowed in drawing tools AND sphere mode. * Blocked when draw or contrast mode is active, or left button is held (mutual exclusion). */ toggleCrosshair(): void; /** * Check if crosshair mode is enabled. */ isCrosshairEnabled(): boolean; /** * Get current interaction state. */ getState(): Readonly; isShiftHeld(): boolean; isCtrlHeld(): boolean; isLeftButtonDown(): boolean; isRightButtonDown(): boolean; /** * Whether the user is currently performing a slice-drag (left-button held * in idle mode with a non-sphere tool). Draw / contrast / crosshair set * `mode` away from 'idle', and sphere-family tools use left-drag for * their own purposes, so both are correctly excluded. Consumers use this * to coordinate other input streams (e.g. temporarily reinterpreting the * wheel) with an active slice-drag. */ isDragSliceActive(): boolean; /** * Update keyboard settings. */ setKeyboardSettings(settings: Partial): void; getKeyboardSettings(): KeyboardSettings; /** * Enable or disable the contrast shortcut (Ctrl/Meta key). * * When disabled: * - `ctrlHeld` state is never set to true * - The mode will not be changed to `'contrast'` via key events * - If the mode is currently `'contrast'` it is reset to `'idle'` * * The external keydown/keyup handlers are still called regardless * of this flag so other Ctrl-based shortcuts (e.g. Ctrl+Z undo) * continue to work normally. */ setContrastEnabled(enabled: boolean): void; /** Whether the contrast shortcut is currently enabled. */ isContrastEnabled(): boolean; /** * Register the keydown handler (from DrawToolCore/DragOperator). */ setKeydownHandler(handler: KeyboardHandler): void; /** * Register the keyup handler. */ setKeyupHandler(handler: KeyboardHandler): void; /** * Register pointer down handler. */ setPointerDownHandler(handler: PointerHandler): void; /** * Register pointer move handler. */ setPointerMoveHandler(handler: PointerHandler): void; /** * Register pointer up handler. */ setPointerUpHandler(handler: PointerHandler): void; /** * Register pointer leave handler. */ setPointerLeaveHandler(handler: PointerHandler): void; /** * Register wheel handler. */ setWheelHandler(handler: WheelHandler): void; private handleKeyDown; private handleKeyUp; private handlePointerDown; private handlePointerMove; private handlePointerUp; private handlePointerLeave; private handleWheel; }