Files
warren/frontend/stores/selectionRect.ts
2025-09-04 18:31:02 +02:00

40 lines
960 B
TypeScript

export const useSelectionRect = defineStore('selection-rect', {
state: () => ({
enabled: false as boolean,
a: {
x: 0 as number,
y: 0 as number,
},
b: {
x: 0 as number,
y: 0 as number,
},
}),
actions: {
set(a: { x: number; y: number }, b: { x: number; y: number }) {
this.a.x = a.x;
this.a.y = a.y;
this.b.x = b.x;
this.b.y = b.y;
this.enabled = true;
},
updateB(x: number, y: number) {
this.b.x = x;
this.b.y = y;
},
disable() {
this.enabled = false;
},
isMinSize(minPixels: number = 10) {
return (
Math.max(
Math.abs(this.a.x - this.b.x),
Math.abs(this.a.y - this.b.y)
) >= minPixels
);
},
},
});