{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"terminal-simulator","type":"registry:component","title":"Terminal Simulator","description":"Terminal animation: CLI demo that types commands and prints output. Terminal window with chunked command playback, freeze-frame pauses, step scrolling, and an optional cursor-pinned zoom camera.","dependencies":["remotion"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>. Pass mode=\"dark\" for dark frames.","registryDependencies":["https://kuchi.kalarislabs.com/r/kuchi-ui.json"],"files":[{"path":"components/kuchi/terminal-simulator.tsx","type":"registry:component","target":"components/kuchi/terminal-simulator.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport {\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  interpolate,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  Item,\r\n  mixOklch,\r\n  parseColor,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n  withAlpha,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\nexport type TerminalLineType = \"command\" | \"log\" | \"success\" | \"error\";\r\n\r\n/** Package-manager command panel — the flythrough's second station. */\r\nexport interface CommandSpec {\r\n  /** Tab labels. The first is the active tab. */\r\n  managers?: string[];\r\n  /** The command typed into the active tab, e.g. \"npm install One Tool\". */\r\n  text: string;\r\n}\r\n\r\nexport interface TerminalLine {\r\n  text: string;\r\n  type: TerminalLineType;\r\n  /** Frame gap before this line starts typing. Defaults to 8. */\r\n  delay?: number;\r\n  /**\r\n   * Extra freeze-frame pause AFTER this line finishes typing, in frames.\r\n   * Use this to build tension before the next batch of logs. If omitted,\r\n   * lines whose text ends in \"...\" auto-freeze for 18 frames.\r\n   */\r\n  pause?: number;\r\n}\r\n\r\nexport interface TerminalZoom {\r\n  /** Turn the extra landing zoom on. */\r\n  enabled: boolean;\r\n  /** Camera zoom the final punch-in lands at. Defaults to 2.4. */\r\n  scale?: number;\r\n  /** Kept for API compatibility; the flythrough camera always leads the eye. */\r\n  followCursor?: boolean;\r\n}\r\n\r\nexport interface TerminalSimulatorProps {\r\n  lines?: TerminalLine[];\r\n  /**\r\n   * Headline at the first camera station. Wrap words in `*asterisks*` to tint\r\n   * them with the accent gradient. `null`/\"\" skips the station — the camera\r\n   * starts on the command panel instead.\r\n   */\r\n  intro?: string | null;\r\n  /**\r\n   * Command panel at the second camera station. `null` skips the station.\r\n   */\r\n  command?: CommandSpec | null;\r\n  /** Command-panel surface color. */\r\n  /** Overrides the design system's `card`. */\r\n  background?: string;\r\n  /** Hairline border color for the command-panel ring and divider. */\r\n  /** Overrides the design system's `border`. */\r\n  borderColor?: string;\r\n  /** Design-system token overrides. */\r\n  theme?: Partial<KuchiTheme>;\r\n  /** Defaults to `\"dark\"` — a terminal is lit for dark. */\r\n  mode?: \"light\" | \"dark\";\r\n  /**\r\n   * The face this scene paints its words in — a label from `fonts.ts`\r\n   * (\"Inter\", \"Space Grotesk\", \"Instrument Serif\") or a CSS family you have\r\n   * loaded yourself. Unset, the scene keeps the face it was designed around.\r\n   *\r\n   * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole\r\n   * timeline from one value.\r\n   */\r\n  fontFamily?: string;\r\n  fontSize?: number;\r\n  /**\r\n   * Reveal speed. The reveal is CHUNKED — every `1 / charsPerFrame` frames\r\n   * bumps the cursor by `chunkSize` characters, so output appears in bursts\r\n   * instead of dripping char-by-char.\r\n   */\r\n  charsPerFrame?: number;\r\n  /** Characters revealed per step. */\r\n  chunkSize?: number;\r\n  /**\r\n   * Landing zoom of the final punch onto the terminal. Pass `true` for the\r\n   * 2.4x default or an object for a custom scale. Off = 1.5x.\r\n   */\r\n  zoom?: boolean | TerminalZoom;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\n// ─── Stage & camera constants ────────────────────────────────────────────────\r\n// The scene is ONE world the camera flies over. Nothing enters from a screen\r\n// edge — the camera pans/zooms between three fixed stations on a single black\r\n// canvas, exactly like a camera-type-flythrough.\r\n\r\n// The stage, the panel and the tab row are app chrome and come from the design\r\n// system. The syntax palette below is the terminal's own colour scheme — the\r\n// look, not chrome — and stays literal, exposed through props.\r\n\r\n/** Station anchors in world px (world is sized for a 1280x720 viewport). */\r\nconst INTRO_POS = { x: 640, y: 360 };\r\nconst CMD_POS = { x: 2140, y: 520 };\r\nconst TERM_POS = { x: 2140, y: 1660 };\r\n\r\n/** Camera timeline (frames at speed 1). */\r\nconst DRIFT_START = 22; // intro starts creeping left\r\nconst WHIP_START = 40; // sudden acceleration toward the command panel\r\nconst CMD_ARRIVE = 70; // camera lands on the command panel\r\nconst CMD_TYPE_START = 74; // \"npm install One Tool\" starts typing\r\nconst PUSH_END = 112; // slow push-in while typing (leaves the ghost trail)\r\nconst PULL_END = 138; // zoom-out + descend toward the terminal\r\nconst PUNCH_END = 158; // sudden punch-in lands on the terminal\r\nconst TERM_TYPE_START = 146; // terminal lines start typing as we land\r\n\r\n/** Command-panel geometry in world px. */\r\nconst CMD_W = 760;\r\nconst CMD_H = 170;\r\n\r\n/** Terminal station geometry in world px (sized against the reference). */\r\nconst TERM_BAR_OFFSET = 137; // bar sits this far left of the focus point\r\nconst TERM_TEXT_OFFSET = 90; // text column left edge relative to focus\r\nconst TERM_BLOCK_TOP = 215; // first line sits this far above the focus point\r\nconst TERM_LINE_H = 83;\r\nconst TERM_FONT = 44;\r\n\r\n/** Lead-in used for the terminal lines' start schedule. */\r\nconst LEAD_IN_FRAMES = 10;\r\n\r\n// ─── Palette (matched against the reference stills) ─────────────────────────\r\n\r\n/** Accent gradient for `*emphasized*` intro words. */\r\nconst ACCENT_GRADIENT = \"linear-gradient(90deg, #7C96FF 0%, #A78BFA 100%)\";\r\n\r\n/** Command-row syntax palette: dim manager/subcommand, highlighted args. */\r\nconst CMD_MANAGER_COLOR = \"#A0673F\";\r\nconst CMD_SUBCOMMAND_COLOR = \"#64789B\";\r\nconst CMD_ARG_COLOR = \"#D7E4F8\";\r\n\r\n/** Focus-terminal palette. */\r\nconst TERM_ACCENT = \"#2EA043\";\r\nconst TERM_CURSOR = \"#1D5B36\";\r\nconst TERM_COLORS: Record<TerminalLineType, string> = {\r\n  command: \"#F2F5F3\",\r\n  log: \"#6E7873\",\r\n  success: \"#1F8039\",\r\n  error: \"#F04438\",\r\n};\r\n\r\n/**\r\n * On a light page the two colours drawn for a dark one — near-white args and\r\n * commands — would vanish, so they take ink instead; the rest read on either.\r\n */\r\nconst LIGHT_ARG_COLOR = \"#1B2533\";\r\nconst LIGHT_TERM_COLORS: Record<TerminalLineType, string> = {\r\n  ...TERM_COLORS,\r\n  command: \"#141414\",\r\n};\r\n\r\n/** Functional color map kept for the public helper API. */\r\nconst TYPE_COLORS: Record<TerminalLineType, string> = TERM_COLORS;\r\n\r\nconst SANS_FAMILY =\r\n  '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Inter, sans-serif';\r\nconst MONO_FAMILY = \"ui-monospace, SFMono-Regular, Menlo, monospace\";\r\n\r\nconst DEFAULT_INTRO = \"*work* one step at a *time.*\";\r\n\r\nconst DEFAULT_COMMAND: CommandSpec = {\r\n  managers: [\"npm\", \"pnpm\", \"yarn\", \"bun\"],\r\n  text: \"npm install One Tool\",\r\n};\r\n\r\nconst DEFAULT_LINES: TerminalLine[] = [\r\n  { text: \"{labels: ['bug']})\", type: \"log\", delay: 0 },\r\n  { text: \"→   label added\", type: \"success\", delay: 6 },\r\n  { text: \"$\", type: \"log\", delay: 10 },\r\n  { text: \"One task\", type: \"command\", delay: 4 },\r\n];\r\n\r\n// ─── Pure helpers ────────────────────────────────────────────────────────────\r\n\r\n/** Auto freeze-frame heuristic: any line ending in \"...\" holds the camera. */\r\nexport function autoPause(line: TerminalLine): number {\r\n  if (line.pause !== undefined) return line.pause;\r\n  // `replace`, not `trimEnd` (ES2019): stock Remotion types ES2015.\r\n  if (line.text.replace(/\\s+$/, \"\").endsWith(\"...\")) return 18;\r\n  return 0;\r\n}\r\n\r\n/** Frames the chunked reveal needs to type `textLength` characters. */\r\nexport function typingDuration(\r\n  textLength: number,\r\n  charsPerFrame: number,\r\n  chunkSize: number,\r\n): number {\r\n  return Math.ceil(textLength / (chunkSize * charsPerFrame));\r\n}\r\n\r\n/**\r\n * Cumulative start frame for each line, including per-line delays and the\r\n * auto/explicit freeze pauses AFTER a line finishes typing.\r\n */\r\nexport function computeLineStarts(\r\n  lines: TerminalLine[],\r\n  charsPerFrame: number,\r\n  chunkSize: number,\r\n  leadIn: number = LEAD_IN_FRAMES,\r\n): number[] {\r\n  const starts: number[] = [];\r\n  let acc = leadIn;\r\n  for (const line of lines) {\r\n    acc += line.delay ?? 8;\r\n    starts.push(acc);\r\n    acc +=\r\n      typingDuration(line.text.length, charsPerFrame, chunkSize) +\r\n      autoPause(line);\r\n  }\r\n  return starts;\r\n}\r\n\r\n/**\r\n * Chunked reveal: Math.floor of an interpolated count, snapped up to the\r\n * nearest multiple of `chunkSize`. This is what gives the bursty terminal\r\n * feel — text doesn't drip, it lurches.\r\n */\r\nexport function chunkedReveal(\r\n  localFrame: number,\r\n  totalChars: number,\r\n  charsPerFrame: number,\r\n  chunkSize: number,\r\n): number {\r\n  if (totalChars <= 0) return 0;\r\n  const linear = Math.floor(\r\n    interpolate(localFrame, [0, totalChars / charsPerFrame], [0, totalChars], {\r\n      extrapolateLeft: \"clamp\",\r\n      extrapolateRight: \"clamp\",\r\n    }),\r\n  );\r\n  return Math.min(totalChars, Math.ceil(linear / chunkSize) * chunkSize);\r\n}\r\n\r\n/**\r\n * STEP-FUNCTION scroll. Each overflowing line snaps the buffer up by exactly\r\n * one row on the frame it begins. No interpolation, no easing — terminals do\r\n * not glide. Returns the number of rows scrolled off the top.\r\n */\r\nexport function computeScrollRows(\r\n  frame: number,\r\n  starts: number[],\r\n  visibleLines: number,\r\n): number {\r\n  let rows = 0;\r\n  for (let i = visibleLines; i < starts.length; i++) {\r\n    if (frame >= starts[i]) rows++;\r\n  }\r\n  return rows;\r\n}\r\n\r\n/** Normalize the `zoom` prop into a fully-resolved camera config. */\r\nexport function resolveZoom(\r\n  zoom: boolean | TerminalZoom | undefined,\r\n): Required<TerminalZoom> {\r\n  if (zoom === undefined || zoom === false) {\r\n    return { enabled: false, scale: 1, followCursor: true };\r\n  }\r\n  if (zoom === true) {\r\n    return { enabled: true, scale: 2.4, followCursor: true };\r\n  }\r\n  return {\r\n    enabled: zoom.enabled,\r\n    scale: zoom.scale ?? 2.4,\r\n    followCursor: zoom.followCursor ?? true,\r\n  };\r\n}\r\n\r\n/** Split `*emphasis*` runs out of the intro string, preserving spaces. */\r\nexport function parseIntro(\r\n  text: string,\r\n): Array<{ text: string; accent: boolean }> {\r\n  const out: Array<{ text: string; accent: boolean }> = [];\r\n  const re = /\\*([^*]+)\\*/g;\r\n  let last = 0;\r\n  let m: RegExpExecArray | null = re.exec(text);\r\n  while (m !== null) {\r\n    if (m.index > last)\r\n      out.push({ text: text.slice(last, m.index), accent: false });\r\n    out.push({ text: m[1], accent: true });\r\n    last = m.index + m[0].length;\r\n    m = re.exec(text);\r\n  }\r\n  if (last < text.length) out.push({ text: text.slice(last), accent: false });\r\n  return out;\r\n}\r\n\r\n/** Colour a shell command: word 0 = manager, word 1 = subcommand, rest = args. */\r\nexport function commandSpans(\r\n  text: string,\r\n  argColor: string = CMD_ARG_COLOR,\r\n): Array<{ text: string; color: string }> {\r\n  const out: Array<{ text: string; color: string }> = [];\r\n  let wordIndex = -1;\r\n  for (const part of text.split(/(\\s+)/)) {\r\n    if (part.length === 0) continue;\r\n    if (/^\\s+$/.test(part)) {\r\n      out.push({ text: part, color: argColor });\r\n      continue;\r\n    }\r\n    wordIndex++;\r\n    const color =\r\n      wordIndex === 0\r\n        ? CMD_MANAGER_COLOR\r\n        : wordIndex === 1\r\n          ? CMD_SUBCOMMAND_COLOR\r\n          : argColor;\r\n    out.push({ text: part, color });\r\n  }\r\n  return out;\r\n}\r\n\r\n// ─── Camera ──────────────────────────────────────────────────────────────────\r\n\r\nexport interface CameraStop {\r\n  /** Frame this stop is reached. */\r\n  frame: number;\r\n  /** World focus point (px) the camera centers on. */\r\n  x: number;\r\n  y: number;\r\n  /** Zoom at this stop. */\r\n  z: number;\r\n  /** Easing applied while travelling INTO this stop from the previous one. */\r\n  easing?: (t: number) => number;\r\n}\r\n\r\nexport interface CameraState {\r\n  x: number;\r\n  y: number;\r\n  z: number;\r\n}\r\n\r\n/**\r\n * Piecewise camera resolver. Between consecutive stops the camera lerps\r\n * x/y/z with the segment's own easing — so a lazy drift can hand off to a\r\n * sudden ease-in whip, which is the whole feel of the flythrough. Clamps to\r\n * the first/last stop outside the timeline.\r\n */\r\nexport function cameraAt(frame: number, stops: CameraStop[]): CameraState {\r\n  const first = stops[0];\r\n  const last = stops[stops.length - 1];\r\n  if (frame <= first.frame) return { x: first.x, y: first.y, z: first.z };\r\n  if (frame >= last.frame) return { x: last.x, y: last.y, z: last.z };\r\n  for (let i = 0; i < stops.length - 1; i++) {\r\n    const a = stops[i];\r\n    const b = stops[i + 1];\r\n    if (frame >= a.frame && frame < b.frame) {\r\n      const t = (frame - a.frame) / (b.frame - a.frame);\r\n      const e = b.easing ? b.easing(t) : t;\r\n      return {\r\n        x: a.x + (b.x - a.x) * e,\r\n        y: a.y + (b.y - a.y) * e,\r\n        z: a.z + (b.z - a.z) * e,\r\n      };\r\n    }\r\n  }\r\n  return { x: last.x, y: last.y, z: last.z };\r\n}\r\n\r\n/**\r\n * The flythrough's shot list: hold on the intro → creep left → sudden\r\n * ease-in whip to the command panel → slow push while it types (this is\r\n * what draws the ghost trail) → zoom-out descending → sudden punch-in\r\n * landing on the terminal. When a station is skipped its segment collapses.\r\n */\r\nexport function buildCameraStops(\r\n  hasIntro: boolean,\r\n  hasCommand: boolean,\r\n  landingZoom: number,\r\n): CameraStop[] {\r\n  const whip = Easing.bezier(0.7, 0, 0.25, 1);\r\n  const punch = Easing.bezier(0.75, 0, 0.3, 1);\r\n  const glide = Easing.bezier(0.35, 0, 0.55, 1);\r\n\r\n  const stops: CameraStop[] = [];\r\n  if (hasIntro) {\r\n    stops.push(\r\n      { frame: 0, x: INTRO_POS.x, y: INTRO_POS.y, z: 1 },\r\n      { frame: DRIFT_START, x: INTRO_POS.x, y: INTRO_POS.y, z: 1 },\r\n      // The slight leftward text drift = camera creeping right, accelerating.\r\n      {\r\n        frame: WHIP_START,\r\n        x: INTRO_POS.x + 52,\r\n        y: INTRO_POS.y,\r\n        z: 1.02,\r\n        easing: Easing.in(Easing.quad),\r\n      },\r\n    );\r\n  }\r\n  if (hasCommand) {\r\n    stops.push(\r\n      {\r\n        frame: hasIntro ? CMD_ARRIVE : 0,\r\n        x: CMD_POS.x,\r\n        y: CMD_POS.y,\r\n        z: 1.55,\r\n        easing: whip,\r\n      },\r\n      // Slow push-in while the command types — leaves the trailing copies.\r\n      {\r\n        frame: PUSH_END,\r\n        x: CMD_POS.x,\r\n        y: CMD_POS.y + 28,\r\n        z: 1.9,\r\n        easing: Easing.inOut(Easing.quad),\r\n      },\r\n      // Zoom out and start descending toward the terminal.\r\n      {\r\n        frame: PULL_END,\r\n        x: CMD_POS.x,\r\n        y: CMD_POS.y + 630,\r\n        z: 0.95,\r\n        easing: glide,\r\n      },\r\n    );\r\n  }\r\n  stops.push({\r\n    frame: hasCommand ? PUNCH_END : hasIntro ? CMD_ARRIVE : 0,\r\n    x: TERM_POS.x,\r\n    y: TERM_POS.y,\r\n    z: landingZoom,\r\n    easing: punch,\r\n  });\r\n  return stops;\r\n}\r\n\r\n/** Screen-space speed of the focus point — drives the motion-blur trail. */\r\nexport function cameraSpeed(frame: number, stops: CameraStop[]): number {\r\n  const a = cameraAt(frame - 1, stops);\r\n  const b = cameraAt(frame, stops);\r\n  const pan = Math.hypot(b.x - a.x, b.y - a.y) * b.z;\r\n  const zoomEdge = Math.abs(b.z - a.z) * 360;\r\n  return pan + zoomEdge;\r\n}\r\n\r\n// ─── Component ───────────────────────────────────────────────────────────────\r\n\r\n/** Ghost samples for the motion-blur trail: frames back, opacity, blur px. */\r\nconst GHOSTS = [\r\n  { back: 2, alpha: 0.3, blur: 3 },\r\n  { back: 4, alpha: 0.18, blur: 6 },\r\n  { back: 6, alpha: 0.1, blur: 10 },\r\n];\r\n\r\nexport function TerminalSimulator({\r\n  lines = DEFAULT_LINES,\r\n  intro = DEFAULT_INTRO,\r\n  command = DEFAULT_COMMAND,\r\n  background,\r\n  borderColor,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  fontSize = 18,\r\n  charsPerFrame = 2,\r\n  chunkSize = 3,\r\n  zoom = false,\r\n  speed = 1,\r\n  className,\r\n}: TerminalSimulatorProps) {\r\n  const frame = useCurrentFrame() * speed;\r\n  const { fps, width, height } = useVideoConfig();\r\n  const { isRendering } = getRemotionEnvironment();\r\n  const t = useKuchiTheme(theme, mode ?? \"dark\");\r\n  const light = (mode ?? \"dark\") === \"light\";\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS_FAMILY;\r\n  const panel = background ?? t.card;\r\n  const hairline = borderColor ?? t.border;\r\n  // One constant stage across the whole flythrough — the page, a shade under\r\n  // the panel that floats on it.\r\n  // A transparent page asks for no page, so the stage under the panel goes too.\r\n  const stage =\r\n    parseColor(t.background).alpha === 0\r\n      ? \"transparent\"\r\n      : mixOklch(t.background, \"#000\", 0.35);\r\n\r\n  const hasIntro = intro != null && intro.trim().length > 0;\r\n  const hasCommand = command != null && command.text.trim().length > 0;\r\n  const camera = resolveZoom(zoom);\r\n  const landingZoom = camera.enabled ? camera.scale : 1.5;\r\n\r\n  const stops = buildCameraStops(hasIntro, hasCommand, landingZoom);\r\n  const cam = cameraAt(frame, stops);\r\n  const speedPx = cameraSpeed(frame, stops);\r\n  // Trail strength ramps in from barely-moving; saturates on the whip.\r\n  const trail = Math.min(1, Math.max(0, (speedPx - 2) / 30));\r\n\r\n  const worldTransform = (c: CameraState) =>\r\n    `translate(${width / 2 - c.x * c.z}px, ${height / 2 - c.y * c.z}px) scale(${c.z})`;\r\n\r\n  // The world is drawn once per ghost and once under the camera; only the\r\n  // camera's copy hands its lines to Studio, so each line has one outline.\r\n  const world = (primary: boolean) => (\r\n    <WorldContent\r\n      face={face}\r\n      frame={frame}\r\n      fps={fps}\r\n      intro={hasIntro ? intro : null}\r\n      command={hasCommand ? command : null}\r\n      lines={lines}\r\n      background={panel}\r\n      borderColor={hairline}\r\n      ink={t.foreground}\r\n      inkMuted={t.mutedForeground}\r\n      light={light}\r\n      fontSize={fontSize}\r\n      charsPerFrame={charsPerFrame}\r\n      chunkSize={chunkSize}\r\n      hasIntro={hasIntro}\r\n      primary={primary}\r\n    />\r\n  );\r\n\r\n  return (\r\n    <div\r\n      className={className}\r\n      style={{\r\n        position: \"absolute\",\r\n        inset: 0,\r\n        overflow: \"hidden\",\r\n        background: stage,\r\n        textRendering: \"geometricPrecision\",\r\n      }}\r\n    >\r\n      {/* Motion-blur trail: the same world drawn at recent camera positions.\r\n          Only alive while the camera actually moves — it IS the drop of the\r\n          fast moves, no element ever slides in from a screen edge. */}\r\n      {trail > 0.01 &&\r\n        GHOSTS.map((g) => (\r\n          <div\r\n            key={g.back}\r\n            style={{\r\n              position: \"absolute\",\r\n              left: 0,\r\n              top: 0,\r\n              transformOrigin: \"0 0\",\r\n              transform: worldTransform(cameraAt(frame - g.back, stops)),\r\n              opacity: g.alpha * trail,\r\n              filter: `blur(${g.blur * trail}px)`,\r\n              pointerEvents: \"none\",\r\n            }}\r\n          >\r\n            {world(false)}\r\n          </div>\r\n        ))}\r\n\r\n      {/* The camera */}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: 0,\r\n          top: 0,\r\n          transformOrigin: \"0 0\",\r\n          transform: worldTransform(cam),\r\n          ...(isRendering ? {} : { willChange: \"transform\" }),\r\n        }}\r\n      >\r\n        {world(true)}\r\n      </div>\r\n    </div>\r\n  );\r\n}\r\n\r\n// ─── World (all three stations on one canvas) ────────────────────────────────\r\n\r\nfunction WorldContent({\r\n  frame,\r\n  fps,\r\n  intro,\r\n  command,\r\n  lines,\r\n  background,\r\n  borderColor,\r\n  ink,\r\n  inkMuted,\r\n  light,\r\n  fontSize,\r\n  charsPerFrame,\r\n  chunkSize,\r\n  hasIntro,\r\n  face,\r\n  primary,\r\n}: {\r\n  frame: number;\r\n  fps: number;\r\n  intro: string | null;\r\n  command: CommandSpec | null;\r\n  lines: TerminalLine[];\r\n  background: string;\r\n  borderColor: string;\r\n  ink: string;\r\n  inkMuted: string;\r\n  light: boolean;\r\n  fontSize: number;\r\n  charsPerFrame: number;\r\n  chunkSize: number;\r\n  hasIntro: boolean;\r\n  face: string;\r\n  primary: boolean;\r\n}) {\r\n  const s = fontSize / 18; // font scale, layout stays fixed\r\n\r\n  return (\r\n    <div style={{ position: \"absolute\", left: 0, top: 0 }}>\r\n      {intro !== null && (\r\n        <IntroStation\r\n          frame={frame}\r\n          text={intro}\r\n          fontScale={s}\r\n          ink={ink}\r\n          face={face}\r\n        />\r\n      )}\r\n      {command !== null && (\r\n        <CommandStation\r\n          frame={frame}\r\n          command={command}\r\n          background={background}\r\n          borderColor={borderColor}\r\n          ink={ink}\r\n          inkMuted={inkMuted}\r\n          light={light}\r\n          fontScale={s}\r\n          charsPerFrame={charsPerFrame}\r\n          chunkSize={chunkSize}\r\n          fps={fps}\r\n          typeStart={hasIntro ? CMD_TYPE_START : 8}\r\n        />\r\n      )}\r\n      <TerminalStation\r\n        frame={frame}\r\n        light={light}\r\n        lines={lines}\r\n        fontScale={s}\r\n        charsPerFrame={charsPerFrame}\r\n        chunkSize={chunkSize}\r\n        fps={fps}\r\n        primary={primary}\r\n        typeStart={\r\n          command !== null ? TERM_TYPE_START : hasIntro ? CMD_ARRIVE - 6 : 6\r\n        }\r\n      />\r\n    </div>\r\n  );\r\n}\r\n\r\n/** Station 1 — the headline, words fading in staggered. */\r\nfunction IntroStation({\r\n  frame,\r\n  text,\r\n  fontScale,\r\n  ink,\r\n  face,\r\n}: {\r\n  frame: number;\r\n  text: string;\r\n  fontScale: number;\r\n  ink: string;\r\n  face: string;\r\n}) {\r\n  const tokens = parseIntro(text);\r\n  return (\r\n    <div\r\n      style={{\r\n        position: \"absolute\",\r\n        left: INTRO_POS.x,\r\n        top: INTRO_POS.y,\r\n        transform: \"translate(-50%, -50%)\",\r\n        whiteSpace: \"pre\",\r\n        fontFamily: face,\r\n        fontSize: Math.round(58 * fontScale),\r\n        fontWeight: 600,\r\n        letterSpacing: \"-0.01em\",\r\n      }}\r\n    >\r\n      {tokens.map((tok, i) => {\r\n        const t = interpolate(frame, [2 + i * 4, 14 + i * 4], [0, 1], {\r\n          extrapolateLeft: \"clamp\",\r\n          extrapolateRight: \"clamp\",\r\n          easing: Easing.out(Easing.cubic),\r\n        });\r\n        const style = tok.accent\r\n          ? {\r\n              backgroundImage: ACCENT_GRADIENT,\r\n              WebkitBackgroundClip: \"text\" as const,\r\n              backgroundClip: \"text\" as const,\r\n              color: \"transparent\",\r\n            }\r\n          : { color: ink };\r\n        return (\r\n          <span\r\n            // biome-ignore lint/suspicious/noArrayIndexKey: positional tokens\r\n            key={i}\r\n            style={{ ...style, opacity: t, filter: `blur(${(1 - t) * 3}px)` }}\r\n          >\r\n            {tok.text}\r\n          </span>\r\n        );\r\n      })}\r\n    </div>\r\n  );\r\n}\r\n\r\n/** Station 2 — the package-manager panel with the highlighted install command. */\r\nfunction CommandStation({\r\n  frame,\r\n  command,\r\n  background,\r\n  borderColor,\r\n  ink,\r\n  inkMuted,\r\n  light,\r\n  fontScale,\r\n  charsPerFrame,\r\n  chunkSize,\r\n  fps,\r\n  typeStart,\r\n}: {\r\n  frame: number;\r\n  command: CommandSpec;\r\n  background: string;\r\n  borderColor: string;\r\n  ink: string;\r\n  inkMuted: string;\r\n  light: boolean;\r\n  fontScale: number;\r\n  charsPerFrame: number;\r\n  chunkSize: number;\r\n  fps: number;\r\n  typeStart: number;\r\n}) {\r\n  const argColor = light ? LIGHT_ARG_COLOR : CMD_ARG_COLOR;\r\n  const managers = command.managers?.length ? command.managers : [\"npm\"];\r\n  const revealed = chunkedReveal(\r\n    Math.max(0, frame - typeStart),\r\n    command.text.length,\r\n    charsPerFrame,\r\n    chunkSize,\r\n  );\r\n  const typingDone = revealed >= command.text.length;\r\n  const blink = Math.floor((frame / fps) * 2) % 2 === 0;\r\n  const spans = commandSpans(command.text, argColor);\r\n\r\n  const tabFont = Math.round(20 * fontScale);\r\n  const rowFont = Math.round(33 * fontScale);\r\n\r\n  return (\r\n    <div\r\n      style={{\r\n        position: \"absolute\",\r\n        left: CMD_POS.x - CMD_W / 2,\r\n        top: CMD_POS.y - CMD_H / 2,\r\n        width: CMD_W,\r\n        height: CMD_H,\r\n        background,\r\n        borderRadius: 14,\r\n        overflow: \"hidden\",\r\n        boxShadow: `0 0 0 1px ${borderColor}, 0 30px 60px ${withAlpha(\r\n          mixOklch(background, \"#000\", 0.8),\r\n          0.55,\r\n        )}`,\r\n        fontFamily: MONO_FAMILY,\r\n      }}\r\n    >\r\n      {/* Tab row */}\r\n      <div\r\n        style={{\r\n          height: 54,\r\n          display: \"flex\",\r\n          alignItems: \"center\",\r\n          gap: 6,\r\n          padding: \"0 16px\",\r\n          borderBottom: `1px solid ${borderColor}`,\r\n        }}\r\n      >\r\n        {managers.map((m, i) => (\r\n          <div\r\n            key={m}\r\n            style={{\r\n              fontSize: tabFont,\r\n              fontWeight: i === 0 ? 600 : 500,\r\n              padding: \"7px 14px\",\r\n              borderRadius: 8,\r\n              color: i === 0 ? ink : inkMuted,\r\n              background: i === 0 ? withAlpha(ink, 0.1) : \"transparent\",\r\n            }}\r\n          >\r\n            {m}\r\n          </div>\r\n        ))}\r\n      </div>\r\n\r\n      {/* Command row — manager and subcommand dim, the args highlighted */}\r\n      <div\r\n        style={{\r\n          display: \"flex\",\r\n          alignItems: \"center\",\r\n          height: CMD_H - 54,\r\n          padding: \"0 24px\",\r\n          fontSize: rowFont,\r\n          letterSpacing: \"0.01em\",\r\n          whiteSpace: \"pre\",\r\n        }}\r\n      >\r\n        {(() => {\r\n          let acc = 0;\r\n          return spans.map((p, i) => {\r\n            const start = acc;\r\n            acc += p.text.length;\r\n            const vis = Math.max(0, Math.min(p.text.length, revealed - start));\r\n            return (\r\n              <span\r\n                // biome-ignore lint/suspicious/noArrayIndexKey: positional spans\r\n                key={i}\r\n                style={{ color: p.color }}\r\n              >\r\n                {p.text.slice(0, vis)}\r\n              </span>\r\n            );\r\n          });\r\n        })()}\r\n        {!typingDone && frame >= typeStart && blink && (\r\n          <span\r\n            style={{\r\n              display: \"inline-block\",\r\n              width: rowFont * 0.55,\r\n              height: rowFont,\r\n              background: argColor,\r\n              marginLeft: 2,\r\n            }}\r\n          />\r\n        )}\r\n      </div>\r\n    </div>\r\n  );\r\n}\r\n\r\n/** Station 3 — the green focus terminal. */\r\nfunction TerminalStation({\r\n  frame,\r\n  light,\r\n  lines,\r\n  fontScale,\r\n  charsPerFrame,\r\n  chunkSize,\r\n  fps,\r\n  typeStart,\r\n  primary,\r\n}: {\r\n  frame: number;\r\n  light: boolean;\r\n  lines: TerminalLine[];\r\n  fontScale: number;\r\n  charsPerFrame: number;\r\n  chunkSize: number;\r\n  fps: number;\r\n  typeStart: number;\r\n  primary: boolean;\r\n}) {\r\n  const starts = computeLineStarts(lines, charsPerFrame, chunkSize, typeStart);\r\n  const font = Math.round(TERM_FONT * fontScale);\r\n  const blink = Math.floor((frame / fps) * 2) % 2 === 0;\r\n\r\n  return (\r\n    <>\r\n      {/* Accent bar */}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: TERM_POS.x - TERM_BAR_OFFSET,\r\n          top: TERM_POS.y - 520,\r\n          width: 5,\r\n          height: 1040,\r\n          background: TERM_ACCENT,\r\n          boxShadow: `0 0 22px ${withAlpha(TERM_ACCENT, 0.75)}`,\r\n        }}\r\n      />\r\n      {/* Output column */}\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: TERM_POS.x - TERM_TEXT_OFFSET,\r\n          top: TERM_POS.y - TERM_BLOCK_TOP,\r\n          fontFamily: MONO_FAMILY,\r\n        }}\r\n      >\r\n        {lines.map((line, index) => {\r\n          const revealed = chunkedReveal(\r\n            Math.max(0, frame - starts[index]),\r\n            line.text.length,\r\n            charsPerFrame,\r\n            chunkSize,\r\n          );\r\n          const typingDone = revealed >= line.text.length;\r\n          const isLast = index === lines.length - 1;\r\n          const showCursor =\r\n            line.type === \"command\" &&\r\n            frame >= starts[index] &&\r\n            (!typingDone || (isLast && blink));\r\n          return (\r\n            // The line Studio selects is its row: nothing moves a line on its\r\n            // own, the camera carries the whole column.\r\n            <Item\r\n              // biome-ignore lint/suspicious/noArrayIndexKey: lines are positional and never reorder\r\n              key={index}\r\n              index={index}\r\n              primary={primary}\r\n            >\r\n              <div\r\n                style={{\r\n                  height: TERM_LINE_H,\r\n                  display: \"flex\",\r\n                  alignItems: \"center\",\r\n                  color: (light ? LIGHT_TERM_COLORS : TERM_COLORS)[line.type],\r\n                  fontSize: font,\r\n                  whiteSpace: \"pre\",\r\n                }}\r\n              >\r\n                <span>{line.text.substring(0, revealed)}</span>\r\n                {showCursor && (\r\n                  <span\r\n                    style={{\r\n                      display: \"inline-block\",\r\n                      width: font * 0.6,\r\n                      height: font * 0.95,\r\n                      background: TERM_CURSOR,\r\n                      marginLeft: 6,\r\n                    }}\r\n                  />\r\n                )}\r\n              </div>\r\n            </Item>\r\n          );\r\n        })}\r\n      </div>\r\n    </>\r\n  );\r\n}\r\n\r\nexport { TYPE_COLORS };\r\n"}]}