import React,{useEffect,useRef,useState} from 'react'; import {Expand,SplitSquareHorizontal,X,ZoomIn,ZoomOut} from 'lucide-react'; import {clampPan,overlayClip,nextZoom,ZOOM_MIN,ZOOM_MAX} from './viewerMath.mjs'; // Zoom enlarges the photo; drag (mouse or finger) moves around it. In compare // mode the divider and the split always line up, at any zoom and position. export default function InspectionViewer({record,url,heatmap,onComparisonUsed}){ const [compare,setCompare]=useState(false),[position,setPosition]=useState(50),[zoom,setZoom]=useState(1),[pan,setPan]=useState({x:0,y:0}),[expanded,setExpanded]=useState(false); const dialog=useRef(null),drag=useRef(null); useEffect(()=>{setZoom(1);setPan({x:0,y:0});setPosition(50)},[record.id]); useEffect(()=>{if(expanded)dialog.current?.showModal();else dialog.current?.close()},[expanded]); const movable=zoom>1&&!compare; function changeZoom(direction){const next=nextZoom(zoom,direction);setZoom(next);setPan(value=>clampPan(value,next))} function resetView(){setZoom(1);setPan({x:0,y:0})} function start(e){ if(!movable)return; e.currentTarget.setPointerCapture?.(e.pointerId); drag.current={x:e.clientX,y:e.clientY,pan,w:e.currentTarget.clientWidth||1,h:e.currentTarget.clientHeight||1}; } function move(e){const d=drag.current;if(!d)return;setPan(clampPan({x:d.pan.x+(e.clientX-d.x)/d.w*100,y:d.pan.y+(e.clientY-d.y)/d.h*100},zoom))} function end(){drag.current=null} function image(){ const clip=overlayClip(position,zoom,pan.x); return
{help} Highlighted areas look different from normal examples. Stronger colors do not mean a more serious defect.
>; }