The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { AbsoluteFill, Img, interpolate, spring, staticFile, useVideoConfig } from "remotion"; |
| 2 | import type { CodeStep, Mark, Token } from "../../shared/intro.ts"; |
| 3 | import { hand, mono, sans } from "../fonts.ts"; |
| 4 | import { brand, vscode } from "../theme.ts"; |
| 5 | import { BundleView } from "./Bundle.tsx"; |
| 6 | import { |
| 7 | Arrow, |
| 8 | boxPath, |
| 9 | circlePath, |
| 10 | drawProgress, |
| 11 | stroke, |
| 12 | strikePath, |
| 13 | TONE, |
| 14 | underlinePath, |
| 15 | } from "./draw.tsx"; |
| 16 | import { DrillView } from "./Drill.tsx"; |
| 17 | import { graphAnchor, MiniGraphView } from "./MiniGraph.tsx"; |
| 18 | import { ReqView, reqHeight } from "./Req.tsx"; |
| 19 | import { TimelineView } from "./Timeline.tsx"; |
| 20 | |
| 21 | /** The code canvas, inside the frame and above the caption band. */ |
| 22 | /** Below the step title at the top of the frame. */ |
| 23 | const AREA = { x: 110, y: 170, width: 1700, height: 870 }; |
| 24 | export type Area = typeof AREA; |
| 25 | /** Two files side by side: each gets half the canvas. The left pane starts where full-width code does. */ |
| 26 | export const SPLIT = { |
| 27 | left: { ...AREA, width: 850 }, |
| 28 | right: { ...AREA, x: 990, width: 820 }, |
| 29 | /** The left pane's top half, when a generated file sits under it. */ |
| 30 | leftTop: { ...AREA, width: 850, height: 390 }, |
| 31 | /** Under the left pane: a file generated from it. */ |
| 32 | leftBottom: { ...AREA, y: 620, width: 850, height: 420 }, |
| 33 | }; |
| 34 | const PANEL_WIDTH = 560; |
| 35 | /** Width kept for the drawing when a step has one. */ |
| 36 | export const DIAGRAM_WIDTH = 760; |
| 37 | /** Left edge of the drawing (MiniGraph's area). */ |
| 38 | const DRAWING_X = 1090; |
| 39 | const CHAR = 0.6; |
| 40 | const LINE = 1.55; |
| 41 | |
| 42 | const lineText = (tokens: Token[]) => tokens.map((t) => t.text).join(""); |
| 43 | |
| 44 | /** Pixel geometry for the code block, centred in whatever space it gets. */ |
| 45 | const layout = (step: CodeStep, area: Area = AREA) => { |
| 46 | const width = |
| 47 | area.width - |
| 48 | (step.diagram || step.timeline |
| 49 | ? DIAGRAM_WIDTH + 60 |
| 50 | : step.panel || step.drill || step.req || step.bundle || (step.error && !step.error.below) |
| 51 | ? PANEL_WIDTH + 60 |
| 52 | : 0); |
| 53 | const size = step.fontSize; |
| 54 | const cw = size * CHAR; |
| 55 | const lh = size * LINE; |
| 56 | const longest = Math.max(...step.lines.map((l) => lineText(l).length), 1); |
| 57 | const blockW = longest * cw; |
| 58 | const blockH = step.lines.length * lh; |
| 59 | // Code sits at the same left edge on every step, so it never shifts sideways |
| 60 | // when a panel comes or goes. Only a one-line hero snippet is centred. |
| 61 | const left = step.lines.length > 1 ? area.x + 30 : area.x + Math.max(0, (width - blockW) / 2); |
| 62 | // With a drawing the program grows over several steps: pin its first line |
| 63 | // so new lines extend downward instead of pushing the code up. |
| 64 | // Code always starts at the same spot under its label; only a one-line hero is centred. |
| 65 | const top = |
| 66 | step.diagram || step.lines.length > 1 |
| 67 | ? area.y + 90 |
| 68 | : area.y + 50 + Math.max(0, (area.height - 50 - blockH) / 2); |
| 69 | return { size, cw, lh, left, top, blockW, blockH, width }; |
| 70 | }; |
| 71 | |
| 72 | const rect = ( |
| 73 | step: CodeStep, |
| 74 | g: ReturnType<typeof layout>, |
| 75 | mark: { line: number; col: number; len: number }, |
| 76 | ) => ({ |
| 77 | x: g.left + mark.col * g.cw, |
| 78 | y: g.top + mark.line * g.lh, |
| 79 | w: mark.len * g.cw, |
| 80 | h: g.lh, |
| 81 | }); |
| 82 | |
| 83 | /** |
| 84 | * Lines of the previous code step in the same group, matched to this step's |
| 85 | * lines so unchanged lines glide from where they were. |
| 86 | */ |
| 87 | const matchLines = (prev: CodeStep | undefined, step: CodeStep) => { |
| 88 | const from = new Map<number, number>(); |
| 89 | if (!prev || prev.group !== step.group) return from; |
| 90 | const used = new Set<number>(); |
| 91 | const prevText = prev.lines.map((l) => lineText(l).trim()); |
| 92 | step.lines.forEach((line, i) => { |
| 93 | const text = lineText(line).trim(); |
| 94 | if (!text) return; |
| 95 | let best = -1; |
| 96 | for (let j = 0; j < prevText.length; j++) { |
| 97 | if (used.has(j) || prevText[j] !== text) continue; |
| 98 | if (best < 0 || Math.abs(j - i) < Math.abs(best - i)) best = j; |
| 99 | } |
| 100 | if (best >= 0) { |
| 101 | used.add(best); |
| 102 | from.set(i, best); |
| 103 | } |
| 104 | }); |
| 105 | return from; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * Changed lines that are a small edit of a previous line: the columns that |
| 110 | * differ (in the new line), so only that span is highlighted and fades in. |
| 111 | */ |
| 112 | const modifiedLines = (prev: CodeStep, step: CodeStep, matched: Map<number, number>) => { |
| 113 | const out = new Map<number, { from: number; start: number; end: number }>(); |
| 114 | const taken = new Set(matched.values()); |
| 115 | // Compare without indentation, so re-indenting a line isn't an edit. |
| 116 | const prevText = prev.lines.map((l) => lineText(l).trimStart()); |
| 117 | const prevIndent = prev.lines.map((l) => lineText(l).length - lineText(l).trimStart().length); |
| 118 | step.lines.forEach((line, i) => { |
| 119 | const full = lineText(line); |
| 120 | const indent = full.length - full.trimStart().length; |
| 121 | const text = full.trimStart(); |
| 122 | if (matched.has(i) || !text) return; |
| 123 | let best: { from: number; start: number; end: number; score: number } | undefined; |
| 124 | prevText.forEach((old, j) => { |
| 125 | if (taken.has(j) || !old.trim()) return; |
| 126 | let pre = 0; |
| 127 | while (pre < old.length && pre < text.length && old[pre] === text[pre]) pre++; |
| 128 | let suf = 0; |
| 129 | while ( |
| 130 | suf < old.length - pre && |
| 131 | suf < text.length - pre && |
| 132 | old[old.length - 1 - suf] === text[text.length - 1 - suf] |
| 133 | ) |
| 134 | suf++; |
| 135 | const score = pre + suf; |
| 136 | // Mostly the same line, or the old line with something inserted into it. |
| 137 | const insertion = score >= old.length && old.trim().length >= 2; |
| 138 | // The old line with something taken out: nothing new to highlight. |
| 139 | const deletion = score >= text.length && text.trim().length >= 2; |
| 140 | // Re-indented lines only count when they just lost text (e.g. being wrapped). |
| 141 | if (!deletion && prevIndent[j] !== indent) return; |
| 142 | if (!insertion && !deletion && score < Math.max(old.length, text.length) * 0.4) return; |
| 143 | if (!deletion && text.length - suf <= pre) return; |
| 144 | if ( |
| 145 | !best || |
| 146 | score > best.score || |
| 147 | (score === best.score && Math.abs(j - i) < Math.abs(best.from - i)) |
| 148 | ) |
| 149 | best = { from: j, start: indent + pre, end: indent + text.length - suf, score }; |
| 150 | }); |
| 151 | if (best) { |
| 152 | taken.add(best.from); |
| 153 | out.set(i, { from: best.from, start: best.start, end: best.end }); |
| 154 | } |
| 155 | }); |
| 156 | return out; |
| 157 | }; |
| 158 | |
| 159 | /** Tokens split at a column range, so part of a line can be styled on its own. */ |
| 160 | const sliceTokens = (tokens: Token[], start: number, end: number) => { |
| 161 | const out: { token: Token; inside: boolean }[] = []; |
| 162 | let col = 0; |
| 163 | for (const token of tokens) { |
| 164 | const a = col; |
| 165 | const b = col + token.text.length; |
| 166 | const cuts = [a, Math.min(Math.max(start, a), b), Math.min(Math.max(end, a), b), b]; |
| 167 | for (let k = 0; k < 3; k++) { |
| 168 | if (cuts[k + 1]! > cuts[k]!) |
| 169 | out.push({ |
| 170 | token: { ...token, text: token.text.slice(cuts[k]! - a, cuts[k + 1]! - a) }, |
| 171 | inside: k === 1, |
| 172 | }); |
| 173 | } |
| 174 | col = b; |
| 175 | } |
| 176 | return out; |
| 177 | }; |
| 178 | |
| 179 | const MarkView = ({ |
| 180 | mark, |
| 181 | g, |
| 182 | step, |
| 183 | progress, |
| 184 | index, |
| 185 | }: { |
| 186 | mark: Mark; |
| 187 | g: ReturnType<typeof layout>; |
| 188 | step: CodeStep; |
| 189 | progress: number; |
| 190 | index: number; |
| 191 | }) => { |
| 192 | const r = rect(step, g, mark); |
| 193 | const color = TONE[mark.tone ?? "construct"]; |
| 194 | const seed = index * 13 + mark.line * 7 + mark.col; |
| 195 | let path: string; |
| 196 | if (mark.kind === "circle") path = circlePath(r.x, r.y, r.w, r.h, seed); |
| 197 | else if (mark.kind === "underline") path = underlinePath(r.x, r.y + r.h * 0.92, r.w, seed); |
| 198 | else if (mark.kind === "strike") path = strikePath(r.x, r.y + r.h * 0.52, r.w, seed); |
| 199 | else if (mark.kind === "box") { |
| 200 | const lastLine = mark.toLine ?? mark.line; |
| 201 | const w = mark.toLine |
| 202 | ? Math.max(...step.lines.slice(mark.line, lastLine + 1).map((l) => lineText(l).length)) * |
| 203 | g.cw - |
| 204 | mark.col * g.cw |
| 205 | : r.w; |
| 206 | path = boxPath(r.x, r.y, w, (lastLine - mark.line + 1) * g.lh, seed); |
| 207 | } else path = ""; |
| 208 | |
| 209 | // An arrowed label sits well clear of the code, with the arrow bridging the gap. |
| 210 | const reach = mark.arrow ? 110 : 0; |
| 211 | const labelPos = (() => { |
| 212 | switch (mark.side ?? "right") { |
| 213 | case "below": |
| 214 | return { |
| 215 | x: r.x + r.w / 2, |
| 216 | y: r.y + r.h + (mark.kind === "circle" ? 34 : 22) + reach, |
| 217 | anchor: "middle" as const, |
| 218 | }; |
| 219 | case "above": |
| 220 | return { |
| 221 | x: r.x + r.w / 2, |
| 222 | y: r.y - (mark.kind === "circle" ? 30 : 16), |
| 223 | anchor: "middle" as const, |
| 224 | }; |
| 225 | case "left": |
| 226 | return { x: r.x - 40, y: r.y + r.h / 2 + 10, anchor: "end" as const }; |
| 227 | default: { |
| 228 | // Past the end of the line, so the label never sits on code. |
| 229 | const lineEnd = g.left + lineText(step.lines[mark.line] ?? []).length * g.cw; |
| 230 | const x = Math.max(r.x + r.w + (mark.kind === "circle" ? 44 : 28), lineEnd + 36); |
| 231 | return { x, y: r.y + r.h / 2 + 10, anchor: "start" as const }; |
| 232 | } |
| 233 | } |
| 234 | })(); |
| 235 | const labelIn = interpolate(progress, [0.55, 1], [0, 1], { |
| 236 | extrapolateLeft: "clamp", |
| 237 | extrapolateRight: "clamp", |
| 238 | }); |
| 239 | const labelSize = Math.min(52, Math.max(34, g.size * 1.05)); |
| 240 | const labelLines = (mark.label ?? "").split("\n"); |
| 241 | const arrowIn = interpolate(progress, [0.35, 0.8], [0, 1], { |
| 242 | extrapolateLeft: "clamp", |
| 243 | extrapolateRight: "clamp", |
| 244 | }); |
| 245 | |
| 246 | return ( |
| 247 | <g> |
| 248 | {mark.kind === "highlight" ? ( |
| 249 | <rect |
| 250 | x={r.x - 8} |
| 251 | y={r.y + 4} |
| 252 | width={(r.w + 16) * progress} |
| 253 | height={r.h - 8} |
| 254 | rx={6} |
| 255 | fill={color} |
| 256 | opacity={0.22} |
| 257 | /> |
| 258 | ) : ( |
| 259 | stroke(path, color, progress, mark.kind === "strike" ? 5 : 4) |
| 260 | )} |
| 261 | {mark.label ? ( |
| 262 | <text |
| 263 | x={labelPos.x} |
| 264 | y={labelPos.y} |
| 265 | textAnchor={labelPos.anchor} |
| 266 | fill={color} |
| 267 | fontFamily={hand} |
| 268 | fontWeight={700} |
| 269 | fontSize={labelSize} |
| 270 | opacity={labelIn} |
| 271 | stroke={brand.bg} |
| 272 | strokeWidth={12} |
| 273 | strokeLinejoin="round" |
| 274 | paintOrder="stroke" |
| 275 | > |
| 276 | {labelLines.map((line, i) => ( |
| 277 | <tspan key={i} x={labelPos.x} dy={i === 0 ? 0 : labelSize * 1.05}> |
| 278 | {line} |
| 279 | </tspan> |
| 280 | ))} |
| 281 | </text> |
| 282 | ) : null} |
| 283 | {mark.arrow && mark.label && (mark.side === "below" || mark.side === "above") ? ( |
| 284 | <Arrow |
| 285 | x1={labelPos.x - 30} |
| 286 | y1={mark.side === "below" ? labelPos.y - labelSize * 0.9 : labelPos.y + labelSize * 0.4} |
| 287 | x2={r.x + r.w / 2} |
| 288 | y2={mark.side === "below" ? r.y + r.h + 10 : r.y - 10} |
| 289 | color={color} |
| 290 | progress={arrowIn} |
| 291 | bend={0.18} |
| 292 | /> |
| 293 | ) : null} |
| 294 | </g> |
| 295 | ); |
| 296 | }; |
| 297 | |
| 298 | export const CodeSlide = ({ |
| 299 | step, |
| 300 | prev, |
| 301 | prev2, |
| 302 | local, |
| 303 | area = AREA, |
| 304 | }: { |
| 305 | step: CodeStep; |
| 306 | prev?: CodeStep; |
| 307 | /** The step before `prev`: what was dimmed and drawn when this step began. */ |
| 308 | prev2?: CodeStep; |
| 309 | local: number; |
| 310 | /** Where the code sits: the whole canvas, or one side of a split. */ |
| 311 | area?: Area; |
| 312 | }) => { |
| 313 | const { fps } = useVideoConfig(); |
| 314 | const g = layout(step, area); |
| 315 | const morph = prev && prev.group === step.group; |
| 316 | const matched = matchLines(morph ? prev : undefined, step); |
| 317 | const pg = prev ? layout(prev, area) : g; |
| 318 | const asideIn = |
| 319 | prev?.aside?.text === step.aside?.text |
| 320 | ? 1 |
| 321 | : interpolate(local, [4, 12], [0, 1], { |
| 322 | extrapolateLeft: "clamp", |
| 323 | extrapolateRight: "clamp", |
| 324 | }); |
| 325 | // The photo lands after the text, with a little overshoot. |
| 326 | const photoIn = |
| 327 | prev?.aside?.image === step.aside?.image |
| 328 | ? 1 |
| 329 | : spring({ frame: local - 12, fps, config: { damping: 11, stiffness: 160 } }); |
| 330 | const t = morph |
| 331 | ? interpolate(local, [0, 8], [0, 1], { |
| 332 | extrapolateLeft: "clamp", |
| 333 | extrapolateRight: "clamp", |
| 334 | easing: (x) => 1 - (1 - x) ** 3, |
| 335 | }) |
| 336 | : interpolate(local, [0, 6], [0, 1], { extrapolateLeft: "clamp", extrapolateRight: "clamp" }); |
| 337 | const newIn = morph |
| 338 | ? interpolate(local, [2, 8], [0, 1], { extrapolateLeft: "clamp", extrapolateRight: "clamp" }) |
| 339 | : t; |
| 340 | const marksStart = morph ? 6 : 4; |
| 341 | |
| 342 | // Lines new or changed since the previous step stay bright; the rest dims. |
| 343 | // Each line moves from how bright it was at the end of the previous step. |
| 344 | // Only an edit gets highlighted: when most of the code is new, it's a different snippet. |
| 345 | const isEdit = (from: CodeStep, to: CodeStep, m: Map<number, number>) => |
| 346 | m.size >= from.lines.filter((l) => lineText(l).trim()).length / 2 && to.lines.length > 0; |
| 347 | // A step with a diff shows its changes as -/+ lines; otherwise changed lines are worked out here. |
| 348 | const edit = !step.diff && !!morph && isEdit(prev!, step, matched); |
| 349 | const changed = (i: number) => |
| 350 | step.diff ? !!step.diff[i] : edit && !matched.has(i) && !!lineText(step.lines[i] ?? []).trim(); |
| 351 | const modified = edit |
| 352 | ? modifiedLines(prev!, step, matched) |
| 353 | : new Map<number, { from: number; start: number; end: number }>(); |
| 354 | const anyChanged = |
| 355 | step.tints.length === 0 && !step.quiet && step.lines.some((_, i) => changed(i)); |
| 356 | const morph2 = !!prev && !!prev2 && prev.group === step.group && prev2.group === prev.group; |
| 357 | const prevMatched = morph2 ? matchLines(prev2, prev!) : new Map<number, number>(); |
| 358 | const prevEdit = morph2 && isEdit(prev2!, prev!, prevMatched); |
| 359 | const prevChanged = (j: number) => |
| 360 | prev?.diff |
| 361 | ? !!prev.diff[j] |
| 362 | : prevEdit && !prevMatched.has(j) && !!lineText(prev!.lines[j] ?? []).trim(); |
| 363 | const prevAny = |
| 364 | (morph2 || !!prev?.diff) && |
| 365 | prev!.tints.length === 0 && |
| 366 | !prev!.quiet && |
| 367 | prev!.lines.some((_, j) => prevChanged(j)); |
| 368 | const dimT = interpolate(local, [0, 8], [0, 1], { |
| 369 | extrapolateLeft: "clamp", |
| 370 | extrapolateRight: "clamp", |
| 371 | }); |
| 372 | // Lines with a mark on them stay bright too: dimming what's circled fights the circle. |
| 373 | const marked = (i: number) => step.marks.some((m) => i >= m.line && i <= (m.toLine ?? m.line)); |
| 374 | const lineLevel = (i: number) => { |
| 375 | const target = anyChanged ? (changed(i) || marked(i) ? 1 : 0.4) : 1; |
| 376 | const from = matched.get(i); |
| 377 | const start = from === undefined ? target : prevAny ? (prevChanged(from) ? 1 : 0.4) : 1; |
| 378 | return start + (target - start) * dimT; |
| 379 | }; |
| 380 | // A mark already drawn in the previous step stays drawn instead of redrawing. |
| 381 | const sameMark = (m: Mark) => |
| 382 | !!morph && |
| 383 | prev!.marks.some( |
| 384 | (p) => |
| 385 | p.kind === m.kind && |
| 386 | lineText(prev!.lines[p.line] ?? []).slice(p.col, p.col + p.len) === |
| 387 | lineText(step.lines[m.line] ?? []).slice(m.col, m.col + m.len), |
| 388 | ); |
| 389 | |
| 390 | const tintOf = (i: number) => step.tints.find((tint) => i >= tint.from && i <= tint.to); |
| 391 | const focused = (i: number) => !step.focus || (i >= step.focus.from && i <= step.focus.to); |
| 392 | |
| 393 | return ( |
| 394 | <AbsoluteFill> |
| 395 | {step.file || step.pseudo ? ( |
| 396 | <div |
| 397 | style={{ |
| 398 | position: "absolute", |
| 399 | left: area.x, |
| 400 | top: area.y, |
| 401 | display: "flex", |
| 402 | alignItems: "center", |
| 403 | gap: 12, |
| 404 | // What the code is: the imaginary language, or the file being shown. |
| 405 | fontFamily: mono, |
| 406 | fontSize: 22, |
| 407 | color: brand.fgMuted, |
| 408 | // Continuing the same code: the label is already there. |
| 409 | opacity: morph ? 1 : t, |
| 410 | }} |
| 411 | > |
| 412 | {step.pseudo ? "an imaginary cloud language" : step.file} |
| 413 | </div> |
| 414 | ) : null} |
| 415 | {step.diagram ? ( |
| 416 | <div |
| 417 | style={{ |
| 418 | position: "absolute", |
| 419 | left: DRAWING_X, |
| 420 | top: AREA.y, |
| 421 | fontFamily: mono, |
| 422 | fontSize: 22, |
| 423 | color: brand.fgMuted, |
| 424 | opacity: morph ? 1 : t, |
| 425 | }} |
| 426 | > |
| 427 | the cloud |
| 428 | </div> |
| 429 | ) : null} |
| 430 | {/* a diff: removed lines in red with -, added lines in green with + */} |
| 431 | {step.diff |
| 432 | ? step.diff.map((d, i) => { |
| 433 | if (!d) return null; |
| 434 | const add = d.kind === "add"; |
| 435 | // A step that says what it adds (resource, binding, API) tints its new lines in the pyramid's colour. |
| 436 | const layer = add && step.layer ? LAYER[step.layer] : undefined; |
| 437 | const color = layer ? layer.color : add ? "#2ea043" : "#f85149"; |
| 438 | const first = add && !step.diff![i - 1]?.kind; |
| 439 | return ( |
| 440 | <div key={`diff-${i}`} style={{ opacity: add ? newIn : 1 }}> |
| 441 | <div |
| 442 | style={{ |
| 443 | position: "absolute", |
| 444 | left: g.left - 40, |
| 445 | top: g.top + i * g.lh, |
| 446 | width: g.blockW + 66, |
| 447 | height: g.lh, |
| 448 | background: layer |
| 449 | ? `${layer.color}24` |
| 450 | : add |
| 451 | ? "rgba(46, 160, 67, 0.16)" |
| 452 | : "rgba(248, 81, 73, 0.16)", |
| 453 | }} |
| 454 | /> |
| 455 | {layer && first && step.diff!.findIndex((x) => x?.kind === "add") === i ? ( |
| 456 | <div |
| 457 | style={{ |
| 458 | position: "absolute", |
| 459 | left: g.left + g.blockW + 44, |
| 460 | top: g.top + i * g.lh, |
| 461 | height: g.lh, |
| 462 | lineHeight: `${g.lh}px`, |
| 463 | fontFamily: hand, |
| 464 | fontWeight: 700, |
| 465 | fontSize: Math.max(30, g.size * 1.3), |
| 466 | color: layer.color, |
| 467 | whiteSpace: "nowrap", |
| 468 | }} |
| 469 | > |
| 470 | ← {layer.label} |
| 471 | </div> |
| 472 | ) : null} |
| 473 | {d.start !== undefined && d.end !== undefined && d.end > d.start ? ( |
| 474 | <div |
| 475 | style={{ |
| 476 | position: "absolute", |
| 477 | left: g.left + d.start * g.cw - 3, |
| 478 | top: g.top + i * g.lh + 3, |
| 479 | width: (d.end - d.start) * g.cw + 6, |
| 480 | height: g.lh - 6, |
| 481 | borderRadius: 4, |
| 482 | background: layer |
| 483 | ? `${layer.color}66` |
| 484 | : add |
| 485 | ? "rgba(46, 160, 67, 0.4)" |
| 486 | : "rgba(248, 81, 73, 0.4)", |
| 487 | }} |
| 488 | /> |
| 489 | ) : null} |
| 490 | <div |
| 491 | style={{ |
| 492 | position: "absolute", |
| 493 | left: g.left - 32, |
| 494 | top: g.top + i * g.lh, |
| 495 | height: g.lh, |
| 496 | lineHeight: `${g.lh}px`, |
| 497 | fontFamily: mono, |
| 498 | fontSize: g.size, |
| 499 | fontWeight: 700, |
| 500 | color, |
| 501 | }} |
| 502 | > |
| 503 | {add ? "+" : "-"} |
| 504 | </div> |
| 505 | </div> |
| 506 | ); |
| 507 | }) |
| 508 | : null} |
| 509 | {/* lines new or changed since the previous step in this sequence, in diff green */} |
| 510 | {/* Steps that tint phases are about the phases, not the edit: no change highlight. */} |
| 511 | {edit && step.tints.length === 0 && !step.quiet |
| 512 | ? step.lines.map((tokens, i) => { |
| 513 | if (matched.has(i) || !lineText(tokens).trim()) return null; |
| 514 | const span = modified.get(i); |
| 515 | if (span && span.end <= span.start) return null; |
| 516 | if (span) { |
| 517 | // An edit within the line: mark the line, highlight just the new part. |
| 518 | return ( |
| 519 | <div key={`added-${i}`}> |
| 520 | <div |
| 521 | style={{ |
| 522 | position: "absolute", |
| 523 | left: g.left - 26, |
| 524 | top: g.top + i * g.lh, |
| 525 | width: 4, |
| 526 | height: g.lh, |
| 527 | background: "#2ea043", |
| 528 | opacity: newIn, |
| 529 | }} |
| 530 | /> |
| 531 | <div |
| 532 | style={{ |
| 533 | position: "absolute", |
| 534 | left: g.left + span.start * g.cw - 4, |
| 535 | top: g.top + i * g.lh + 3, |
| 536 | width: (span.end - span.start) * g.cw + 8, |
| 537 | height: g.lh - 6, |
| 538 | borderRadius: 5, |
| 539 | background: "rgba(46, 160, 67, 0.3)", |
| 540 | opacity: newIn, |
| 541 | }} |
| 542 | /> |
| 543 | </div> |
| 544 | ); |
| 545 | } |
| 546 | return ( |
| 547 | <div |
| 548 | key={`added-${i}`} |
| 549 | style={{ |
| 550 | position: "absolute", |
| 551 | left: g.left - 26, |
| 552 | top: g.top + i * g.lh, |
| 553 | width: g.blockW + 52, |
| 554 | height: g.lh, |
| 555 | background: "rgba(46, 160, 67, 0.22)", |
| 556 | borderLeft: "4px solid #2ea043", |
| 557 | opacity: newIn, |
| 558 | }} |
| 559 | /> |
| 560 | ); |
| 561 | }) |
| 562 | : null} |
| 563 | {/* phase tints: a bar in the gutter and a faint wash behind the lines */} |
| 564 | {step.lines.map((_, i) => { |
| 565 | const tint = tintOf(i); |
| 566 | if (!tint) return null; |
| 567 | return ( |
| 568 | <div |
| 569 | key={`tint-${i}`} |
| 570 | style={{ |
| 571 | position: "absolute", |
| 572 | left: g.left - 26, |
| 573 | top: g.top + i * g.lh, |
| 574 | width: g.blockW + 40, |
| 575 | height: g.lh, |
| 576 | background: `linear-gradient(90deg, ${TONE[tint.tone]}26, ${TONE[tint.tone]}08 70%, transparent)`, |
| 577 | borderLeft: `4px solid ${TONE[tint.tone]}`, |
| 578 | opacity: newIn, |
| 579 | }} |
| 580 | /> |
| 581 | ); |
| 582 | })} |
| 583 | {step.lines.map((tokens, i) => { |
| 584 | const span = modified.get(i); |
| 585 | // An edited line glides from its old position; only the new part fades in. |
| 586 | const from = matched.get(i) ?? span?.from; |
| 587 | const y0 = from !== undefined ? pg.top + from * pg.lh : g.top + i * g.lh; |
| 588 | const indentOf = (t: string) => t.length - t.trimStart().length; |
| 589 | const shift = |
| 590 | from !== undefined |
| 591 | ? (indentOf(lineText(prev!.lines[from] ?? [])) - indentOf(lineText(tokens))) * g.cw |
| 592 | : 0; |
| 593 | const x0 = from !== undefined ? pg.left + shift : g.left; |
| 594 | const y = y0 + (g.top + i * g.lh - y0) * t; |
| 595 | const x = x0 + (g.left - x0) * t; |
| 596 | const size = |
| 597 | (from !== undefined ? pg.size : g.size) + |
| 598 | (g.size - (from !== undefined ? pg.size : g.size)) * t; |
| 599 | const opacity = (from !== undefined ? 1 : newIn) * (focused(i) ? 1 : 0.28) * lineLevel(i); |
| 600 | const parts = span |
| 601 | ? sliceTokens(tokens, span.start, span.end) |
| 602 | : tokens.map((token) => ({ token, inside: false })); |
| 603 | return ( |
| 604 | <div |
| 605 | key={`line-${i}`} |
| 606 | style={{ |
| 607 | position: "absolute", |
| 608 | left: x, |
| 609 | top: y, |
| 610 | height: g.lh, |
| 611 | lineHeight: `${g.lh}px`, |
| 612 | fontFamily: mono, |
| 613 | fontSize: size, |
| 614 | whiteSpace: "pre", |
| 615 | opacity, |
| 616 | }} |
| 617 | > |
| 618 | {parts.map(({ token, inside }, k) => ( |
| 619 | <span |
| 620 | key={k} |
| 621 | style={{ |
| 622 | color: token.color, |
| 623 | opacity: inside ? newIn : 1, |
| 624 | fontWeight: token.bold ? 700 : undefined, |
| 625 | }} |
| 626 | > |
| 627 | {token.text} |
| 628 | </span> |
| 629 | ))} |
| 630 | </div> |
| 631 | ); |
| 632 | })} |
| 633 | {step.error ? ( |
| 634 | <ErrorView |
| 635 | step={step} |
| 636 | g={g} |
| 637 | local={local} |
| 638 | delay={marksStart} |
| 639 | minTop={step.req ? g.top + reqHeight(step.req) + 20 : AREA.y} |
| 640 | /> |
| 641 | ) : null} |
| 642 | {step.bundle ? ( |
| 643 | <BundleView |
| 644 | bundle={step.bundle} |
| 645 | prev={prev?.bundle} |
| 646 | x={AREA.x + AREA.width - PANEL_WIDTH} |
| 647 | labelY={AREA.y} |
| 648 | top={g.top} |
| 649 | local={local} |
| 650 | delay={marksStart} |
| 651 | /> |
| 652 | ) : null} |
| 653 | {step.req ? ( |
| 654 | <ReqView |
| 655 | req={step.req} |
| 656 | prev={prev?.req} |
| 657 | x={AREA.x + AREA.width - PANEL_WIDTH} |
| 658 | labelY={AREA.y} |
| 659 | top={g.top} |
| 660 | local={local} |
| 661 | delay={marksStart} |
| 662 | /> |
| 663 | ) : null} |
| 664 | <svg |
| 665 | width={1920} |
| 666 | height={1080} |
| 667 | style={{ position: "absolute", left: 0, top: 0, overflow: "visible" }} |
| 668 | > |
| 669 | {step.marks.map((mark, i) => ( |
| 670 | <MarkView |
| 671 | key={i} |
| 672 | mark={mark} |
| 673 | g={g} |
| 674 | step={step} |
| 675 | index={i} |
| 676 | progress={sameMark(mark) ? 1 : drawProgress(local, marksStart + i * 4, 9)} |
| 677 | /> |
| 678 | ))} |
| 679 | </svg> |
| 680 | {step.timeline ? ( |
| 681 | <TimelineView timeline={step.timeline} local={local} delay={marksStart} /> |
| 682 | ) : null} |
| 683 | {step.diagram ? ( |
| 684 | <MiniGraphView |
| 685 | graph={step.diagram} |
| 686 | prev={morph ? prev?.diagram : undefined} |
| 687 | prev2={morph && prev2?.group === step.group ? prev2.diagram : undefined} |
| 688 | local={local} |
| 689 | delay={marksStart} |
| 690 | /> |
| 691 | ) : null} |
| 692 | {step.diagram && step.diagramLinks ? ( |
| 693 | <svg |
| 694 | width={1920} |
| 695 | height={1080} |
| 696 | style={{ position: "absolute", left: 0, top: 0, overflow: "visible" }} |
| 697 | > |
| 698 | {step.diagramLinks.map((link, i) => { |
| 699 | const to = graphAnchor(step.diagram!, link.to); |
| 700 | if (!to) return null; |
| 701 | const color = TONE[link.tone ?? "construct"]; |
| 702 | const r = rect(step, g, link.from); |
| 703 | // The underline runs on along the baseline to just past the code, bends |
| 704 | // to the target's height there, then runs straight in: turning early |
| 705 | // keeps the arc clear of nodes and notes between the code and its target. |
| 706 | const y1 = r.y + r.h * 0.92; |
| 707 | const gx = g.left + Math.max(...step.lines.map((l) => lineText(l).length)) * g.cw + 14; |
| 708 | // A link that was already drawn on the previous step stays drawn. |
| 709 | const text = (st: CodeStep, sp: { line: number; col: number; len: number }) => |
| 710 | lineText(st.lines[sp.line] ?? []).slice(sp.col, sp.col + sp.len); |
| 711 | const drawn = prev?.diagramLinks?.some( |
| 712 | (p) => |
| 713 | JSON.stringify(p.to) === JSON.stringify(link.to) && |
| 714 | text(prev, p.from) === text(step, link.from), |
| 715 | ); |
| 716 | const start = drawn ? -100 : marksStart + i * 6; |
| 717 | return ( |
| 718 | <g key={i}> |
| 719 | {stroke( |
| 720 | underlinePath(r.x, y1, r.w, i * 5 + 2), |
| 721 | color, |
| 722 | drawProgress(local, start, 6), |
| 723 | 3, |
| 724 | )} |
| 725 | <g opacity={0.75}> |
| 726 | {stroke( |
| 727 | `M ${r.x + r.w} ${y1} L ${gx} ${y1} C ${gx + 55} ${y1}, ${gx + 30} ${to.y}, ${gx + 85} ${to.y} L ${to.x} ${to.y}`, |
| 728 | color, |
| 729 | drawProgress(local, start + 3, 9), |
| 730 | 2.5, |
| 731 | )} |
| 732 | </g> |
| 733 | </g> |
| 734 | ); |
| 735 | })} |
| 736 | </svg> |
| 737 | ) : null} |
| 738 | {step.cross ? ( |
| 739 | <svg |
| 740 | width={1920} |
| 741 | height={1080} |
| 742 | style={{ position: "absolute", left: 0, top: 0, overflow: "visible" }} |
| 743 | > |
| 744 | {(() => { |
| 745 | // Two quick hand-drawn strokes over the code block, already drawn if the previous step had them. |
| 746 | const x0 = g.left - 20; |
| 747 | const y0 = g.top - 16; |
| 748 | const x1 = g.left + g.blockW + 20; |
| 749 | const y1 = g.top + g.blockH + 16; |
| 750 | const at = prev?.cross ? -100 : 4; |
| 751 | return ( |
| 752 | <> |
| 753 | {stroke( |
| 754 | `M ${x0} ${y0} Q ${(x0 + x1) / 2 + 18} ${(y0 + y1) / 2 - 14}, ${x1} ${y1}`, |
| 755 | TONE.bad, |
| 756 | drawProgress(local, at, 7), |
| 757 | 12, |
| 758 | )} |
| 759 | {stroke( |
| 760 | `M ${x1 + 6} ${y0 + 8} Q ${(x0 + x1) / 2 - 12} ${(y0 + y1) / 2 - 10}, ${x0 - 4} ${y1 - 6}`, |
| 761 | TONE.bad, |
| 762 | drawProgress(local, at + 6, 7), |
| 763 | 12, |
| 764 | )} |
| 765 | </> |
| 766 | ); |
| 767 | })()} |
| 768 | </svg> |
| 769 | ) : null} |
| 770 | {step.aside?.at === "left" ? ( |
| 771 | <div |
| 772 | style={{ |
| 773 | position: "absolute", |
| 774 | left: AREA.x + 20, |
| 775 | bottom: 1080 - (AREA.y + AREA.height) + 6, |
| 776 | display: "flex", |
| 777 | alignItems: "center", |
| 778 | gap: 34, |
| 779 | }} |
| 780 | > |
| 781 | {step.aside.image ? ( |
| 782 | <div |
| 783 | style={{ |
| 784 | width: 400, |
| 785 | padding: 12, |
| 786 | background: "#f4efe4", |
| 787 | borderRadius: 6, |
| 788 | boxShadow: "0 18px 50px rgba(0, 0, 0, 0.55)", |
| 789 | transform: `rotate(${-3 + (1 - photoIn) * 10}deg) scale(${photoIn})`, |
| 790 | transformOrigin: "center bottom", |
| 791 | opacity: Math.min(1, photoIn * 2), |
| 792 | }} |
| 793 | > |
| 794 | <Img |
| 795 | src={staticFile(`intro/assets/${step.aside.image}`)} |
| 796 | style={{ width: "100%", display: "block", borderRadius: 3 }} |
| 797 | /> |
| 798 | </div> |
| 799 | ) : null} |
| 800 | <div |
| 801 | style={{ |
| 802 | fontFamily: hand, |
| 803 | fontWeight: 700, |
| 804 | fontSize: 54, |
| 805 | lineHeight: 1.05, |
| 806 | color: TONE[step.aside.tone ?? "construct"], |
| 807 | transform: `rotate(-4deg) scale(${0.85 + asideIn * 0.15})`, |
| 808 | opacity: asideIn, |
| 809 | whiteSpace: "pre", |
| 810 | }} |
| 811 | > |
| 812 | {step.aside.text} |
| 813 | </div> |
| 814 | </div> |
| 815 | ) : null} |
| 816 | {step.aside?.image && step.aside.at !== "left" ? ( |
| 817 | <div |
| 818 | style={{ |
| 819 | position: "absolute", |
| 820 | right: 1920 - (AREA.x + AREA.width) + 40, |
| 821 | bottom: 1080 - (AREA.y + AREA.height) + 170, |
| 822 | width: 330, |
| 823 | padding: 12, |
| 824 | paddingBottom: 12, |
| 825 | background: "#f4efe4", |
| 826 | borderRadius: 6, |
| 827 | boxShadow: "0 18px 50px rgba(0, 0, 0, 0.55)", |
| 828 | transform: `rotate(${4 - (1 - photoIn) * 10}deg) scale(${photoIn})`, |
| 829 | transformOrigin: "center bottom", |
| 830 | opacity: Math.min(1, photoIn * 2), |
| 831 | }} |
| 832 | > |
| 833 | <Img |
| 834 | src={staticFile(`intro/assets/${step.aside.image}`)} |
| 835 | style={{ width: "100%", display: "block", borderRadius: 3 }} |
| 836 | /> |
| 837 | </div> |
| 838 | ) : null} |
| 839 | {step.aside && step.aside.at !== "left" ? ( |
| 840 | <div |
| 841 | style={{ |
| 842 | position: "absolute", |
| 843 | right: 1920 - (AREA.x + AREA.width) + 10, |
| 844 | bottom: 1080 - (AREA.y + AREA.height) + 40, |
| 845 | fontFamily: hand, |
| 846 | fontWeight: 700, |
| 847 | fontSize: 84, |
| 848 | lineHeight: 1, |
| 849 | whiteSpace: "nowrap", |
| 850 | color: TONE[step.aside.tone ?? "construct"], |
| 851 | textShadow: "0 0 24px rgba(0, 0, 0, 0.6)", |
| 852 | transform: `rotate(-5deg) scale(${0.85 + asideIn * 0.15})`, |
| 853 | transformOrigin: "right bottom", |
| 854 | opacity: asideIn, |
| 855 | }} |
| 856 | > |
| 857 | {step.aside.text} |
| 858 | <svg |
| 859 | width="100%" |
| 860 | height={24} |
| 861 | viewBox="0 0 600 24" |
| 862 | preserveAspectRatio="none" |
| 863 | style={{ display: "block", overflow: "visible" }} |
| 864 | > |
| 865 | {stroke( |
| 866 | underlinePath(0, 10, 600, 11), |
| 867 | TONE[step.aside.tone ?? "construct"], |
| 868 | drawProgress(local, 10, 8), |
| 869 | 5, |
| 870 | )} |
| 871 | </svg> |
| 872 | </div> |
| 873 | ) : null} |
| 874 | {step.drill ? ( |
| 875 | <DrillView |
| 876 | drill={step.drill} |
| 877 | x={AREA.x + AREA.width - PANEL_WIDTH} |
| 878 | labelY={AREA.y} |
| 879 | top={g.top} |
| 880 | local={local} |
| 881 | delay={marksStart + step.marks.filter((m) => !sameMark(m)).length * 4} |
| 882 | /> |
| 883 | ) : null} |
| 884 | {step.panel ? ( |
| 885 | <Panel step={step} local={local} delay={marksStart + step.marks.length * 4} fps={fps} /> |
| 886 | ) : null} |
| 887 | {step.reel ? <Reel reel={step.reel} prev={prev?.reel} local={local} /> : null} |
| 888 | </AbsoluteFill> |
| 889 | ); |
| 890 | }; |
| 891 | |
| 892 | const ErrorView = ({ |
| 893 | step, |
| 894 | g, |
| 895 | local, |
| 896 | delay, |
| 897 | minTop, |
| 898 | }: { |
| 899 | step: CodeStep; |
| 900 | g: ReturnType<typeof layout>; |
| 901 | local: number; |
| 902 | delay: number; |
| 903 | minTop: number; |
| 904 | }) => { |
| 905 | const error = step.error!; |
| 906 | const r = rect(step, g, error); |
| 907 | const p = drawProgress(local, delay, 8); |
| 908 | const box = interpolate(local, [delay + 4, delay + 10], [0, 1], { |
| 909 | extrapolateLeft: "clamp", |
| 910 | extrapolateRight: "clamp", |
| 911 | }); |
| 912 | // A squiggle along the error range. |
| 913 | const wave: string[] = []; |
| 914 | for (let x = 0; x <= r.w * p; x += 6) |
| 915 | wave.push(`${r.x + x},${r.y + r.h - 4 + (Math.floor(x / 6) % 2 ? 4 : 0)}`); |
| 916 | // Under the code, like an editor tooltip; or in the right column beside it. |
| 917 | // Under the code, bottom-right and sized to the message; or in the right column beside it. |
| 918 | const boxWidth = error.below |
| 919 | ? Math.min(900, 60 + Math.max(...error.message.map((l) => l.length)) * 12.6) |
| 920 | : PANEL_WIDTH; |
| 921 | const boxX = error.below ? AREA.x + AREA.width - boxWidth : AREA.x + AREA.width - PANEL_WIDTH; |
| 922 | const boxY = error.below |
| 923 | ? Math.min(g.top + step.lines.length * g.lh + 28, AREA.y + AREA.height - 100) |
| 924 | : Math.min(Math.max(minTop, r.y - 40), AREA.y + AREA.height - 320); |
| 925 | return ( |
| 926 | <> |
| 927 | <svg width={1920} height={1080} style={{ position: "absolute", left: 0, top: 0 }}> |
| 928 | {wave.length > 1 ? ( |
| 929 | <polyline points={wave.join(" ")} fill="none" stroke="#f14c4c" strokeWidth={2.5} /> |
| 930 | ) : null} |
| 931 | {box > 0 && !error.below ? ( |
| 932 | <path |
| 933 | d={`M ${r.x + r.w * 0.5} ${r.y + r.h + 2} C ${r.x + r.w * 0.5} ${r.y + r.h + 60}, ${boxX - 80} ${boxY + 30}, ${boxX - 8} ${boxY + 30}`} |
| 934 | fill="none" |
| 935 | stroke="#f14c4c" |
| 936 | strokeWidth={2} |
| 937 | strokeDasharray="6 6" |
| 938 | opacity={box} |
| 939 | /> |
| 940 | ) : null} |
| 941 | </svg> |
| 942 | <div |
| 943 | style={{ |
| 944 | position: "absolute", |
| 945 | left: boxX, |
| 946 | top: boxY, |
| 947 | width: boxWidth, |
| 948 | padding: "14px 18px", |
| 949 | background: "#252526", |
| 950 | border: "1px solid #454545", |
| 951 | borderRadius: 6, |
| 952 | boxShadow: "0 12px 32px rgba(0,0,0,0.5)", |
| 953 | fontFamily: mono, |
| 954 | fontSize: 21, |
| 955 | lineHeight: 1.5, |
| 956 | color: "#cccccc", |
| 957 | whiteSpace: "pre-wrap", |
| 958 | opacity: box, |
| 959 | transform: `translateY(${(1 - box) * 8}px)`, |
| 960 | }} |
| 961 | > |
| 962 | {error.message.map((line, i) => ( |
| 963 | <div |
| 964 | key={i} |
| 965 | style={{ |
| 966 | paddingLeft: i * 18, |
| 967 | color: i === error.message.length - 1 ? "#ffffff" : "#cccccc", |
| 968 | }} |
| 969 | > |
| 970 | {line} |
| 971 | </div> |
| 972 | ))} |
| 973 | <div style={{ marginTop: 6, color: "#9d9d9d", fontFamily: sans, fontSize: 15 }}> |
| 974 | {error.code} |
| 975 | </div> |
| 976 | </div> |
| 977 | </> |
| 978 | ); |
| 979 | }; |
| 980 | |
| 981 | const Panel = ({ |
| 982 | step, |
| 983 | local, |
| 984 | delay, |
| 985 | }: { |
| 986 | step: CodeStep; |
| 987 | local: number; |
| 988 | delay: number; |
| 989 | fps: number; |
| 990 | }) => { |
| 991 | const panel = step.panel!; |
| 992 | const x = AREA.x + AREA.width - PANEL_WIDTH; |
| 993 | const inAt = (i: number) => |
| 994 | interpolate(local, [delay + i * 3, delay + i * 3 + 7], [0, 1], { |
| 995 | extrapolateLeft: "clamp", |
| 996 | extrapolateRight: "clamp", |
| 997 | }); |
| 998 | return ( |
| 999 | <div |
| 1000 | style={{ |
| 1001 | position: "absolute", |
| 1002 | left: x, |
| 1003 | top: AREA.y, |
| 1004 | width: PANEL_WIDTH, |
| 1005 | height: AREA.height, |
| 1006 | display: "flex", |
| 1007 | flexDirection: "column", |
| 1008 | justifyContent: "center", |
| 1009 | gap: 22, |
| 1010 | fontFamily: sans, |
| 1011 | }} |
| 1012 | > |
| 1013 | <div |
| 1014 | style={{ |
| 1015 | fontFamily: hand, |
| 1016 | fontWeight: 700, |
| 1017 | fontSize: 40, |
| 1018 | color: TONE.construct, |
| 1019 | opacity: inAt(0), |
| 1020 | }} |
| 1021 | > |
| 1022 | {panel.title} |
| 1023 | </div> |
| 1024 | {panel.items.map((item, i) => { |
| 1025 | const color = TONE[item.tone ?? "neutral"]; |
| 1026 | const p = inAt(i + 1); |
| 1027 | return ( |
| 1028 | <div key={i} style={{ opacity: p, transform: `translateX(${(1 - p) * 20}px)` }}> |
| 1029 | <div style={{ color: item.tone ? color : brand.fg, fontSize: 24, fontWeight: 600 }}> |
| 1030 | {item.title} |
| 1031 | </div> |
| 1032 | {item.body ? ( |
| 1033 | <div style={{ color: brand.fgMuted, fontSize: 20, marginTop: 4 }}>{item.body}</div> |
| 1034 | ) : null} |
| 1035 | {item.mono ? ( |
| 1036 | <pre |
| 1037 | style={{ |
| 1038 | margin: "10px 0 0", |
| 1039 | padding: "14px 16px", |
| 1040 | background: vscode.editorBg, |
| 1041 | border: `1px solid ${item.tone ? color : "rgba(255,255,255,0.1)"}`, |
| 1042 | borderRadius: 10, |
| 1043 | fontFamily: mono, |
| 1044 | fontSize: 18, |
| 1045 | lineHeight: 1.45, |
| 1046 | color: "#d4d4d4", |
| 1047 | whiteSpace: "pre-wrap", |
| 1048 | }} |
| 1049 | > |
| 1050 | {item.mono} |
| 1051 | </pre> |
| 1052 | ) : null} |
| 1053 | {item.bar !== undefined ? ( |
| 1054 | <div |
| 1055 | style={{ |
| 1056 | marginTop: 10, |
| 1057 | height: 18, |
| 1058 | borderRadius: 9, |
| 1059 | background: "rgba(255,255,255,0.06)", |
| 1060 | }} |
| 1061 | > |
| 1062 | <div |
| 1063 | style={{ |
| 1064 | width: `${item.bar * 100 * p}%`, |
| 1065 | minWidth: 10, |
| 1066 | height: "100%", |
| 1067 | borderRadius: 9, |
| 1068 | background: color, |
| 1069 | }} |
| 1070 | /> |
| 1071 | </div> |
| 1072 | ) : null} |
| 1073 | </div> |
| 1074 | ); |
| 1075 | })} |
| 1076 | </div> |
| 1077 | ); |
| 1078 | }; |
| 1079 | |
| 1080 | /** Where a span of text sits on screen, for drawing between panes. */ |
| 1081 | export const spanRect = ( |
| 1082 | step: CodeStep, |
| 1083 | area: Area, |
| 1084 | span: { line: number; col: number; len: number }, |
| 1085 | ) => rect(step, layout(step, area), span); |
| 1086 | |
| 1087 | /** The pyramid's colours, for the kind of thing a step adds. */ |
| 1088 | const LAYER = { |
| 1089 | resource: { color: "#8b9cf6", label: "resource" }, |
| 1090 | binding: { color: "#e0a86b", label: "binding" }, |
| 1091 | api: { color: "#a3c473", label: "API" }, |
| 1092 | } as const; |
| 1093 | |
| 1094 | /** The option row under the code, at the same place as on roll slides. */ |
| 1095 | const Reel = ({ |
| 1096 | reel, |
| 1097 | prev, |
| 1098 | local, |
| 1099 | }: { |
| 1100 | reel: NonNullable<CodeStep["reel"]>; |
| 1101 | prev?: CodeStep["reel"]; |
| 1102 | local: number; |
| 1103 | }) => { |
| 1104 | const t = interpolate(local, [0, 12], [0, 1], { |
| 1105 | extrapolateLeft: "clamp", |
| 1106 | extrapolateRight: "clamp", |
| 1107 | }); |
| 1108 | return ( |
| 1109 | <div |
| 1110 | style={{ |
| 1111 | position: "absolute", |
| 1112 | left: 110, |
| 1113 | right: 110, |
| 1114 | top: 985, |
| 1115 | display: "flex", |
| 1116 | flexWrap: "wrap", |
| 1117 | rowGap: 14, |
| 1118 | columnGap: 44, |
| 1119 | fontFamily: sans, |
| 1120 | fontSize: 30, |
| 1121 | fontWeight: 600, |
| 1122 | }} |
| 1123 | > |
| 1124 | {reel.items.map((item, i) => { |
| 1125 | const was = prev ? (prev.at === i ? 1 : 0) : reel.at === i ? 1 : 0; |
| 1126 | const on = was + ((reel.at === i ? 1 : 0) - was) * t; |
| 1127 | return ( |
| 1128 | <div |
| 1129 | key={item} |
| 1130 | style={{ |
| 1131 | color: on > 0.5 ? brand.fg : brand.fgMuted, |
| 1132 | opacity: 0.45 + 0.55 * on, |
| 1133 | paddingBottom: 8, |
| 1134 | borderBottom: `3px solid rgba(126, 231, 135, ${on})`, |
| 1135 | }} |
| 1136 | > |
| 1137 | {item} |
| 1138 | </div> |
| 1139 | ); |
| 1140 | })} |
| 1141 | </div> |
| 1142 | ); |
| 1143 | }; |