import { create } from 'zustand'; import type { Selection, SelectionType, SelectionMode, SelectionState, } from '@/types/selection'; interface SelectionStore extends SelectionState { setActiveSelection: (selection: Selection | null) => void; setSelectionType: (type: SelectionType) => void; setSelectionMode: (mode: SelectionMode) => void; setFeather: (feather: number) => void; setTolerance: (tolerance: number) => void; setMarching: (isMarching: boolean) => void; clearSelection: () => void; invertSelection: () => void; } export const useSelectionStore = create((set) => ({ activeSelection: null, selectionType: 'rectangular', selectionMode: 'new', feather: 0, tolerance: 32, isMarching: true, setActiveSelection: (selection) => set({ activeSelection: selection, }), setSelectionType: (type) => set({ selectionType: type, }), setSelectionMode: (mode) => set({ selectionMode: mode, }), setFeather: (feather) => set({ feather: Math.max(0, Math.min(250, feather)), }), setTolerance: (tolerance) => set({ tolerance: Math.max(0, Math.min(255, tolerance)), }), setMarching: (isMarching) => set({ isMarching, }), clearSelection: () => set({ activeSelection: null, }), invertSelection: () => set((state) => { if (state.activeSelection) { return { activeSelection: { ...state.activeSelection, inverted: !state.activeSelection.inverted, }, }; } return state; }), }));