"use client"; import { motion } from "motion/react"; import { ChartFrame } from "@/components/charts/chart-frame"; export type SeqActor = { id: string; label: string }; export type SeqMessage = { from: string; to: string; label: string; dashed?: boolean }; type SequenceDiagramProps = { actors: SeqActor[]; messages: SeqMessage[]; width?: number; height?: number; className?: string; }; const TOP = 40; const MSG_GAP = 46; /** SequenceDiagram — actor boxes + dashed lifelines that draw down; messages are horizontal arrows drawn one after another top→down. */ export function SequenceDiagram({ actors, messages, width = 680, height, className }: SequenceDiagramProps) { const h = height ?? TOP + 30 + messages.length * MSG_GAP + 30; const pad = 80; const lifeX = (i: number) => (actors.length === 1 ? width / 2 : pad + (i / (actors.length - 1)) * (width - pad * 2)); const idxOf = new Map(actors.map((a, i) => [a.id, i])); return ( {({ inView, reduce }) => ( <> {actors.map((a, i) => { const x = lifeX(i); return ( {a.label} ); })} {messages.map((m, i) => { const x0 = lifeX(idxOf.get(m.from) ?? 0); const x1 = lifeX(idxOf.get(m.to) ?? 0); const y = TOP + 40 + i * MSG_GAP; const dir = x1 >= x0 ? 1 : -1; return ( {m.label} ); })} )} ); }