task(A2): tool dispatcher behind flag

This commit is contained in:
Agent Zero
2026-08-26 21:14:46 +02:00
parent 5d7fa23825
commit 4a7a8f912f
5 changed files with 396 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
/**
* pointer.ts DOM-PointerEvent → ToolPointerEvent Normalisierung (Task A2).
* Konvertiert Bildschirmkoordinaten in Weltkoordinaten über ZoomPanController.
*/
import type { ToolPointerEvent } from '../plugins/types';
import type { ZoomPanController } from '../canvas/ZoomPanController';
/**
* Normalisiert ein Pointer/Mouse-Event zu einem ToolPointerEvent.
* @param e DOM-Event (MouseEvent ist Obermenge von PointerEvent-Feldern)
* @param canvas Das Canvas-Element (für offset-Koordinaten)
* @param zoomPan aktiver Zoom/Pan-Controller
*/
export function toToolPointerEvent(
e: MouseEvent,
canvas: HTMLCanvasElement,
zoomPan: ZoomPanController,
): ToolPointerEvent {
const rect = canvas.getBoundingClientRect();
const sx = e.clientX - rect.left;
const sy = e.clientY - rect.top;
const world = zoomPan.screenToWorld(sx, sy);
return {
world: { x: world.x, y: world.y },
screen: { x: sx, y: sy },
button: e.button,
shift: e.shiftKey,
alt: e.altKey,
ctrl: e.ctrlKey || e.metaKey,
};
}
/** Fangt weitere Pointer-Events auf dem Canvas bis zum release (Pen/Tablet- Komfort). */
export function capturePointer(canvas: HTMLCanvasElement, e: PointerEvent): void {
if (typeof canvas.setPointerCapture === 'function') {
try {
canvas.setPointerCapture(e.pointerId);
} catch {
/* pointerId evtl. schon ungültig — unkritisch */
}
}
}
/** Gibt einen vorherigen Pointer-Capture frei. */
export function releasePointer(canvas: HTMLCanvasElement, e: PointerEvent): void {
if (typeof canvas.releasePointerCapture === 'function') {
try {
canvas.releasePointerCapture(e.pointerId);
} catch {
/* ignorieren */
}
}
}