Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | 'use client' import { useEffect, useRef } from 'react' import { BYRNE } from '../types' import { CITATIONS } from '../engine/citations' import { PROP_REGISTRY } from '../propositions/registry' import { usePropPreviews } from '../render/usePropPreviews' import { FOUNDATION_ITEMS, FOUNDATION_DIAGRAMS } from './foundationsData' import { EuclidFoundationCanvas } from './EuclidFoundationCanvas' import { getFoundationIdForCitation, getFoundationHref, getPropositionHref, getPropIdForCitation, } from './citationUtils' const POPOVER_WIDTH = 248 /** Accent color for the citation label, keyed by citation prefix. */ function labelColor(citationKey: string): string { if (citationKey.startsWith('Def.')) return BYRNE.red if (citationKey.startsWith('Post.')) return BYRNE.yellow if (citationKey.startsWith('C.N.')) return BYRNE.blue return BYRNE.given } interface CitationPopoverProps { citationKey: string anchorRect: DOMRect onClose: () => void /** Called when the pointer enters the popover — lets caller cancel close timers. */ onMouseEnter?: () => void /** Called when the pointer leaves the popover. */ onMouseLeave?: () => void } export function CitationPopover({ citationKey, anchorRect, onClose, onMouseEnter, onMouseLeave, }: CitationPopoverProps) { const popoverRef = useRef<HTMLDivElement>(null) // Resolve content const citDef = CITATIONS[citationKey] const foundationId = getFoundationIdForCitation(citationKey) const foundationItem = foundationId ? FOUNDATION_ITEMS.find((f) => f.id === foundationId) : null const diagram = foundationId ? FOUNDATION_DIAGRAMS[foundationId] : null // For proposition citations (I.1, I.2, …) const propMatch = citationKey.match(/^I\.(\d+)$/) const propId = propMatch ? parseInt(propMatch[1], 10) : null const propDef = propId != null ? PROP_REGISTRY[propId] : null // Pre-rendered proposition previews (same rendering path as the Euclid map) const propPreviews = usePropPreviews() const propPreviewSrc = propId != null ? (propPreviews.get(propId) ?? null) : null const activeDiagram = diagram ?? null const foundationHref = getFoundationHref(citationKey) const propositionHref = getPropIdForCitation(citationKey) != null ? getPropositionHref(citationKey) : null // Positioning: prefer left of anchor (into canvas), fall back to above/below const vw = typeof window !== 'undefined' ? window.innerWidth : 1200 const vh = typeof window !== 'undefined' ? window.innerHeight : 800 const preferredLeft = anchorRect.left - POPOVER_WIDTH - 8 const fitsLeft = preferredLeft >= 16 let left: number let top: number if (fitsLeft) { left = preferredLeft // Center vertically on anchor, clamped to viewport top = Math.max(16, Math.min(vh - 400, anchorRect.top + anchorRect.height / 2 - 150)) } else { // Place above the anchor, horizontally aligned to it left = Math.max(16, Math.min(vw - POPOVER_WIDTH - 16, anchorRect.left)) top = anchorRect.top - 8 - 300 // 300 = rough popover height estimate if (top < 16) { // Fall back to below top = anchorRect.bottom + 8 } top = Math.max(16, Math.min(vh - 400, top)) } // Keyboard dismiss useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', onKey) return () => window.removeEventListener('keydown', onKey) }, [onClose]) const accentColor = labelColor(citationKey) const label = citDef?.label ?? citationKey const title = foundationItem?.title ?? propDef?.title ?? null const statement = foundationItem?.statement ?? citDef?.text ?? null const plain = foundationItem?.plain ?? null return ( <div ref={popoverRef} data-component="citation-popover" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} style={{ position: 'fixed', left, top, width: POPOVER_WIDTH, zIndex: 500, background: 'rgba(252, 252, 248, 0.97)', border: '1px solid rgba(203, 213, 225, 0.8)', borderRadius: 12, boxShadow: '0 8px 32px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.08)', padding: '12px 14px', display: 'flex', flexDirection: 'column', gap: 10, animation: 'euclid-popover-in 0.12s ease-out', pointerEvents: 'auto', }} > <style>{` @keyframes euclid-popover-in { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } } `}</style> {/* Label */} <div style={{ fontSize: '0.7rem', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: accentColor, fontFamily: 'system-ui, sans-serif', }} > {label} {title && ( <span style={{ color: '#1e293b', marginLeft: 6, fontWeight: 600 }}>— {title}</span> )} </div> {/* Foundation diagram (Def, Post, C.N.) */} {activeDiagram && ( <div style={{ width: '100%', height: 140 }}> <EuclidFoundationCanvas diagram={activeDiagram} /> </div> )} {/* Proposition preview — same rendering as the Euclid map */} {propPreviewSrc && ( <div style={{ width: '100%', height: 140, borderRadius: 16, overflow: 'hidden', border: '1px solid rgba(203, 213, 225, 0.6)', background: '#FAFAF0', boxSizing: 'border-box', display: 'flex', alignItems: 'center', justifyContent: 'center', }} > <img src={propPreviewSrc} alt="" style={{ width: '100%', height: '100%', objectFit: 'contain' }} /> </div> )} {/* Statement */} {statement && ( <div style={{ fontSize: '0.82rem', color: '#1e293b', fontFamily: 'Georgia, serif', fontStyle: 'italic', lineHeight: 1.5, }} > {statement} </div> )} {/* Plain English */} {plain && ( <div style={{ fontSize: '0.78rem', color: '#64748b', fontFamily: 'system-ui, sans-serif', lineHeight: 1.45, paddingTop: 2, borderTop: '1px solid rgba(203, 213, 225, 0.5)', }} > {plain} </div> )} {/* Foundation page link (opens in new tab) */} {foundationHref && ( <a href={foundationHref} target="_blank" rel="noopener noreferrer" style={{ fontSize: '0.72rem', color: '#10b981', fontFamily: 'system-ui, sans-serif', fontWeight: 600, textDecoration: 'none', display: 'flex', alignItems: 'center', gap: 3, paddingTop: 2, }} onMouseEnter={(e) => ((e.currentTarget as HTMLElement).style.textDecoration = 'underline') } onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.textDecoration = 'none')} > Open full page → </a> )} {/* Proposition page link (navigates in-page) */} {propositionHref && ( <a href={propositionHref} style={{ fontSize: '0.72rem', color: '#10b981', fontFamily: 'system-ui, sans-serif', fontWeight: 600, textDecoration: 'none', display: 'flex', alignItems: 'center', gap: 3, paddingTop: 2, }} onMouseEnter={(e) => ((e.currentTarget as HTMLElement).style.textDecoration = 'underline') } onMouseLeave={(e) => ((e.currentTarget as HTMLElement).style.textDecoration = 'none')} > Open proposition → </a> )} </div> ) } |