import type { TUIOTouch } from '../types/TUIO'; import { TangiblesManager } from '../tangible-manager/TangiblesManager.svelte'; import type { SvelteSocket } from '@hardingjam/svelte-socket'; type TouchEventListener = (touch: TUIOTouch) => void; /** * Defines a rectangular region on the screen for detecting touch and tangible events. * Touch zones allow you to register callbacks for events that occur within specific areas. */ export interface TouchZone { /** Unique identifier for the touch zone. Usually the kebab-cased name of the component. */ id: string; /** Horizontal position of the zone's left edge (0=left, 1=right) */ u: number; /** Vertical position in TUIO coordinates (0=bottom, 1=top) */ v: number; /** Width of the zone as a normalized value (0-1) */ normalisedWidth: number; /** Height of the zone as a normalized value (0-1) */ normalisedHeight: number; /** Called when a tangible object is placed within the zone */ onPlaceTangible?: TouchEventListener; /** Called when a tangible object is removed from the zone */ onRemoveTangible?: TouchEventListener; /** Called when a tangible object moves within the zone */ onMoveTangible?: TouchEventListener; /** Called when a finger touch starts within the zone */ onTouchStart?: TouchEventListener; /** Called when a finger touch moves within the zone */ onTouchMove?: TouchEventListener; /** Called when a finger touch ends within the zone */ onTouchEnd?: TouchEventListener; } /** * Configuration options for creating a TUIOHandler instance. */ export interface TUIOHandlerConfig { /** The SvelteSocket instance connected to the TUIO server */ svelteSocket: SvelteSocket; /** Callback fired when a finger touch ends (2Dcur profile). Receives normalized u,v coordinates. */ onFingerTouchEnd?: (u: number, v: number) => void; /** Callback fired when a finger touch starts (2Dcur profile). Receives normalized u,v coordinates. */ onFingerTouchStart?: (u: number, v: number) => void; /** Callback fired when a tangible object is placed (2Dobj profile). Called after TangiblesManager update. */ onPlaceTangible?: (touch: TUIOTouch) => void; /** Callback fired when a tangible object is removed (2Dobj profile). Called after TangiblesManager update. */ onRemoveTangible?: (touch: TUIOTouch) => void; /** Callback fired when a tangible object moves (2Dobj profile). Called after TangiblesManager update. */ onMoveTangible?: (touch: TUIOTouch) => void; /** Minimum time in milliseconds between callback invocations. Set to 0 to disable throttling. */ throttleTime?: number; /** Initial touch zones to register when the handler is created */ touchZones?: TouchZone[]; } /** * Manages WebSocket connections for TUIO (Tangible User Interface Objects) events. * Handles touch start, end, and move events from a TUIO-compatible server. */ export declare class TUIOHandler { svelteSocket: SvelteSocket; touchZones: TouchZone[]; tangiblesManager: TangiblesManager; private onFingerTouchEnd; private onFingerTouchStart; private onPlaceTangible?; private onRemoveTangible?; private onMoveTangible?; private throttleTime; private lastCallTimes; private messageListener; private openListener; private errorListener; /** * Creates a TUIOHandler instance. * Sets up event listeners for messages, connection status, and errors. * Parses incoming JSON data and routes to appropriate handlers. * * @param {TUIOHandlerConfig} config - Configuration object with socket and optional event handlers */ constructor(config: TUIOHandlerConfig); /** * Checks if enough time has passed since the last call to allow this callback. * @param key - Unique key for the callback being throttled * @returns true if the callback should be called, false if throttled * @private */ private shouldCallCallback; /** * Attaches event listeners to the WebSocket connection. * Sets up handlers for messages, connection status, and errors. * * @private */ private addSocketEventListeners; /** * Registers a touch zone. Events within the zone trigger the zone's callbacks. * * @param {TouchZone} zone - The touch zone configuration */ registerTouchZone(zone: TouchZone): void; /** * Removes a touch zone by its ID. * * @param {string} zoneId - The ID of the zone to remove */ unregisterTouchZone(zoneId: string): void; /** * Removes all event listeners and clears state. * Call when the handler is no longer needed. */ destroy(): void; /** * Handles finger touch start events (2Dcur profile). * Calls custom callback if provided and notifies matching touch zones. * * @param {TUIOTouch} touch - The touch event data * @private */ private handleFingerTouchStart; /** * Handles finger touch move events (2Dcur profile). * Notifies matching touch zones. * * @param {TUIOTouch} touch - The touch event data * @private */ private handleFingerTouchMove; /** * Handles finger touch end events (2Dcur profile). * Calls custom callback if provided and notifies matching touch zones. * * @param {TUIOTouch} touch - The touch event data * @private */ private handleFingerTouchEnd; /** * Checks if a touch is within a zone's bounds. * Inverts v-coordinate because TUIO uses 0 at bottom, 1 at top, * while screen coordinates use 0 at top, 1 at bottom. * * @param {TUIOTouch} touch - The touch to check * @param {TouchZone} zone - The zone to check against * @returns {boolean} True if the touch is within the zone * @private */ private isTouchInZone; /** * Handles tangible placement events (2Dobj profile). * Adds to tangibles manager and calls custom callback if provided. * * @param {TUIOTouch} touch - The touch event data * @private */ private handlePlaceTangible; /** * Handles tangible removal events (2Dobj profile). * Removes from tangibles manager and calls custom callback if provided. * * @param {TUIOTouch} touch - The touch event data * @private */ private handleRemoveTangible; /** * Handles tangible movement events (2Dobj profile). * Updates tangibles manager and calls custom callback if provided. * * @param {TUIOTouch} touch - The touch event data * @private */ private handleMoveTangible; } interface $$__sveltets_2_IsomorphicComponent = any, Events extends Record = any, Slots extends Record = any, Exports = {}, Bindings = string> { new (options: import('svelte').ComponentConstructorOptions): import('svelte').SvelteComponent & { $$bindings?: Bindings; } & Exports; (internal: unknown, props: { $$events?: Events; $$slots?: Slots; }): Exports & { $set?: any; $on?: any; }; z_$$bindings?: Bindings; } declare const TUIOHandler: $$__sveltets_2_IsomorphicComponent, { [evt: string]: CustomEvent; }, {}, {}, string>; type TUIOHandler = InstanceType; export default TUIOHandler;