| 0b4b582 | | | 1 | "use client"; |
| 0b4b582 | | | 2 | |
| 0b4b582 | | | 3 | import { useEffect, useRef, useState, useCallback } from "react"; |
| 0b4b582 | | | 4 | |
| 0b4b582 | | | 5 | interface DiagramViewerProps { |
| 0b4b582 | | | 6 | code: string; |
| 0b4b582 | | | 7 | diagramId: string; |
| 0b4b582 | | | 8 | onNodeClick?: (nodeId: string | null) => void; |
| 0b4b582 | | | 9 | } |
| 0b4b582 | | | 10 | |
| 0b4b582 | | | 11 | // ── Node Focus: dim unconnected elements on click ── |
| 0b4b582 | | | 12 | |
| 0b4b582 | | | 13 | interface GraphInfo { |
| 0b4b582 | | | 14 | adjacency: Record<string, Set<string>>; |
| 0b4b582 | | | 15 | nodeMap: Map<string, SVGElement[]>; |
| 0b4b582 | | | 16 | } |
| 0b4b582 | | | 17 | |
| 0b4b582 | | | 18 | function buildGraphFromSvg(svgEl: SVGElement): GraphInfo { |
| 0b4b582 | | | 19 | const adjacency: Record<string, Set<string>> = {}; |
| 0b4b582 | | | 20 | const nodeMap = new Map<string, SVGElement[]>(); |
| 0b4b582 | | | 21 | |
| 0b4b582 | | | 22 | const ensure = (id: string) => { |
| 0b4b582 | | | 23 | if (!adjacency[id]) adjacency[id] = new Set(); |
| 0b4b582 | | | 24 | }; |
| 0b4b582 | | | 25 | const addNode = (id: string, el: SVGElement) => { |
| 0b4b582 | | | 26 | if (!nodeMap.has(id)) nodeMap.set(id, []); |
| 0b4b582 | | | 27 | nodeMap.get(id)!.push(el); |
| 0b4b582 | | | 28 | el.classList.add("node-dimable", "node-clickable"); |
| 0b4b582 | | | 29 | }; |
| 0b4b582 | | | 30 | |
| 0b4b582 | | | 31 | // Collect nodes — extract the short ID that edges use in data-start/data-end. |
| 0b4b582 | | | 32 | // Flowchart: g.id "flowchart-Customer-0" → edge uses "Customer" |
| 0b4b582 | | | 33 | // ER: g.id "entity-policy-3" → edge uses "entity-policy-3" |
| 0b4b582 | | | 34 | svgEl.querySelectorAll<SVGElement>("g.node").forEach((g) => { |
| 0b4b582 | | | 35 | if (!g.id) return; |
| 0b4b582 | | | 36 | const parts = g.id.split("-"); |
| 0b4b582 | | | 37 | const short = parts.length >= 3 ? parts.slice(1, -1).join("-") : g.id; |
| 0b4b582 | | | 38 | addNode(short, g); |
| 0b4b582 | | | 39 | }); |
| 0b4b582 | | | 40 | svgEl |
| 0b4b582 | | | 41 | .querySelectorAll<SVGElement>( |
| 0b4b582 | | | 42 | "g[id^='entity-'], g.classGroup, g.statediagram-state" |
| 0b4b582 | | | 43 | ) |
| 0b4b582 | | | 44 | .forEach((g) => { |
| 0b4b582 | | | 45 | if (g.id) addNode(g.id, g); |
| 0b4b582 | | | 46 | }); |
| 0b4b582 | | | 47 | |
| 0b4b582 | | | 48 | // Build adjacency from data-start / data-end on edges |
| 0b4b582 | | | 49 | svgEl |
| 0b4b582 | | | 50 | .querySelectorAll<SVGElement>("[data-start][data-end]") |
| 0b4b582 | | | 51 | .forEach((el) => { |
| 0b4b582 | | | 52 | const s = el.getAttribute("data-start")!; |
| 0b4b582 | | | 53 | const e = el.getAttribute("data-end")!; |
| 0b4b582 | | | 54 | if (s && e) { |
| 0b4b582 | | | 55 | ensure(s); |
| 0b4b582 | | | 56 | ensure(e); |
| 0b4b582 | | | 57 | adjacency[s].add(e); |
| 0b4b582 | | | 58 | adjacency[e].add(s); |
| 0b4b582 | | | 59 | } |
| 0b4b582 | | | 60 | el.classList.add("node-dimable"); |
| 0b4b582 | | | 61 | }); |
| 0b4b582 | | | 62 | |
| 0b4b582 | | | 63 | // Copy data-start/data-end from edge paths onto their labels |
| 0b4b582 | | | 64 | // so labels highlight together with their edges during node focus |
| 0b4b582 | | | 65 | const pathDataById = new Map<string, { start: string; end: string }>(); |
| 0b4b582 | | | 66 | svgEl.querySelectorAll<SVGElement>("[data-start][data-end]").forEach((el) => { |
| 0b4b582 | | | 67 | if (el.id) { |
| 0b4b582 | | | 68 | pathDataById.set(el.id, { |
| 0b4b582 | | | 69 | start: el.getAttribute("data-start")!, |
| 0b4b582 | | | 70 | end: el.getAttribute("data-end")!, |
| 0b4b582 | | | 71 | }); |
| 0b4b582 | | | 72 | } |
| 0b4b582 | | | 73 | }); |
| 0b4b582 | | | 74 | svgEl.querySelectorAll<SVGElement>("g.edgeLabel").forEach((label) => { |
| 0b4b582 | | | 75 | const inner = label.querySelector("[data-id]"); |
| 0b4b582 | | | 76 | const dataId = inner?.getAttribute("data-id"); |
| 0b4b582 | | | 77 | if (dataId && pathDataById.has(dataId)) { |
| 0b4b582 | | | 78 | const { start, end } = pathDataById.get(dataId)!; |
| 0b4b582 | | | 79 | label.setAttribute("data-start", start); |
| 0b4b582 | | | 80 | label.setAttribute("data-end", end); |
| 0b4b582 | | | 81 | } |
| 0b4b582 | | | 82 | }); |
| 0b4b582 | | | 83 | |
| 0b4b582 | | | 84 | // Tag edge containers and clusters as dimable |
| 0b4b582 | | | 85 | svgEl |
| 0b4b582 | | | 86 | .querySelectorAll<SVGElement>(".edgePath, .edgeLabel, .cluster") |
| 0b4b582 | | | 87 | .forEach((el) => { |
| 0b4b582 | | | 88 | el.classList.add("node-dimable"); |
| 0b4b582 | | | 89 | }); |
| 0b4b582 | | | 90 | |
| 0b4b582 | | | 91 | // Tag loose path/line elements NOT inside a node, existing dimable, or marker defs |
| 0b4b582 | | | 92 | svgEl.querySelectorAll<SVGElement>("path, line").forEach((el) => { |
| 0b4b582 | | | 93 | if (el.closest("marker, defs")) return; |
| 0b4b582 | | | 94 | if (!el.closest(".node-dimable") && !el.closest(".node-clickable")) { |
| 0b4b582 | | | 95 | el.classList.add("node-dimable"); |
| 0b4b582 | | | 96 | } |
| 0b4b582 | | | 97 | }); |
| 0b4b582 | | | 98 | |
| 0b4b582 | | | 99 | return { adjacency, nodeMap }; |
| 0b4b582 | | | 100 | } |
| 0b4b582 | | | 101 | |
| 0b4b582 | | | 102 | function applyNodeFocus( |
| 0b4b582 | | | 103 | container: HTMLElement, |
| 0b4b582 | | | 104 | svgEl: SVGElement, |
| 0b4b582 | | | 105 | clickedNodeId: string, |
| 0b4b582 | | | 106 | adjacency: Record<string, Set<string>>, |
| 0b4b582 | | | 107 | nodeMap: Map<string, SVGElement[]> |
| 0b4b582 | | | 108 | ) { |
| 0b4b582 | | | 109 | const connected = new Set([clickedNodeId]); |
| 0b4b582 | | | 110 | if (adjacency[clickedNodeId]) |
| 0b4b582 | | | 111 | adjacency[clickedNodeId].forEach((id) => connected.add(id)); |
| 0b4b582 | | | 112 | |
| 0b4b582 | | | 113 | svgEl |
| 0b4b582 | | | 114 | .querySelectorAll(".node-highlight") |
| 0b4b582 | | | 115 | .forEach((el) => el.classList.remove("node-highlight")); |
| 0b4b582 | | | 116 | |
| 0b4b582 | | | 117 | const highlight = (el: Element) => { |
| 0b4b582 | | | 118 | el.classList.add("node-highlight"); |
| 0b4b582 | | | 119 | el.querySelectorAll(".node-dimable").forEach((child) => |
| 0b4b582 | | | 120 | child.classList.add("node-highlight") |
| 0b4b582 | | | 121 | ); |
| 0b4b582 | | | 122 | }; |
| 0b4b582 | | | 123 | |
| 0b4b582 | | | 124 | for (const [id, elements] of nodeMap) { |
| 0b4b582 | | | 125 | if (connected.has(id)) elements.forEach(highlight); |
| 0b4b582 | | | 126 | } |
| 0b4b582 | | | 127 | |
| 0b4b582 | | | 128 | svgEl |
| 0b4b582 | | | 129 | .querySelectorAll<SVGElement>("[data-start][data-end]") |
| 0b4b582 | | | 130 | .forEach((el) => { |
| 0b4b582 | | | 131 | const s = el.getAttribute("data-start")!; |
| 0b4b582 | | | 132 | const e = el.getAttribute("data-end")!; |
| 0b4b582 | | | 133 | if (connected.has(s) && connected.has(e)) highlight(el); |
| 0b4b582 | | | 134 | }); |
| 0b4b582 | | | 135 | |
| 0b4b582 | | | 136 | container.classList.add("node-focus"); |
| 0b4b582 | | | 137 | } |
| 0b4b582 | | | 138 | |
| 0b4b582 | | | 139 | function clearNodeFocus(container: HTMLElement) { |
| 0b4b582 | | | 140 | container.classList.remove("node-focus"); |
| 0b4b582 | | | 141 | const svg = container.querySelector("svg"); |
| 0b4b582 | | | 142 | if (svg) { |
| 0b4b582 | | | 143 | svg |
| 0b4b582 | | | 144 | .querySelectorAll(".node-highlight") |
| 0b4b582 | | | 145 | .forEach((el) => el.classList.remove("node-highlight")); |
| 0b4b582 | | | 146 | } |
| 0b4b582 | | | 147 | } |
| 0b4b582 | | | 148 | |
| 0b4b582 | | | 149 | function wireNodeFocus(container: HTMLElement): string | null { |
| 0b4b582 | | | 150 | const svgEl = container.querySelector("svg") as SVGElement | null; |
| 0b4b582 | | | 151 | if (!svgEl) return null; |
| 0b4b582 | | | 152 | |
| 0b4b582 | | | 153 | const { adjacency, nodeMap } = buildGraphFromSvg(svgEl); |
| 0b4b582 | | | 154 | if (Object.keys(adjacency).length === 0) return null; |
| 0b4b582 | | | 155 | |
| 0b4b582 | | | 156 | let selectedNodeId: string | null = null; |
| 0b4b582 | | | 157 | |
| 0b4b582 | | | 158 | for (const [nodeId, elements] of nodeMap) { |
| 0b4b582 | | | 159 | elements.forEach((el) => { |
| 0b4b582 | | | 160 | el.addEventListener("click", (e) => { |
| 0b4b582 | | | 161 | e.stopPropagation(); |
| 0b4b582 | | | 162 | if (selectedNodeId === nodeId) { |
| 0b4b582 | | | 163 | clearNodeFocus(container); |
| 0b4b582 | | | 164 | selectedNodeId = null; |
| 0b4b582 | | | 165 | } else { |
| 0b4b582 | | | 166 | applyNodeFocus(container, svgEl, nodeId, adjacency, nodeMap); |
| 0b4b582 | | | 167 | selectedNodeId = nodeId; |
| 0b4b582 | | | 168 | } |
| 0b4b582 | | | 169 | }); |
| 0b4b582 | | | 170 | }); |
| 0b4b582 | | | 171 | } |
| 0b4b582 | | | 172 | |
| 0b4b582 | | | 173 | return selectedNodeId; |
| 0b4b582 | | | 174 | } |
| 0b4b582 | | | 175 | |
| 0b4b582 | | | 176 | // ── CSS for node focus (injected once) ── |
| 0b4b582 | | | 177 | const NODE_FOCUS_STYLES = ` |
| 0b4b582 | | | 178 | .node-focus svg .node-dimable { |
| 0b4b582 | | | 179 | opacity: 0.1; |
| 0b4b582 | | | 180 | transition: opacity 0.2s ease; |
| 0b4b582 | | | 181 | } |
| 0b4b582 | | | 182 | .node-focus svg .node-dimable.node-highlight { |
| 0b4b582 | | | 183 | opacity: 1 !important; |
| 0b4b582 | | | 184 | transition: opacity 0.2s ease; |
| 0b4b582 | | | 185 | } |
| 0b4b582 | | | 186 | svg .node-clickable { |
| 0b4b582 | | | 187 | cursor: pointer; |
| 0b4b582 | | | 188 | } |
| 0b4b582 | | | 189 | `; |
| 0b4b582 | | | 190 | |
| 0b4b582 | | | 191 | let stylesInjected = false; |
| 0b4b582 | | | 192 | function injectNodeFocusStyles() { |
| 0b4b582 | | | 193 | if (stylesInjected) return; |
| 0b4b582 | | | 194 | stylesInjected = true; |
| 0b4b582 | | | 195 | const style = document.createElement("style"); |
| 0b4b582 | | | 196 | style.textContent = NODE_FOCUS_STYLES; |
| 0b4b582 | | | 197 | document.head.appendChild(style); |
| 0b4b582 | | | 198 | } |
| 0b4b582 | | | 199 | |
| 0b4b582 | | | 200 | export function DiagramViewer({ |
| 0b4b582 | | | 201 | code, |
| 0b4b582 | | | 202 | diagramId, |
| 0b4b582 | | | 203 | onNodeClick, |
| 0b4b582 | | | 204 | }: DiagramViewerProps) { |
| 0b4b582 | | | 205 | const wrapperRef = useRef<HTMLDivElement>(null); |
| 0b4b582 | | | 206 | const containerRef = useRef<HTMLDivElement>(null); |
| 0b4b582 | | | 207 | const [panZoom, setPanZoom] = useState({ x: 0, y: 0, scale: 1 }); |
| 0b4b582 | | | 208 | const [error, setError] = useState<string | null>(null); |
| 0b4b582 | | | 209 | const dragging = useRef(false); |
| 0b4b582 | | | 210 | const didDrag = useRef(false); |
| 0b4b582 | | | 211 | const lastPos = useRef({ x: 0, y: 0 }); |
| 0b4b582 | | | 212 | const mermaidRef = useRef<any>(null); |
| 0b4b582 | | | 213 | |
| 0b4b582 | | | 214 | // Load mermaid dynamically |
| 0b4b582 | | | 215 | useEffect(() => { |
| 0b4b582 | | | 216 | injectNodeFocusStyles(); |
| 0b4b582 | | | 217 | import("mermaid").then((mod) => { |
| 0b4b582 | | | 218 | const m = mod.default; |
| 0b4b582 | | | 219 | m.initialize({ |
| 0b4b582 | | | 220 | startOnLoad: false, |
| 0b4b582 | | | 221 | theme: "base", |
| 0b4b582 | | | 222 | themeVariables: { |
| 0b4b582 | | | 223 | primaryColor: "#e8f2ee", |
| 0b4b582 | | | 224 | primaryTextColor: "#2c2824", |
| 0b4b582 | | | 225 | primaryBorderColor: "#b0d4c5", |
| 0b4b582 | | | 226 | lineColor: "#7a746c", |
| 0b4b582 | | | 227 | secondaryColor: "#f2efe9", |
| 0b4b582 | | | 228 | tertiaryColor: "#faf8f5", |
| 0b4b582 | | | 229 | fontFamily: "'Libre Caslon Text', Georgia, serif", |
| 0b4b582 | | | 230 | fontSize: "13px", |
| 0b4b582 | | | 231 | }, |
| 0b4b582 | | | 232 | securityLevel: "loose", |
| 0b4b582 | | | 233 | }); |
| 0b4b582 | | | 234 | mermaidRef.current = m; |
| 0b4b582 | | | 235 | }); |
| 0b4b582 | | | 236 | }, []); |
| 0b4b582 | | | 237 | |
| 0b4b582 | | | 238 | // Render diagram when code changes |
| 0b4b582 | | | 239 | const render = useCallback(async () => { |
| 0b4b582 | | | 240 | const m = mermaidRef.current; |
| 0b4b582 | | | 241 | const el = containerRef.current; |
| 0b4b582 | | | 242 | if (!m || !el || !code.trim()) return; |
| 0b4b582 | | | 243 | |
| 0b4b582 | | | 244 | try { |
| 0b4b582 | | | 245 | const id = `mermaid-${diagramId}-${Date.now()}`; |
| 0b4b582 | | | 246 | const { svg } = await m.render(id, code); |
| 0b4b582 | | | 247 | el.innerHTML = svg; |
| 0b4b582 | | | 248 | setError(null); |
| 0b4b582 | | | 249 | |
| 0b4b582 | | | 250 | // Fit to container |
| 0b4b582 | | | 251 | const svgEl = el.querySelector("svg"); |
| 0b4b582 | | | 252 | if (svgEl) { |
| 0b4b582 | | | 253 | svgEl.style.width = "100%"; |
| 0b4b582 | | | 254 | svgEl.style.height = "100%"; |
| 0b4b582 | | | 255 | svgEl.style.maxWidth = "none"; |
| 0b4b582 | | | 256 | } |
| 0b4b582 | | | 257 | |
| 0b4b582 | | | 258 | // Wire up node-focus click handlers |
| 0b4b582 | | | 259 | wireNodeFocus(el); |
| 0b4b582 | | | 260 | } catch (e: any) { |
| 0b4b582 | | | 261 | setError(e.message || "Failed to render diagram"); |
| 0b4b582 | | | 262 | } |
| 0b4b582 | | | 263 | }, [code, diagramId]); |
| 0b4b582 | | | 264 | |
| 0b4b582 | | | 265 | useEffect(() => { |
| 0b4b582 | | | 266 | if (mermaidRef.current) render(); |
| 0b4b582 | | | 267 | }, [render]); |
| 0b4b582 | | | 268 | |
| 0b4b582 | | | 269 | // Also render once mermaid loads |
| 0b4b582 | | | 270 | useEffect(() => { |
| 0b4b582 | | | 271 | const check = setInterval(() => { |
| 0b4b582 | | | 272 | if (mermaidRef.current) { |
| 0b4b582 | | | 273 | clearInterval(check); |
| 0b4b582 | | | 274 | render(); |
| 0b4b582 | | | 275 | } |
| 0b4b582 | | | 276 | }, 100); |
| 0b4b582 | | | 277 | return () => clearInterval(check); |
| 0b4b582 | | | 278 | }, [render]); |
| 0b4b582 | | | 279 | |
| 0b4b582 | | | 280 | // Reset pan/zoom on diagram switch |
| 0b4b582 | | | 281 | useEffect(() => { |
| 0b4b582 | | | 282 | setPanZoom({ x: 0, y: 0, scale: 1 }); |
| 0b4b582 | | | 283 | }, [diagramId]); |
| 0b4b582 | | | 284 | |
| 0b4b582 | | | 285 | // Pan handling |
| 0b4b582 | | | 286 | const handleMouseDown = useCallback((e: React.MouseEvent) => { |
| 0b4b582 | | | 287 | if (e.button !== 0 && e.button !== 1) return; |
| 0b4b582 | | | 288 | dragging.current = true; |
| 0b4b582 | | | 289 | didDrag.current = false; |
| 0b4b582 | | | 290 | lastPos.current = { x: e.clientX, y: e.clientY }; |
| 0b4b582 | | | 291 | }, []); |
| 0b4b582 | | | 292 | |
| 0b4b582 | | | 293 | const handleMouseMove = useCallback((e: React.MouseEvent) => { |
| 0b4b582 | | | 294 | if (!dragging.current) return; |
| 0b4b582 | | | 295 | const dx = e.clientX - lastPos.current.x; |
| 0b4b582 | | | 296 | const dy = e.clientY - lastPos.current.y; |
| 0b4b582 | | | 297 | if (Math.abs(dx) > 2 || Math.abs(dy) > 2) didDrag.current = true; |
| 0b4b582 | | | 298 | lastPos.current = { x: e.clientX, y: e.clientY }; |
| 0b4b582 | | | 299 | setPanZoom((prev) => ({ ...prev, x: prev.x + dx, y: prev.y + dy })); |
| 0b4b582 | | | 300 | }, []); |
| 0b4b582 | | | 301 | |
| 0b4b582 | | | 302 | const handleMouseUp = useCallback(() => { |
| 0b4b582 | | | 303 | dragging.current = false; |
| 0b4b582 | | | 304 | }, []); |
| 0b4b582 | | | 305 | |
| 0b4b582 | | | 306 | // Click on background clears node focus |
| 0b4b582 | | | 307 | const handleClick = useCallback(() => { |
| 0b4b582 | | | 308 | if (didDrag.current) return; |
| 0b4b582 | | | 309 | if (containerRef.current) clearNodeFocus(containerRef.current); |
| 0b4b582 | | | 310 | }, []); |
| 0b4b582 | | | 311 | |
| 0b4b582 | | | 312 | // Zoom handling — must use native listener with { passive: false } to preventDefault |
| 0b4b582 | | | 313 | useEffect(() => { |
| 0b4b582 | | | 314 | const el = wrapperRef.current; |
| 0b4b582 | | | 315 | if (!el) return; |
| 0b4b582 | | | 316 | const handleWheel = (e: WheelEvent) => { |
| 0b4b582 | | | 317 | e.preventDefault(); |
| 0b4b582 | | | 318 | const delta = e.deltaY > 0 ? 0.9 : 1.1; |
| 0b4b582 | | | 319 | const rect = el.getBoundingClientRect(); |
| 0b4b582 | | | 320 | const cx = e.clientX - rect.left; |
| 0b4b582 | | | 321 | const cy = e.clientY - rect.top; |
| 0b4b582 | | | 322 | setPanZoom((prev) => { |
| 0b4b582 | | | 323 | const newScale = Math.max(0.1, Math.min(5, prev.scale * delta)); |
| 0b4b582 | | | 324 | const ratio = newScale / prev.scale; |
| 0b4b582 | | | 325 | return { |
| 0b4b582 | | | 326 | scale: newScale, |
| 0b4b582 | | | 327 | x: cx - ratio * (cx - prev.x), |
| 0b4b582 | | | 328 | y: cy - ratio * (cy - prev.y), |
| 0b4b582 | | | 329 | }; |
| 0b4b582 | | | 330 | }); |
| 0b4b582 | | | 331 | }; |
| 0b4b582 | | | 332 | el.addEventListener("wheel", handleWheel, { passive: false }); |
| 0b4b582 | | | 333 | return () => el.removeEventListener("wheel", handleWheel); |
| 0b4b582 | | | 334 | }, []); |
| 0b4b582 | | | 335 | |
| 0b4b582 | | | 336 | const resetZoom = useCallback(() => { |
| 0b4b582 | | | 337 | setPanZoom({ x: 0, y: 0, scale: 1 }); |
| 0b4b582 | | | 338 | }, []); |
| 0b4b582 | | | 339 | |
| 0b4b582 | | | 340 | return ( |
| 0b4b582 | | | 341 | <div |
| 0b4b582 | | | 342 | ref={wrapperRef} |
| 0b4b582 | | | 343 | style={{ |
| 0b4b582 | | | 344 | flex: 1, |
| 0b4b582 | | | 345 | position: "relative", |
| 0b4b582 | | | 346 | overflow: "hidden", |
| 0b4b582 | | | 347 | cursor: dragging.current ? "grabbing" : "grab", |
| 0b4b582 | | | 348 | backgroundColor: "var(--bg-page)", |
| 0b4b582 | | | 349 | }} |
| 0b4b582 | | | 350 | onMouseDown={handleMouseDown} |
| 0b4b582 | | | 351 | onMouseMove={handleMouseMove} |
| 0b4b582 | | | 352 | onMouseUp={handleMouseUp} |
| 0b4b582 | | | 353 | onMouseLeave={handleMouseUp} |
| 0b4b582 | | | 354 | onClick={handleClick} |
| 0b4b582 | | | 355 | > |
| 0b4b582 | | | 356 | <div |
| 0b4b582 | | | 357 | ref={containerRef} |
| 0b4b582 | | | 358 | style={{ |
| 0b4b582 | | | 359 | transform: `translate(${panZoom.x}px, ${panZoom.y}px) scale(${panZoom.scale})`, |
| 0b4b582 | | | 360 | transformOrigin: "0 0", |
| 0b4b582 | | | 361 | padding: "2rem", |
| 0b4b582 | | | 362 | display: "flex", |
| 0b4b582 | | | 363 | justifyContent: "center", |
| 0b4b582 | | | 364 | alignItems: "flex-start", |
| 0b4b582 | | | 365 | minHeight: "100%", |
| 0b4b582 | | | 366 | }} |
| 0b4b582 | | | 367 | /> |
| 0b4b582 | | | 368 | {error && ( |
| 0b4b582 | | | 369 | <div |
| 0b4b582 | | | 370 | className="text-xs px-3 py-2" |
| 0b4b582 | | | 371 | style={{ |
| 0b4b582 | | | 372 | position: "absolute", |
| 0b4b582 | | | 373 | bottom: "3rem", |
| 0b4b582 | | | 374 | left: "1rem", |
| 0b4b582 | | | 375 | right: "1rem", |
| 0b4b582 | | | 376 | backgroundColor: "var(--bg-card)", |
| 0b4b582 | | | 377 | border: "1px solid var(--border)", |
| 0b4b582 | | | 378 | color: "var(--text-muted)", |
| 0b4b582 | | | 379 | }} |
| 0b4b582 | | | 380 | > |
| 0b4b582 | | | 381 | {error} |
| 0b4b582 | | | 382 | </div> |
| 0b4b582 | | | 383 | )} |
| 0b4b582 | | | 384 | <div |
| 0b4b582 | | | 385 | className="flex items-center gap-1 text-xs" |
| 0b4b582 | | | 386 | style={{ |
| 0b4b582 | | | 387 | position: "absolute", |
| 0b4b582 | | | 388 | bottom: "0.75rem", |
| 0b4b582 | | | 389 | left: "50%", |
| 0b4b582 | | | 390 | transform: "translateX(-50%)", |
| 0b4b582 | | | 391 | }} |
| 0b4b582 | | | 392 | > |
| 0b4b582 | | | 393 | <button |
| 0b4b582 | | | 394 | onClick={() => |
| 0b4b582 | | | 395 | setPanZoom((p) => ({ ...p, scale: Math.min(5, p.scale * 1.2) })) |
| 0b4b582 | | | 396 | } |
| 0b4b582 | | | 397 | className="px-2 py-1" |
| 0b4b582 | | | 398 | style={{ |
| 0b4b582 | | | 399 | background: "var(--bg-card)", |
| 0b4b582 | | | 400 | border: "1px solid var(--border)", |
| 0b4b582 | | | 401 | color: "var(--text-muted)", |
| 0b4b582 | | | 402 | cursor: "pointer", |
| 0b4b582 | | | 403 | font: "inherit", |
| 0b4b582 | | | 404 | }} |
| 0b4b582 | | | 405 | > |
| 0b4b582 | | | 406 | + |
| 0b4b582 | | | 407 | </button> |
| 0b4b582 | | | 408 | <button |
| 0b4b582 | | | 409 | onClick={resetZoom} |
| 0b4b582 | | | 410 | className="px-2 py-1" |
| 0b4b582 | | | 411 | style={{ |
| 0b4b582 | | | 412 | background: "var(--bg-card)", |
| 0b4b582 | | | 413 | border: "1px solid var(--border)", |
| 0b4b582 | | | 414 | color: "var(--text-muted)", |
| 0b4b582 | | | 415 | cursor: "pointer", |
| 0b4b582 | | | 416 | font: "inherit", |
| 0b4b582 | | | 417 | }} |
| 0b4b582 | | | 418 | > |
| 0b4b582 | | | 419 | {Math.round(panZoom.scale * 100)}% |
| 0b4b582 | | | 420 | </button> |
| 0b4b582 | | | 421 | <button |
| 0b4b582 | | | 422 | onClick={() => |
| 0b4b582 | | | 423 | setPanZoom((p) => ({ ...p, scale: Math.max(0.1, p.scale * 0.8) })) |
| 0b4b582 | | | 424 | } |
| 0b4b582 | | | 425 | className="px-2 py-1" |
| 0b4b582 | | | 426 | style={{ |
| 0b4b582 | | | 427 | background: "var(--bg-card)", |
| 0b4b582 | | | 428 | border: "1px solid var(--border)", |
| 0b4b582 | | | 429 | color: "var(--text-muted)", |
| 0b4b582 | | | 430 | cursor: "pointer", |
| 0b4b582 | | | 431 | font: "inherit", |
| 0b4b582 | | | 432 | }} |
| 0b4b582 | | | 433 | > |
| 0b4b582 | | | 434 | − |
| 0b4b582 | | | 435 | </button> |
| 0b4b582 | | | 436 | </div> |
| 0b4b582 | | | 437 | </div> |
| 0b4b582 | | | 438 | ); |
| 0b4b582 | | | 439 | } |