'use client'; import { useState } from 'react'; import { useSelectionStore } from '@/store/selection-store'; import { useToolStore } from '@/store/tool-store'; import { useHistoryStore } from '@/store/history-store'; import { copySelection, cutSelection, deleteSelection, fillSelection, strokeSelection, pasteCanvas, } from '@/lib/selection-operations'; import { ClearSelectionCommand, InvertSelectionCommand, } from '@/core/commands/selection-command'; import type { SelectionType, SelectionMode } from '@/types/selection'; import { Square, Circle, Lasso, Wand2, Copy, Scissors, Trash2, FlipVertical, X, PlusSquare, MinusSquare, Layers, Paintbrush, Clipboard, } from 'lucide-react'; import { cn } from '@/lib/utils'; const SELECTION_TOOLS: Array<{ type: SelectionType; label: string; icon: React.ComponentType<{ className?: string }>; }> = [ { type: 'rectangular', label: 'Rectangle', icon: Square }, { type: 'elliptical', label: 'Ellipse', icon: Circle }, { type: 'lasso', label: 'Lasso', icon: Lasso }, { type: 'magic-wand', label: 'Magic Wand', icon: Wand2 }, ]; const SELECTION_MODES: Array<{ mode: SelectionMode; label: string; icon: React.ComponentType<{ className?: string }>; }> = [ { mode: 'new', label: 'New', icon: Square }, { mode: 'add', label: 'Add', icon: PlusSquare }, { mode: 'subtract', label: 'Subtract', icon: MinusSquare }, { mode: 'intersect', label: 'Intersect', icon: Layers }, ]; export function SelectionPanel() { const { activeSelection, selectionType, selectionMode, feather, tolerance, setSelectionType, setSelectionMode, setFeather, setTolerance, clearSelection, invertSelection, } = useSelectionStore(); const { setActiveTool, settings } = useToolStore(); const { executeCommand } = useHistoryStore(); const [copiedCanvas, setCopiedCanvas] = useState( null ); const hasSelection = !!activeSelection; const handleToolSelect = (type: SelectionType) => { setSelectionType(type); setActiveTool('select'); }; const handleCopy = () => { const canvas = copySelection(); if (canvas) { setCopiedCanvas(canvas); } }; const handleCut = () => { const canvas = cutSelection(); if (canvas) { setCopiedCanvas(canvas); } }; const handlePaste = () => { if (copiedCanvas) { pasteCanvas(copiedCanvas); } }; const handleDelete = () => { deleteSelection(); }; const handleClear = () => { const command = new ClearSelectionCommand(); executeCommand(command); }; const handleInvert = () => { const command = new InvertSelectionCommand(); executeCommand(command); }; const handleFill = () => { fillSelection(settings.color); }; const handleStroke = () => { strokeSelection(settings.color, 2); }; return (
{/* Header */}

Selection

{/* Selection Tools */}

Tools

{SELECTION_TOOLS.map((tool) => ( ))}
{/* Selection Modes */}

Mode

{SELECTION_MODES.map((mode) => ( ))}
{/* Selection Parameters */}

Parameters

{/* Feather */}
setFeather(Number(e.target.value))} className="w-full" />
{feather}px
{/* Tolerance (for magic wand) */} {selectionType === 'magic-wand' && (
setTolerance(Number(e.target.value))} className="w-full" />
{tolerance}
)}
{/* Selection Operations */}

Operations

{!hasSelection && (

Use selection tools to create a selection

)}
); }