Implement LineTool.ts

This commit is contained in:
2026-06-22 07:22:56 +00:00
parent c79a87ff6e
commit d5b645e5b3
+39
View File
@@ -0,0 +1,39 @@
import { Tool } from '../Tool';
import { YjsDocument } from '../../crdt/YjsDocument';
class LineTool extends Tool {
private startPoint: { x: number; y: number } | null = null;
constructor(yjsDoc: YjsDocument) {
super(yjsDoc);
this.name = 'LineTool';
}
onMouseDown(event: MouseEvent): void {
if (!this.startPoint) {
this.startPoint = { x: event.clientX, y: event.clientY };
} else {
// Create line element in Yjs document
this.yjsDoc.createLine(this.startPoint.x, this.startPoint.y, event.clientX, event.clientY);
this.startPoint = null;
}
}
onMouseMove(event: MouseEvent): void {
// Preview line while dragging
}
onMouseUp(event: MouseEvent): void {
// Handle mouse up if needed
}
onKeyUp(event: KeyboardEvent): void {
// Handle key up events
}
reset(): void {
this.startPoint = null;
}
}
export { LineTool };