{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"prompt-zoom","type":"registry:component","title":"Prompt Zoom","description":"AI prompt zoom: an assistant home screen that cuts into the chat input as the prompt types. An assistant landing screen that offers its suggestions, then cuts — hard, in a single frame — into the caret, where the prompt types itself.","dependencies":["remotion","@remotion/google-fonts"],"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","https://kuchi.kalarislabs.com/r/input.json"],"files":[{"path":"components/kuchi/prompt-zoom.tsx","type":"registry:component","target":"components/kuchi/prompt-zoom.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Inter\";\r\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/SourceSerif4\";\r\nimport {\r\n  AbsoluteFill,\r\n  getRemotionEnvironment,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport { inputStyleContext } from \"@/components/kuchi/input\";\r\nimport {\r\n  mixOklch,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n// Loaded through @remotion/google-fonts, never a CSS variable — a Remotion\r\n// bundle has none of the app's CSS, so a `var(--font-…)` gets you the right face\r\n// in the Player and a fallback in the mp4 (design-system rule 4).\r\nconst { fontFamily: SERIF } = loadSerif(\"normal\", {\r\n  weights: [\"400\"],\r\n  subsets: [\"latin\"],\r\n});\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"400\", \"500\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\nexport interface PromptZoomProps {\r\n  /** The greeting above the field. */\r\n  greeting?: string;\r\n  /** Field placeholder, shown until the first character is typed. */\r\n  placeholder?: string;\r\n  /** The prompt that types itself once the cut has landed. */\r\n  text?: string;\r\n  /** Suggestion pills under the field. Empty by default — pass some to show\r\n   *  them. They are static: the shot belongs to the typing and the cut. */\r\n  chips?: string[];\r\n  /** Model label in the field's footer, and the effort beside it. */\r\n  model?: string;\r\n  effort?: string;\r\n  /** Seconds at which typing begins. */\r\n  typeStart?: number;\r\n  /** Seconds at which the view cuts. Not a transition — one frame. It lands\r\n   *  *while the prompt is still being typed*, which is the whole gag. */\r\n  cutAt?: number;\r\n  /** Typing speed. 18 is what the reference measures. */\r\n  charsPerSecond?: number;\r\n  /** How far the cut pushes in. 2.547 is what the reference measures. */\r\n  zoom?: number;\r\n  /** Focal point of the cut, as a fraction of the frame. */\r\n  focusX?: number;\r\n  focusY?: number;\r\n  /** The starburst mark. Defaults to `theme.primary`. */\r\n  accentColor?: string;\r\n  theme?: Partial<KuchiTheme>;\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  speed?: number;\r\n}\r\n\r\n// --- Pure helpers (unit-tested) -------------------------------------------\r\n\r\n/** Characters revealed by effective frame `fc`, clamped to `total`. */\r\nexport function typedCount(\r\n  fc: number,\r\n  startF: number,\r\n  perFrame: number,\r\n  total: number,\r\n): number {\r\n  if (fc <= startF) return 0;\r\n  if (perFrame <= 0) return total;\r\n  return Math.min(total, Math.floor((fc - startF) * perFrame));\r\n}\r\n\r\n/**\r\n * The cut, as a hard boolean. There is no ramp and no easing on purpose.\r\n *\r\n * Measured on the reference: the wide view is intact on one frame and fully\r\n * pushed in on the very next (frames 39 → 40, 803ms → 824ms). Nothing in\r\n * between. Interpolating this — even over two or three frames — turns a cut into\r\n * a zoom, and the whole read of the shot is that it *snaps*.\r\n */\r\nexport function isZoomed(fc: number, cutF: number): boolean {\r\n  return fc >= cutF;\r\n}\r\n\r\n/**\r\n * Caret visibility. Solid whenever a character is actively landing, blinking on\r\n * a 1.06s cycle when it is not — which is what a real text caret does, and what\r\n * stops the shot looking frozen while the prompt waits to start.\r\n */\r\nexport function caretOn(fc: number, fps: number, typing: boolean): boolean {\r\n  if (typing) return true;\r\n  const halfCycle = 0.53 * fps;\r\n  return Math.floor(fc / halfCycle) % 2 === 0;\r\n}\r\n\r\n// --- Icons -----------------------------------------------------------------\r\n\r\nfunction Glyph({\r\n  d,\r\n  size,\r\n  color,\r\n  fill,\r\n}: {\r\n  d: string;\r\n  size: number;\r\n  color: string;\r\n  fill?: boolean;\r\n}) {\r\n  return (\r\n    <svg\r\n      viewBox=\"0 0 24 24\"\r\n      width={size}\r\n      height={size}\r\n      fill={fill ? color : \"none\"}\r\n      stroke={fill ? \"none\" : color}\r\n      strokeWidth={1.8}\r\n      strokeLinecap=\"round\"\r\n      strokeLinejoin=\"round\"\r\n      style={{ display: \"block\", flexShrink: 0 }}\r\n    >\r\n      <title>icon</title>\r\n      <path d={d} />\r\n    </svg>\r\n  );\r\n}\r\n\r\n/** Paths for the default chip set, in order. */\r\nconst CHIP_ICONS = [\r\n  \"M12 20h9M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z\", // pencil\r\n  \"M22 10 12 5 2 10l10 5 10-5ZM6 12v5c3 3 9 3 12 0v-5\", // cap\r\n  \"m8 6-6 6 6 6M16 6l6 6-6 6\", // code\r\n  \"M17 8h1a4 4 0 1 1 0 8h-1M3 8h14v9a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4Z\", // cup\r\n  \"M12 3v18M3 12h18M5.6 5.6l12.8 12.8M18.4 5.6 5.6 18.4\", // spark\r\n];\r\n\r\n/**\r\n * The starburst that leads the greeting.\r\n *\r\n * Twelve rays with a solid hub, measured off the reference: they are roughly a\r\n * ninth of the mark's diameter and clearly separated, and their overlap at the\r\n * centre reads as a filled disc.\r\n *\r\n * Six bars, not twelve. A bar is centred on the origin so it draws a ray at both\r\n * ends — the first version stepped twelve bars by 15° and produced *twenty-four*\r\n * rays, which at a 19px mark is not a starburst, it is a dot.\r\n */\r\nfunction Starburst({ size, color }: { size: number; color: string }) {\r\n  const rays = Array.from({ length: 6 }, (_, i) => i * 30);\r\n  return (\r\n    <svg\r\n      viewBox=\"0 0 24 24\"\r\n      width={size}\r\n      height={size}\r\n      style={{ display: \"block\", flexShrink: 0 }}\r\n    >\r\n      <title>Assistant</title>\r\n      {rays.map((a) => (\r\n        <rect\r\n          key={a}\r\n          x={10.9}\r\n          y={1.6}\r\n          width={2.2}\r\n          height={20.8}\r\n          rx={1.1}\r\n          fill={color}\r\n          transform={`rotate(${a} 12 12)`}\r\n        />\r\n      ))}\r\n      <circle cx={12} cy={12} r={3.6} fill={color} />\r\n    </svg>\r\n  );\r\n}\r\n\r\n// --- Main composition ------------------------------------------------------\r\n\r\n/**\r\n * An assistant's field that types a prompt into itself and, partway through the\r\n * sentence, **cuts** — hard, in a single frame — into the caret and keeps going.\r\n *\r\n * ## The cut is the component\r\n *\r\n * Everything here was taken off a frame-by-frame read of the reference, and the\r\n * one number that matters most is that the push-in happens between two adjacent\r\n * frames with nothing in between. It is a cut, not a move. The scale is\r\n * **2.547×** and it is anchored on a point that sits **10% across and 41% down\r\n * the input field** — which is exactly where the caret is.\r\n *\r\n * The typing starts *before* the cut and does not pause for it: the sentence is\r\n * already running when the frame snaps in, and carries straight on at the new\r\n * size. That is what stops the cut reading as a scene change — there is one\r\n * continuous action across it, and the cut just gets you closer to it.\r\n *\r\n * That focal point is over-determined by the measurement rather than guessed:\r\n * fitting the scale and centre to the field's top and left edges then predicts\r\n * the `+` glyph's centre to within 1.2px and the field's bottom edge to 0.0px.\r\n *\r\n * ## Layout is in the reference's own pixels\r\n *\r\n * The stage below is literally 810×450 — the recording's frame — scaled to fit\r\n * whatever composition it is given. Every position in it is a number measured\r\n * off that recording, so there is no second conversion to get wrong.\r\n *\r\n * ## What is not measured\r\n *\r\n * The colours and the wording. The reference is a specific product: its coral\r\n * mark, its model names, its suggestion labels. None of that belongs in a\r\n * component that ships to strangers and lands next to somebody else's `Input`\r\n * (design-system rule 5). The paint is the shadcn token set, the field takes its\r\n * surface from the `Input` primitive's own style context so the two cannot\r\n * drift, and every label is a prop.\r\n */\r\nexport function PromptZoom({\r\n  greeting = \"Up late?\",\r\n  placeholder = \"How can I help you today?\",\r\n  text = \"Get me a plan for tomorrow\",\r\n  chips = [],\r\n  model = \"Auto\",\r\n  effort = \"Medium\",\r\n  typeStart = 0.35,\r\n  cutAt = 1.0,\r\n  charsPerSecond = 18,\r\n  zoom = 2.547,\r\n  focusX = 0.27,\r\n  focusY = 0.516,\r\n  accentColor,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  speed = 1,\r\n}: PromptZoomProps) {\r\n  const frame = useCurrentFrame();\r\n  const { width, height, fps } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS;\r\n  const ui = inputStyleContext(t);\r\n  const accent = accentColor ?? t.primary;\r\n\r\n  const fc = frame * speed;\r\n\r\n  // The reference's own frame. Laying out in these units means every number\r\n  // below is one that was measured, not one that was converted.\r\n  const REF_W = 810;\r\n  const REF_H = 450;\r\n  const stageScale = Math.min(width / REF_W, height / REF_H);\r\n\r\n  // --- measured layout (recording px) ---\r\n  const BOX = { x: 173, y: 197, w: 461, h: 86, r: 11 };\r\n  const HEAD_Y = 145; // ink top of the greeting\r\n  const HEAD_SIZE = 30; // ~28px ink height including descenders\r\n  const MARK = 19;\r\n  const CHIP_Y = 301;\r\n  const CHIP_H = 26;\r\n  const PAD = 20; // field's inner padding\r\n\r\n  // A hairline is specified at a 40px control; this field is 86 tall, so the\r\n  // token is walked toward the foreground through the system's own mix rather\r\n  // than by picking a darker grey (design-system rule 3b). No drop shadow —\r\n  // under a control this size a visible one is a grey smear (rule 3).\r\n  const borderColor = mixOklch(ui.idleBorder, t.foreground, 0.18);\r\n\r\n  // --- timeline ---\r\n  const cutF = cutAt * fps;\r\n  const zoomed = isZoomed(fc, cutF);\r\n  const typedN = typedCount(\r\n    fc,\r\n    typeStart * fps,\r\n    charsPerSecond / fps,\r\n    text.length,\r\n  );\r\n  const typing = typedN > 0 && typedN < text.length;\r\n  const typed = text.slice(0, typedN);\r\n  const caret = caretOn(fc, fps, typing);\r\n\r\n  const isRendering = getRemotionEnvironment().isRendering;\r\n  const willChange = isRendering ? undefined : (\"transform\" as const);\r\n\r\n  const chipRow =\r\n    chips.length === 0 ? null : (\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: BOX.x,\r\n          top: CHIP_Y,\r\n          width: BOX.w,\r\n          display: \"flex\",\r\n          justifyContent: \"center\",\r\n          gap: 9,\r\n        }}\r\n      >\r\n        {chips.map((chip, i) => {\r\n          return (\r\n            <div\r\n              key={chip}\r\n              style={{\r\n                display: \"inline-flex\",\r\n                alignItems: \"center\",\r\n                gap: 5,\r\n                height: CHIP_H,\r\n                padding: \"0 11px\",\r\n                borderRadius: CHIP_H / 2,\r\n                background: t.card,\r\n                border: `1px solid ${borderColor}`,\r\n                color: t.foreground,\r\n                fontFamily: face,\r\n                fontWeight: 500,\r\n                fontSize: 11,\r\n                lineHeight: 1,\r\n                whiteSpace: \"nowrap\",\r\n                textRendering: \"geometricPrecision\",\r\n              }}\r\n            >\r\n              <Glyph\r\n                d={CHIP_ICONS[i % CHIP_ICONS.length]}\r\n                size={12}\r\n                color={t.mutedForeground}\r\n              />\r\n              {chip}\r\n            </div>\r\n          );\r\n        })}\r\n      </div>\r\n    );\r\n\r\n  return (\r\n    <AbsoluteFill style={{ background: t.background }}>\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: \"50%\",\r\n          top: \"50%\",\r\n          width: REF_W,\r\n          height: REF_H,\r\n          transform: `translate(-50%, -50%) scale(${stageScale})`,\r\n        }}\r\n      >\r\n        {/* The cut. A plain static scale about the caret — no interpolation, so\r\n            there is never a frame of it \"zooming\". `transformOrigin` is the\r\n            measured focal point, in the same units as everything else. */}\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            inset: 0,\r\n            transform: `scale(${zoomed ? zoom : 1})`,\r\n            transformOrigin: `${focusX * REF_W}px ${focusY * REF_H}px`,\r\n            willChange,\r\n          }}\r\n        >\r\n          {/* ---- Greeting */}\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              left: 0,\r\n              right: 0,\r\n              top: HEAD_Y - 6,\r\n              display: \"flex\",\r\n              alignItems: \"center\",\r\n              justifyContent: \"center\",\r\n              gap: 12,\r\n              fontFamily: SERIF,\r\n              fontWeight: 400,\r\n              fontSize: HEAD_SIZE,\r\n              lineHeight: 1.1,\r\n              color: t.foreground,\r\n              textRendering: \"geometricPrecision\",\r\n            }}\r\n          >\r\n            <Starburst size={MARK} color={accent} />\r\n            {greeting}\r\n          </div>\r\n\r\n          {/* ---- The field */}\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              left: BOX.x,\r\n              top: BOX.y,\r\n              width: BOX.w,\r\n              height: BOX.h,\r\n              borderRadius: BOX.r,\r\n              background: t.card,\r\n              border: `1px solid ${borderColor}`,\r\n              boxShadow: \"none\",\r\n            }}\r\n          >\r\n            {/* The prompt line, with the caret riding its end. */}\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: PAD,\r\n                top: PAD - 4,\r\n                right: PAD,\r\n                display: \"flex\",\r\n                alignItems: \"center\",\r\n                fontFamily: face,\r\n                fontWeight: 400,\r\n                fontSize: 12,\r\n                lineHeight: 1.4,\r\n                color: typedN > 0 ? t.foreground : t.mutedForeground,\r\n                whiteSpace: \"pre\",\r\n                textRendering: \"geometricPrecision\",\r\n              }}\r\n            >\r\n              {typedN > 0 ? typed : placeholder}\r\n              <span\r\n                style={{\r\n                  display: \"inline-block\",\r\n                  width: 1.4,\r\n                  height: 15,\r\n                  marginLeft: 1,\r\n                  background: t.foreground,\r\n                  opacity: caret ? 1 : 0,\r\n                }}\r\n              />\r\n            </div>\r\n\r\n            {/* Footer: the add affordance, and the model readout. */}\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: PAD,\r\n                right: PAD,\r\n                bottom: 12,\r\n                display: \"flex\",\r\n                alignItems: \"center\",\r\n                justifyContent: \"space-between\",\r\n                fontFamily: face,\r\n                fontSize: 10,\r\n                color: t.mutedForeground,\r\n              }}\r\n            >\r\n              <Glyph d=\"M12 5v14M5 12h14\" size={13} color={t.mutedForeground} />\r\n              <div style={{ display: \"flex\", alignItems: \"center\", gap: 6 }}>\r\n                <span style={{ color: t.foreground, fontWeight: 500 }}>\r\n                  {model}\r\n                </span>\r\n                <span>{effort}</span>\r\n              </div>\r\n            </div>\r\n          </div>\r\n\r\n          {chipRow}\r\n        </div>\r\n      </div>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}