'use client' import type { EditableCell } from './overlay-reconstruction-types' import type { WordPosition } from './usePixelWordPositions' interface OverlayCellRendererProps { cell: EditableCell displayText: string edited: boolean wordPositions: WordPosition[] | undefined medianCellHeightPx: number fontScale: number globalBold: boolean colorValue: string handleTextChange: (cellId: string, newText: string) => void handleKeyDown: (e: React.KeyboardEvent, cellId: string) => void resetCell: (cellId: string) => void } /** Renders a single cell in the overlay -- either as pixel-positioned word spans or a fallback input. */ export function OverlayCellRenderer({ cell, displayText, edited, wordPositions, medianCellHeightPx, fontScale, globalBold, colorValue, handleTextChange, handleKeyDown, resetCell, }: OverlayCellRendererProps) { const bboxPct = cell.bboxPct const fontFamily = "'Liberation Sans', Arial, sans-serif" // Pixel-analysed: render word-groups at detected positions if (wordPositions && wordPositions.length > 0) { return ( <> {wordPositions.map((wp, i) => { const autoFontPx = medianCellHeightPx * wp.fontRatio * fontScale const fs = Math.max(6, autoFontPx) if (wordPositions.length > 1) { return ( {wp.text} ) } return (
handleTextChange(cell.cellId, e.target.value)} onKeyDown={(e) => handleKeyDown(e, cell.cellId)} className={`w-full h-full bg-transparent border-0 outline-none px-0 transition-colors ${ edited ? 'bg-green-50/30' : '' }`} style={{ fontSize: `${fs}px`, fontWeight: globalBold ? 'bold' : 'normal', fontFamily, lineHeight: '1', color: colorValue, }} title={`${cell.cellId} (${cell.colType})`} />
) })} ) } // Fallback: no pixel data -- single input at cell bbox if (!cell.text) return null const fontSize = Math.max(6, medianCellHeightPx * fontScale) return (
handleTextChange(cell.cellId, e.target.value)} onKeyDown={(e) => handleKeyDown(e, cell.cellId)} className={`w-full h-full bg-transparent border-0 outline-none px-0 transition-colors ${ edited ? 'bg-green-50/30' : '' }`} style={{ fontSize: `${fontSize}px`, fontWeight: globalBold ? 'bold' : 'normal', fontFamily, lineHeight: '1', color: colorValue, }} title={`${cell.cellId} (${cell.colType})`} />
) } function ResetButton({ edited, cellId, resetCell }: { edited: boolean; cellId: string; resetCell: (id: string) => void }) { if (!edited) return null return ( ) }