import Link from 'next/link'; import dynamic from 'next/dynamic'; import { ReactNode } from 'react'; import type { Block, PageBlock, Resolved } from '../lib/blocks'; const Mermaid = dynamic(() => import('./Mermaid'), { ssr: false, loading: () =>
Loading diagram…
}); const PALETTE = ['#2f5bea', '#e0702b', '#1b9e77', '#a14b9c', '#c9a227', '#d6336c', '#37a0d6']; /* ---------- inline markdown: **bold**, *italic*, `code`, [text](url) ---------- */ const safeHref = (u: string) => /^(https?:\/\/|\/|#|mailto:)/.test(u); export function inline(s: string): ReactNode[] { const out: ReactNode[] = []; const re = /(\[[^\]]+\]\([^)\s]+\))|(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*)|(`[^`]+`)/g; let last = 0; let m: RegExpExecArray | null; let k = 0; while ((m = re.exec(s))) { if (m.index > last) out.push(s.slice(last, m.index)); const t = m[0]; if (m[1]) { const [, text, url] = t.match(/^\[([^\]]+)\]\(([^)\s]+)\)$/)!; if (!safeHref(url)) out.push(text); else if (url.startsWith('/') || url.startsWith('#')) out.push({text}); else out.push({text} ↗); } else if (m[2]) out.push({inline(t.slice(2, -2))}); else if (m[3]) out.push({t.slice(1, -1)}); else out.push({t.slice(1, -1)}); last = m.index + t.length; } if (last < s.length) out.push(s.slice(last)); return out; } function MarkdownBlock({ text }: { text: string }) { return ( <> {text.replace(/\r/g, '').split(/\n{2,}/).map((raw, i) => { const src = raw.trim(); if (!src) return null; const lines = src.split('\n'); if (lines.every((l) => /^\s*[-*]\s+/.test(l))) return ; if (lines.every((l) => /^\s*\d+[.)]\s+/.test(l))) return
    {lines.map((l, j) =>
  1. {inline(l.replace(/^\s*\d+[.)]\s+/, ''))}
  2. )}
; return

{inline(lines.join(' '))}

; })} ); } /* ---------- horizontal bar chart (SVG) ---------- */ function BarChart({ d }: { d: Extract['data'] }) { const rowH = 22 + (d.series.length - 1) * 12, W = 640, L = 170, R = 56, top = 8; const H = top + d.labels.length * (rowH + 8) + 4; const max = Math.max(...d.series.flatMap((s) => s.values), 0) || 1; const X = (v: number) => (v / max) * (W - L - R); const allInt = d.series.every((s) => s.values.every(Number.isInteger)); const fmt = (v: number) => (allInt ? String(v) : v.toFixed(1)) + (d.unit ?? ''); return (
{d.title}
{d.labels.map((lab, i) => { const y = top + i * (rowH + 8); return ( {lab.length > 26 ? lab.slice(0, 25) + '…' : lab}{lab} {d.series.map((s, j) => { const h = rowH / d.series.length, yy = y + j * h; const hi = d.highlight?.includes(i); return ( {`${lab}${d.series.length > 1 ? ' · ' + s.name : ''}: ${fmt(s.values[i])}`} {fmt(s.values[i])} ); })} ); })} {d.series.length > 1 &&
{d.series.map((s, j) => {s.name})}
} {d.note &&
{d.note}
}
); } const Caption = ({ text }: { text?: string }) => (text ?
{text}
: null); const Note = ({ text, vars }: { text?: string; vars?: Record }) => text ?

{inline(Object.entries(vars ?? {}).reduce((t, [k, v]) => t.split(`{${k}}`).join(String(v)), text))}

: null; function StaticBlock({ b }: { b: Block }) { switch (b.type) { case 'markdown': return ; case 'list': { const Tag = b.data.ordered ? 'ol' : 'ul'; return <>{b.data.lead &&

{inline(b.data.lead)}

}{b.data.items.map((it, i) =>
  • {inline(it)}
  • )}
    ; } case 'callout': return
    {b.data.title && {b.data.title}. }{inline(b.data.text)}
    ; case 'table': { const d = b.data; return (
    {d.columns.map((c, i) => )}{d.rows.map((r, i) => {r.map((c, j) => )})}
    {c}
    {inline(c)}
    ); } case 'chart': return ; case 'mermaid': return ; case 'figure': return /^(https:\/\/|\/)/.test(b.data.src) ?
    {b.data.alt}{b.data.caption &&
    {b.data.caption}
    }
    : null; case 'code': return
    {b.data.text}
    ; case 'links': return (
      {b.data.items.map((l) => (
    • {l.kind}{' '} {l.url.startsWith('/') ? {l.title} : {l.title} ↗} {l.note && — {l.note}}
    • ))}
    ); default: return null; } } /** The dynamic blocks: their numbers and rows come from the database each time the page is rendered. */ function LiveBlock({ b, r }: { b: Block; r?: Resolved }) { if (!r) return null; if (b.type === 'stats' && r.type === 'stats') { return (
    {r.items.map((s, i) => { const inner = <>
    {typeof s.value === 'number' ? s.value.toLocaleString() : s.value}
    {s.label}; return s.href ? {inner} :
    {inner}
    ; })}
    ); } if (b.type === 'tool-table' && r.type === 'tool-table') { const t = r.table; return ( <> {t.rows.length === 0 &&

    No tools yet. Add them with PUT /api/tool-taxonomy/papers/<conf>/<ext_id>.

    } {t.rows.length > 0 && (
    {t.rows.map((row) => ( ))}
    CategoryPapersTools (paper)
    {row.path.slice(0, -1).map((x, i) => {x} → )} {row.title} {row.papers || ''} {row.entries.length === 0 ? '—' : row.entries.map((e, i) => (
    {e.tool}{' '} ({e.paperId ? {e.paperLabel} : e.paperLabel}) {e.via && · via {e.via}}
    ))}
    )} {t.uncategorised.length > 0 && (

    Not in any category yet: {t.uncategorised.map((e, i) => ( {i ? ', ' : ''}{e.tool} ({e.paperId ? {e.paperLabel} : e.paperLabel}) ))}

    )} ); } if (b.type === 'paper-table' && r.type === 'paper-table') { return ( <>
    {r.papers.map((p) => ( ))}
    PaperVenueDateAnalysis
    {p.title} {p.conf_short} {p.date} {p.analysed ? '✓' : ''}
    ); } if (b.type === 'benchmark-table' && r.type === 'benchmark-table') { if (!r.rows.length) return null; return ( <>
    {r.showNew && }{r.rows.map((x) => {r.showNew && })}
    BenchmarkPapersIntroduced in 2026
    {x.name}{x.n}{x.n_new || ''}
    ); } return null; } const LIVE = ['stats', 'tool-table', 'paper-table', 'benchmark-table']; /** A page body: independent blocks, one after the other. Each shows its id (#123) so it can be pointed at. */ export default function Blocks({ blocks }: { blocks: PageBlock[] }) { return (
    {blocks.map((pb) => { const live = LIVE.includes(pb.block.type); if (live && !pb.resolved) return null; return (
    #{pb.id} {live ? : }
    ); })}
    ); }