The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { ReactNode } from "react"; |
| 2 | import { |
| 3 | AbsoluteFill, |
| 4 | interpolate, |
| 5 | staticFile, |
| 6 | useCurrentFrame, |
| 7 | useVideoConfig, |
| 8 | type CalculateMetadataFunction, |
| 9 | } from "remotion"; |
| 10 | import { CAPTION_BAND, VIDEO, type AppId, type SceneCapture } from "../../shared/types.ts"; |
| 11 | import { sans } from "../fonts.ts"; |
| 12 | import { Browser } from "./Browser.tsx"; |
| 13 | import { MenuBar, Wallpaper } from "./Desktop.tsx"; |
| 14 | import { Diagram } from "./Diagram.tsx"; |
| 15 | import { Editor } from "./Editor.tsx"; |
| 16 | import { schedule, segmentAt, TIMING, type SceneSchedule } from "./schedule.ts"; |
| 17 | import { Terminal } from "./Terminal.tsx"; |
| 18 | |
| 19 | export interface SceneProps extends Record<string, unknown> { |
| 20 | id: string; |
| 21 | capture?: SceneCapture; |
| 22 | plan?: SceneSchedule; |
| 23 | } |
| 24 | |
| 25 | /** Loads `out/capture/<id>/scene.json` and lays its beats out on frames. */ |
| 26 | export const calculateSceneMetadata: CalculateMetadataFunction<SceneProps> = async ({ props }) => { |
| 27 | const response = await fetch(staticFile(`${props.id}/scene.json`)); |
| 28 | if (!response.ok) { |
| 29 | throw new Error(`No capture for scene "${props.id}". Run \`pnpm capture\` first.`); |
| 30 | } |
| 31 | const capture = (await response.json()) as SceneCapture; |
| 32 | const { fps } = VIDEO; |
| 33 | const plan = await schedule(capture, fps); |
| 34 | return { durationInFrames: plan.durationInFrames, fps, props: { ...props, capture, plan } }; |
| 35 | }; |
| 36 | |
| 37 | /** The caption in effect at `frame`, and how many frames it has been up. */ |
| 38 | const captionAt = (plan: SceneSchedule, frame: number) => { |
| 39 | let caption: { text: string; since: number } | undefined; |
| 40 | for (const segment of plan.segments) { |
| 41 | if (segment.from > frame) break; |
| 42 | const { beat } = segment; |
| 43 | // Every step's title is its caption; an explicit caption beat overrides it. |
| 44 | if (beat.kind === "step" || beat.kind === "caption") { |
| 45 | const text = beat.kind === "step" ? beat.title : beat.text; |
| 46 | if (caption?.text !== text) caption = { text, since: frame - segment.from }; |
| 47 | } |
| 48 | } |
| 49 | return caption; |
| 50 | }; |
| 51 | |
| 52 | export const Caption = ({ text, since }: { text: string; since: number }) => { |
| 53 | const t = interpolate(since, [0, 5], [0, 1], { |
| 54 | extrapolateLeft: "clamp", |
| 55 | extrapolateRight: "clamp", |
| 56 | }); |
| 57 | return ( |
| 58 | <div |
| 59 | style={{ |
| 60 | position: "absolute", |
| 61 | left: 0, |
| 62 | right: 0, |
| 63 | top: CAPTION_BAND.top, |
| 64 | height: CAPTION_BAND.height, |
| 65 | display: "flex", |
| 66 | alignItems: "center", |
| 67 | justifyContent: "center", |
| 68 | opacity: t, |
| 69 | transform: `translateY(${(1 - t) * 12}px)`, |
| 70 | }} |
| 71 | > |
| 72 | <div |
| 73 | style={{ |
| 74 | maxWidth: 1500, |
| 75 | textAlign: "center", |
| 76 | fontFamily: sans, |
| 77 | fontSize: 38, |
| 78 | fontWeight: 600, |
| 79 | lineHeight: 1.25, |
| 80 | color: "#ffffff", |
| 81 | letterSpacing: -0.2, |
| 82 | // Subtitle style: plain text, legible over any window. |
| 83 | textShadow: |
| 84 | "0 0 2px rgba(0,0,0,0.95), 0 2px 4px rgba(0,0,0,0.9), 0 0 18px rgba(0,0,0,0.75)", |
| 85 | WebkitTextStroke: "0.5px rgba(0,0,0,0.6)", |
| 86 | }} |
| 87 | > |
| 88 | {text} |
| 89 | </div> |
| 90 | </div> |
| 91 | ); |
| 92 | }; |
| 93 | |
| 94 | export const Scene = ({ capture, plan }: SceneProps) => { |
| 95 | const frame = useCurrentFrame(); |
| 96 | const { fps } = useVideoConfig(); |
| 97 | if (!capture || !plan) return null; |
| 98 | |
| 99 | const segment = segmentAt(plan.segments, frame); |
| 100 | const focused = (segment?.app === "slide" || !segment ? "editor" : segment.app) as Exclude< |
| 101 | AppId, |
| 102 | "slide" |
| 103 | >; |
| 104 | const windows: Record<Exclude<AppId, "slide">, ReactNode> = { |
| 105 | editor: <Editor capture={capture} plan={plan} frame={frame} />, |
| 106 | terminal: <Terminal capture={capture} plan={plan} frame={frame} fps={fps} />, |
| 107 | diagram: <Diagram capture={capture} plan={plan} frame={frame} />, |
| 108 | browser: <Browser capture={capture} plan={plan} frame={frame} />, |
| 109 | }; |
| 110 | |
| 111 | return ( |
| 112 | <AbsoluteFill> |
| 113 | <Wallpaper /> |
| 114 | <MenuBar app={focused} /> |
| 115 | <AbsoluteFill>{windows[focused]}</AbsoluteFill> |
| 116 | |
| 117 | {(() => { |
| 118 | const caption = captionAt(plan, frame); |
| 119 | return caption ? <Caption key={caption.text} {...caption} /> : null; |
| 120 | })()} |
| 121 | </AbsoluteFill> |
| 122 | ); |
| 123 | }; |