49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import type { SelectionMode } from '~/shared/types/selection';
|
|
|
|
export const useSelectionRect = defineStore('selection-rect', {
|
|
state: () => ({
|
|
enabled: false as boolean,
|
|
dirty: false as boolean,
|
|
a: {
|
|
x: 0 as number,
|
|
y: 0 as number,
|
|
},
|
|
b: {
|
|
x: 0 as number,
|
|
y: 0 as number,
|
|
},
|
|
mode: 'set' as SelectionMode,
|
|
}),
|
|
actions: {
|
|
set(
|
|
a: { x: number; y: number },
|
|
b: { x: number; y: number },
|
|
mode: SelectionMode
|
|
) {
|
|
this.a.x = a.x;
|
|
this.a.y = a.y;
|
|
|
|
this.b.x = b.x;
|
|
this.b.y = b.y;
|
|
|
|
this.enabled = true;
|
|
this.mode = mode;
|
|
},
|
|
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
|
|
);
|
|
},
|
|
},
|
|
});
|