import { useState } from 'react'; import { Maximize2, Minimize2, Navigation } from 'lucide-react'; import { useAppStore } from '../store'; export const Minimap = () => { const { images, pan, zoom, setPan, isBrowserOpen, isLibraryOpen, isSettingsOpen } = useAppStore(); const [isCollapsed, setIsCollapsed] = useState(false); if (images.length === 0) return null; let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; images.forEach(img => { minX = Math.min(minX, img.x); minY = Math.min(minY, img.y); maxX = Math.max(maxX, img.x + img.width); maxY = Math.max(maxY, img.y + img.height); }); const contentW = Math.max(1, maxX - minX); const contentH = Math.max(1, maxY - minY); const pad = Math.max(200, Math.max(contentW, contentH) * 0.15); minX -= pad; minY -= pad; maxX += pad; maxY += pad; const width = Math.max(1, maxX - minX); const height = Math.max(1, maxY - minY); const MAP_W = 160; const MAP_H = 120; const scale = Math.min(MAP_W / width, MAP_H / height); const ox = (MAP_W - width * scale) / 2; const oy = (MAP_H - height * scale) / 2; const vpX = -pan.x / zoom; const vpY = -pan.y / zoom; const vpW = window.innerWidth / zoom; const vpH = window.innerHeight / zoom; const safeRight = isSettingsOpen ? 24 : isBrowserOpen ? 24 : 20; const safeLeftPanel = isLibraryOpen ? 8 : 20; const wrapperStyle: React.CSSProperties = { position: 'fixed', right: safeRight, bottom: 20, zIndex: 45, maxWidth: 'calc(100vw - 40px)', maxHeight: 'calc(100vh - 40px)', }; const handleClick = (e: React.PointerEvent) => { const rect = e.currentTarget.getBoundingClientRect(); const mx = e.clientX - rect.left; const my = e.clientY - rect.top; const worldX = (mx - ox) / scale + minX; const worldY = (my - oy) / scale + minY; setPan({ x: -worldX * zoom + window.innerWidth / 2, y: -worldY * zoom + window.innerHeight / 2 }); }; if (isCollapsed) { return (
); } return (
Navigator
{images.map(img => (
))}
); };