sveltekit-sync
Version:
Local-first sync engine for SvelteKit
45 lines (44 loc) • 1.26 kB
TypeScript
/**
* Cursor Tracking Utility
*
* Automatically tracks mouse movements and displays cursors for other users.
*/
import type { UsePresenceReturn } from '../hooks/usePresence.svelte.js';
import type { User, CursorPosition } from '../presence.svelte.js';
export interface CursorTrackingOptions {
throttle?: number;
container?: HTMLElement;
}
export interface CursorTrackingReturn {
cursors: Map<string, {
user: User;
position: CursorPosition;
}>;
startTracking(): void;
stopTracking(): void;
}
/**
* Track cursor positions for collaborative editing
*
* @param presence - The presence hook instance
* @param options - Configuration options
* @returns Cursor tracking API
*
* @example
* ```typescript
* const presence = usePresence(channel, currentUser);
* const cursorTracking = useCursorTracking(presence, {
* throttle: 50,
* container: canvasElement
* });
*
* cursorTracking.startTracking();
*
* // Access cursors map
* const cursors = cursorTracking.cursors;
* for (const [userId, { user, position }] of cursors) {
* renderCursor(user, position);
* }
* ```
*/
export declare function useCursorTracking(presence: UsePresenceReturn<any>, options?: CursorTrackingOptions): CursorTrackingReturn;