The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 85 lines 2.52 KB
Raw
1 import type { CodeStep } from "../../shared/intro.ts";
2 import { type Area, spanRect } from "./CodeSlide.tsx";
3 import { drawProgress, stroke, TONE, underlinePath } from "./draw.tsx";
4
5 /**
6 * How two side-by-side files are coupled: each link underlines a piece of
7 * text on the left, the piece it must agree with on the right, and draws a
8 * line between them. Links draw one after another.
9 */
10 export const LinksView = ({
11 step,
12 prev,
13 left,
14 right,
15 local,
16 delay,
17 }: {
18 step: CodeStep;
19 prev?: CodeStep;
20 left: Area;
21 right: Area;
22 local: number;
23 delay: number;
24 }) => {
25 if (!step.links || !step.beside) return null;
26 const text = (s: CodeStep, span: { line: number; col: number; len: number }) =>
27 (s.lines[span.line] ?? [])
28 .map((t) => t.text)
29 .join("")
30 .slice(span.col, span.col + span.len);
31 // A link already drawn on the previous step (same text at both ends, same tone) stays drawn.
32 const drawn = (link: NonNullable<CodeStep["links"]>[number]) =>
33 !!prev?.links &&
34 !!prev.beside &&
35 prev.links.some(
36 (p) =>
37 (p.tone ?? "construct") === (link.tone ?? "construct") &&
38 text(prev, p.from) === text(step, link.from) &&
39 text(prev.beside!, p.to) === text(step.beside!, link.to),
40 );
41 let order = 0;
42 return (
43 <svg
44 width={1920}
45 height={1080}
46 style={{ position: "absolute", left: 0, top: 0, overflow: "visible" }}
47 >
48 {step.links.map((link, i) => {
49 const color = TONE[link.tone ?? "construct"];
50 const a = spanRect(step, left, link.from);
51 const b = spanRect(step.beside!, right, link.to);
52 const start = drawn(link) ? -100 : delay + order++ * 8;
53 const ay = a.y + a.h * 0.92;
54 const by = b.y + b.h * 0.92;
55 const x1 = a.x + a.w;
56 const x2 = b.x;
57 const bend = Math.max(60, (x2 - x1) * 0.45);
58 return (
59 <g key={i}>
60 {stroke(
61 underlinePath(a.x, ay, a.w, i * 7 + 1),
62 color,
63 drawProgress(local, start, 6),
64 3,
65 )}
66 <g opacity={0.7}>
67 {stroke(
68 `M ${x1} ${ay} C ${x1 + bend} ${ay}, ${x2 - bend} ${by}, ${x2} ${by}`,
69 color,
70 drawProgress(local, start + 4, 7),
71 2,
72 )}
73 </g>
74 {stroke(
75 underlinePath(b.x, by, b.w, i * 7 + 4),
76 color,
77 drawProgress(local, start + 9, 6),
78 3,
79 )}
80 </g>
81 );
82 })}
83 </svg>
84 );
85 };