{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"capture-reveal","type":"registry:component","title":"Capture Reveal","description":"Screenshot capture animation: a toast counts \"Capturing selection…\" up to 100% over a browser window, the window drops away and shrinks, the toast pops to \"Copied to clipboard.\" and a two-line headline rises out from behind the window while the cursor glides up. Every curve was measured off a recording frame by frame: the window's drop and shrink share one cubic-bezier, the toast pops on another, the headline rises without scaling or blurring, and type moves by fractions of a pixel.","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"],"files":[{"path":"components/kuchi/capture-reveal.tsx","type":"registry:component","target":"components/kuchi/capture-reveal.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 loadDmSans } from \"@remotion/google-fonts/DMSans\";\r\nimport {\r\n  type CSSProperties,\r\n  type ReactNode,\r\n  type RefObject,\r\n  useEffect,\r\n  useId,\r\n  useLayoutEffect,\r\n  useRef,\r\n  useState,\r\n} from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  staticFile,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\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/**\r\n * A screenshot being taken: \"Capturing selection… 79%\" counts up in a toast\r\n * over a browser window, the window drops away and shrinks, the toast pops to\r\n * \"Copied to clipboard.\" and a two-line headline rises out from behind the\r\n * window while the cursor glides up to the toast.\r\n *\r\n * ## Everything here was measured off a recording, frame by frame\r\n *\r\n * The numbers below are not taste. They were recovered from a 1.21 second,\r\n * 714 × 394, 24fps screen capture (29 frames) by fitting renders of each\r\n * element to it in BT.709 Y′CbCr, through the capture's own blur (σ 0.62px):\r\n *\r\n *   - the window is ONE transform about a fixed origin: a 107.9px drop and a\r\n *     15.8% shrink on the same curve, `cubic-bezier(0.549, 0.228, 0.136,\r\n *     0.938)` over 19.16 frames (0.06px RMS), and then a slow exponential\r\n *     shrink (τ 1.2s) that starts the frame the drop lands (0.03% RMS).\r\n *   - the cursor glides on its own in-out curve over 19.5 frames and then\r\n *     keeps drifting up — a hand that has not quite stopped (0.07px RMS).\r\n *   - the \"Copied\" toast pops from 0.905 to 1 on `cubic-bezier(0.301, 1.056,\r\n *     0.803, 1)` over 22.8 frames. The \"Capturing\" toast is the same curve run\r\n *     the other way: it presses in to 0.881 while the counter runs, which is\r\n *     why the swap reads as a release.\r\n *   - the headline does not scale and does not blur. It rises 22.6px on\r\n *     `cubic-bezier(0.114, 1, 0.665, 1)` over 24 frames and fades in on a\r\n *     faster curve of its own, from behind the window.\r\n *   - the counter is linear: +3% a frame, 1% → 100%.\r\n *\r\n * The recording starts mid-count, so the 1.33s before its first frame — the\r\n * toast arriving and pressing in — is built from the same curves, not\r\n * measured. Everything after is the recording.\r\n *\r\n * ## The type is DM Sans, at the optical sizes the recording used\r\n *\r\n * Fingerprinted against thirty faces: DM Sans at opsz 40 is the closest free\r\n * match for the headline, and DM Sans at opsz 9 for the toast. The opsz axis is\r\n * pinned per element rather than left to `font-optical-sizing`, so a render at\r\n * any resolution draws the letterforms the recording has — a 1080p render\r\n * would otherwise give the toast its display cut.\r\n */\r\n\r\nconst { fontFamily: DM_SANS } = loadDmSans(\"normal\", {\r\n  weights: [\"400\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\n/** DM Sans with its `opsz` axis, which the Google CSS API does not serve. */\r\nconst FACE = \"Capture Reveal DM Sans\";\r\nconst FACE_URL =\r\n  \"https://cdn.jsdelivr.net/npm/@fontsource-variable/dm-sans@5.3.0/files/dm-sans-latin-opsz-normal.woff2\";\r\nlet faceLoad: Promise<unknown> | null = null;\r\nfunction loadFace(): Promise<unknown> {\r\n  if (faceLoad) return faceLoad;\r\n  if (typeof FontFace === \"undefined\") {\r\n    faceLoad = Promise.resolve();\r\n    return faceLoad;\r\n  }\r\n  const face = new FontFace(FACE, `url(${FACE_URL}) format(\"woff2\")`, {\r\n    weight: \"100 1000\",\r\n  });\r\n  document.fonts.add(face);\r\n  // A face that fails to load leaves Google's DM Sans to paint — close, not exact.\r\n  faceLoad = face.load().catch(() => undefined);\r\n  return faceLoad;\r\n}\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The scene, in the reference's own 714 × 394 pixels and 24fps frames\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport const REF_W = 714;\r\nexport const REF_H = 394;\r\n/** The recording's frame rate. Every time below is in its frames, \"beats\". */\r\nexport const BEATS = 24;\r\n/** Where the recording's first frame sits on this scene's clock, in beats. */\r\nexport const REF_AT = 32;\r\n/** The scene's length in beats: the recording's 29, a held tail, and the lead-in. */\r\nexport const SCENE_BEATS = 104;\r\n\r\n/** The page: a 45px grid, fainter across than down — measured per line. */\r\nexport const GRID = {\r\n  x0: 12.85,\r\n  dx: 45.379,\r\n  y0: 16.44,\r\n  dy: 45.245,\r\n  /** Ink of one line, as a mix toward `foreground` at 1px. */\r\n  across: 0.0275,\r\n  down: 0.0149,\r\n};\r\n\r\n/** The window at rest: its box, top corners, and the shadow it casts. */\r\nexport const WIN = { x: 152.34, y: 106.57, w: 400.76, r: 9 };\r\nexport const WIN_SHADOW = { dy: 5.9, blur: 10.07, spread: -1.21, alpha: 0.207 };\r\n/** The point the window scales about — its centre, on the measured 508.5 box. */\r\nexport const WIN_ORIGIN = [352.85, 361.33] as const;\r\n/** The drop: how far, and the shrink that rides the same curve. */\r\nexport const DROP = 107.905;\r\nexport const SHRINK = 0.1581;\r\nexport const DROP_AT = 0.154;\r\nexport const DROP_FOR = 19.16;\r\nexport const DROP_EASE = Easing.bezier(0.5492, 0.2279, 0.1361, 0.9381);\r\n/** The slow shrink after the drop lands. */\r\nexport const SETTLE = 0.0267;\r\nexport const SETTLE_AT = 18.62;\r\nexport const SETTLE_TAU = 28.94;\r\n\r\n/** The cursor's tip, where it glides, and the drift after. */\r\nexport const CURSOR_FROM = [573.334, 189.634] as const;\r\nexport const CURSOR_BY = [-83.28, -111.49] as const;\r\nexport const CURSOR_AT = -0.03;\r\nexport const CURSOR_FOR = 19.5;\r\nexport const CURSOR_EASE = Easing.bezier(0.54, 0.1, 0.41, 0.97);\r\nexport const DRIFT = [-0.16, -0.43] as const;\r\nexport const DRIFT_AT = 19;\r\n/** The arrowhead, from its tip: right point, notch, heel. Fitted outline. */\r\nexport const ARROW: readonly (readonly [number, number])[] = [\r\n  [0, 0],\r\n  [14.779, 15.455],\r\n  [5.855, 15.72],\r\n  [0.051, 21.146],\r\n];\r\nexport const ARROW_OUTLINE = 1.194;\r\nexport const ARROW_SHADOW = {\r\n  dx: -1.571,\r\n  dy: 1.45,\r\n  sigma: 0.716,\r\n  alpha: 0.247,\r\n};\r\n\r\n/** The headline: centre, the middle of its block, and the type. */\r\nexport const HEAD = {\r\n  x: 353.64,\r\n  mid: 188.619,\r\n  pitch: 45.304,\r\n  size: 45.93,\r\n  weight: 367,\r\n  track: 0.952,\r\n  opsz: 40,\r\n  /** Its ink, as a mix from `foreground` toward `mutedForeground`: #2b2b2b. */\r\n  ink: 0.29,\r\n};\r\nexport const RISE = 22.585;\r\nexport const RISE_AT = 7.342;\r\nexport const RISE_FOR = 23.972;\r\nexport const RISE_EASE = Easing.bezier(0.114, 1, 0.665, 1);\r\nexport const FADE_AT = 8;\r\nexport const FADE_FOR = 8.322;\r\nexport const FADE_EASE = Easing.bezier(0, 0.235, 0.166, 1);\r\n\r\n/** Both toasts share a surface and a type style. */\r\nexport const TOAST = {\r\n  h: 49.357,\r\n  r: 8.879,\r\n  shadow: { dy: 0.012, blur: 14.549, spread: -2.397, alpha: 0.2512 },\r\n  size: 12.46,\r\n  weight: 347,\r\n  track: -0.192,\r\n  opsz: 9,\r\n};\r\n/** \"Copied\": centre, and its row laid out from the box's left edge. */\r\nexport const COPIED = {\r\n  at: [357.7, 62.904] as const,\r\n  check: { x: 21.371, dy: 0.005, r: 7.143, stroke: 1.124 },\r\n  /** The tick, from the circle's centre. */\r\n  tick: [\r\n    [-3.232, 0.238],\r\n    [-0.916, 2.835],\r\n    [3.193, -2.28],\r\n  ] as const,\r\n  text: { x: 38.469, base: 3.445 },\r\n  right: 18.464,\r\n};\r\n/**\r\n * \"Capturing\": centre and scale at rest, and its row from the box's left edge.\r\n * The counter gets the width of \"100%\" whatever it reads, so the box does not\r\n * twitch as the digits change — with the same 10px either side of it.\r\n */\r\nexport const CAPTURING = {\r\n  at: [353.221, 63.002] as const,\r\n  scale: 0.8855,\r\n  icon: { x: 20.957, dy: -1.09 },\r\n  text: { x: 39.039, base: 3.665 },\r\n  gap: 10.067,\r\n  right: 10.067,\r\n  percent: { base: 4.731 },\r\n};\r\n/**\r\n * The toast's mark: kuchi's, in its own 432 × 349.84 ink box, set 14px wide and\r\n * centred where the reference's app mark sat (its box ran x −5.5…8.9, y −5.9…8.7).\r\n * The recording carried another product's logo; a component ships ours.\r\n */\r\nexport const MARK = {\r\n  path: \"M76.9648 0H355.03520000000003Q432 0 432 76.9648V272.87519999999995Q432 349.84 355.03520000000003 349.84H76.9648Q0 349.84 0 272.87519999999995V76.9648Q0 0 76.9648 0Z\",\r\n  width: 432,\r\n  height: 349.84,\r\n  /** Rendered width, and the centre it sits on, in reference pixels. */\r\n  size: 14,\r\n  cx: 1.7,\r\n  cy: 1.4,\r\n};\r\n/**\r\n * The toast's greys, as mixes of the theme's own: on the default light theme\r\n * they land on the recording's #474747 / #4f4f4f / #d0d0d0 / #c9c9c9.\r\n */\r\nexport const INK = {\r\n  copied: 0.615,\r\n  capturing: 0.705,\r\n  percent: 0.6975,\r\n  mark: 0.6525,\r\n};\r\n/** The swap, and the pop both toasts ride. */\r\nexport const SWAP_AT = 7.5;\r\nexport const POP_FROM = 0.9053;\r\nexport const POP_FOR = 22.84;\r\nexport const POP_EASE = Easing.bezier(0.3012, 1.056, 0.8028, 1.0);\r\n/** The lead-in nobody recorded: the toast arrives, then presses in. */\r\nexport const TOAST_IN = -26;\r\nexport const PRESS_AT = -24;\r\n/** The counter: 1% at `TOAST_IN`, three a frame. */\r\nexport const COUNT_RATE = 3;\r\n\r\nconst unit = (v: number) => Math.min(1, Math.max(0, v));\r\nconst ease = (f: (t: number) => number, at: number, dur: number, n: number) =>\r\n  f(unit((n - at) / dur));\r\n\r\n/** The window's drop and scale at beat `n`. */\r\nexport function windowAt(n: number): { drop: number; scale: number } {\r\n  const p = ease(DROP_EASE, DROP_AT, DROP_FOR, n);\r\n  const settle =\r\n    n > SETTLE_AT ? SETTLE * (1 - Math.exp(-(n - SETTLE_AT) / SETTLE_TAU)) : 0;\r\n  return { drop: DROP * p, scale: 1 - SHRINK * p - settle };\r\n}\r\n\r\n/** The cursor tip at beat `n`. */\r\nexport function cursorAt(n: number): [number, number] {\r\n  const p = ease(CURSOR_EASE, CURSOR_AT, CURSOR_FOR, n);\r\n  const d = Math.max(0, n - DRIFT_AT);\r\n  return [\r\n    CURSOR_FROM[0] + CURSOR_BY[0] * p + DRIFT[0] * d,\r\n    CURSOR_FROM[1] + CURSOR_BY[1] * p + DRIFT[1] * d,\r\n  ];\r\n}\r\n\r\n/** The headline's rise (px still to climb) and opacity at beat `n`. */\r\n/**\r\n * The outro — not in the recording, built from its curves: once everything has\r\n * settled, the window slides out of the bottom of the frame on the drop's own\r\n * curve, the toast and cursor fade out on the headline's fade run backwards,\r\n * and the headline pushes forward to the middle of the frame.\r\n */\r\nexport const OUTRO_AT = 40;\r\n/** How far the window falls on its way out, past the frame's bottom edge. */\r\nexport const OUTRO_DROP = 240;\r\n/** The headline's push: scale, and the frame-middle it settles on. */\r\nexport const OUTRO_SCALE = 1.3;\r\nexport const OUTRO_MID = REF_H / 2;\r\n\r\n/** Outro progress at beat `n`: the drop (window, headline) and the fade. */\r\nexport function outroAt(n: number): { p: number; fade: number } {\r\n  return {\r\n    p: ease(DROP_EASE, OUTRO_AT, DROP_FOR, n),\r\n    fade: n < OUTRO_AT ? 1 : 1 - ease(FADE_EASE, OUTRO_AT, FADE_FOR, n),\r\n  };\r\n}\r\n\r\nexport function headlineAt(n: number): { rise: number; opacity: number } {\r\n  return {\r\n    rise: RISE * (1 - ease(RISE_EASE, RISE_AT, RISE_FOR, n)),\r\n    opacity: n < FADE_AT ? 0 : ease(FADE_EASE, FADE_AT, FADE_FOR, n),\r\n  };\r\n}\r\n\r\n/** The counter's reading at beat `n`. */\r\nexport function percentAt(n: number): number {\r\n  // The epsilon is for the clock, not the count: 32/24·24 is 31.999…\r\n  return Math.min(100, Math.floor(1 + COUNT_RATE * (n - TOAST_IN) + 1e-6));\r\n}\r\n\r\n/** Which toast is up, and its scale and opacity at beat `n`. */\r\nexport function toastAt(n: number): {\r\n  copied: boolean;\r\n  scale: number;\r\n  opacity: number;\r\n} {\r\n  if (n >= SWAP_AT) {\r\n    const p = ease(POP_EASE, SWAP_AT, POP_FOR, n);\r\n    return { copied: true, scale: POP_FROM + (1 - POP_FROM) * p, opacity: 1 };\r\n  }\r\n  const p = ease(POP_EASE, PRESS_AT, POP_FOR, n);\r\n  return {\r\n    copied: false,\r\n    scale: 1 - (1 - CAPTURING.scale) * p,\r\n    opacity: n < TOAST_IN ? 0 : ease(FADE_EASE, TOAST_IN, FADE_FOR, n),\r\n  };\r\n}\r\n\r\n/**\r\n * A line of type that can sit — and move — a fraction of a pixel.\r\n *\r\n * Chrome rounds a glyph run's baseline to a whole device pixel, in HTML and\r\n * SVG alike. The headline's rise ends in a long, slow crawl — a tenth of a\r\n * pixel a frame — that would otherwise hold still and then jump. So the line\r\n * is painted twice, one device pixel apart, both on whole pixels, cross-faded\r\n * by the fraction in between; `plus-lighter` adds the two copies' coverage,\r\n * so the blend is exactly linear. (Same trick as check-cycle.)\r\n */\r\nfunction Line({\r\n  x,\r\n  y,\r\n  dev,\r\n  style,\r\n  children,\r\n}: {\r\n  x: number;\r\n  y: number;\r\n  /** A baseline at y, in this group's units, lands on device row a·y + b. */\r\n  dev: { a: number; b: number };\r\n  style: CSSProperties;\r\n  children: ReactNode;\r\n}) {\r\n  // The Player scales the scene with CSS, so its pixel grid is not the one\r\n  // `dev` describes — there a single copy is the honest choice.\r\n  if (getRemotionEnvironment().isPlayer)\r\n    return (\r\n      <text x={x} y={y} style={style}>\r\n        {children}\r\n      </text>\r\n    );\r\n  const d = dev.a * y + dev.b;\r\n  const lo = Math.floor(d);\r\n  const f = d - lo;\r\n  const at = (row: number) => (row + 1e-3 - dev.b) / dev.a;\r\n  return (\r\n    <g style={{ isolation: \"isolate\" }}>\r\n      {[\r\n        [lo, 1 - f],\r\n        [lo + 1, f],\r\n      ].map(([row, w]) =>\r\n        (w ?? 0) < 1e-3 ? null : (\r\n          <text\r\n            key={row}\r\n            x={x}\r\n            y={at(row ?? 0)}\r\n            style={{ ...style, opacity: w, mixBlendMode: \"plus-lighter\" }}\r\n          >\r\n            {children}\r\n          </text>\r\n        ),\r\n      )}\r\n    </g>\r\n  );\r\n}\r\n\r\n/**\r\n * A root-relative asset is a `public/` file. Only the site's own Player serves\r\n * it at that path; Remotion Studio and a render know its URL through\r\n * `staticFile()` alone — so every environment but the Player rewrites it.\r\n */\r\nfunction resolveSrc(src: string): string {\r\n  const isLocal = src.startsWith(\"/\") && !src.startsWith(\"//\");\r\n  if (!isLocal || getRemotionEnvironment().isPlayer) return src;\r\n  const base = staticFile(\"_\").slice(0, -2);\r\n  if (base && src.startsWith(`${base}/`)) return src;\r\n  try {\r\n    return staticFile(src.replace(/^\\/+/, \"\"));\r\n  } catch {\r\n    return src;\r\n  }\r\n}\r\n\r\n/** The screenshot's natural aspect, held behind the render until it is known. */\r\nfunction useAspect(src: string): number | null {\r\n  const [aspect, setAspect] = useState<number | null>(null);\r\n  const [handle] = useState(() => delayRender(`capture-reveal: ${src}`));\r\n  useEffect(() => {\r\n    if (!src) {\r\n      continueRender(handle);\r\n      return;\r\n    }\r\n    const img = new Image();\r\n    img.onload = () => {\r\n      setAspect(img.naturalHeight / Math.max(1, img.naturalWidth));\r\n      continueRender(handle);\r\n    };\r\n    img.onerror = () => continueRender(handle);\r\n    img.src = src;\r\n  }, [src, handle]);\r\n  return aspect;\r\n}\r\n\r\n/** Advance widths of the toast copy, measured in the real face once it loads. */\r\nfunction useWidths(\r\n  texts: string[],\r\n  font: string,\r\n): [number[] | null, RefObject<SVGGElement | null>] {\r\n  const probe = useRef<SVGGElement>(null);\r\n  const [widths, setWidths] = useState<number[] | null>(null);\r\n  const [handle] = useState(() => delayRender(\"capture-reveal: measure\"));\r\n  const key = texts.join(\"\\u0000\");\r\n  // biome-ignore lint/correctness/useExhaustiveDependencies: `key` is `texts`\r\n  useLayoutEffect(() => {\r\n    let live = true;\r\n    loadFace()\r\n      .then(() => document.fonts.ready)\r\n      .then(() => {\r\n        if (!live) return;\r\n        const nodes = probe.current?.querySelectorAll(\"text\") ?? [];\r\n        setWidths(Array.from(nodes, (t) => t.getComputedTextLength()));\r\n        continueRender(handle);\r\n      });\r\n    return () => {\r\n      live = false;\r\n    };\r\n  }, [key, font, handle]);\r\n  return [widths, probe];\r\n}\r\n\r\nexport interface CaptureRevealProps {\r\n  /** The headline; `|` breaks it into lines. */\r\n  headline?: string;\r\n  /** The toast while the counter runs. */\r\n  capturing?: string;\r\n  /** The toast once it lands. */\r\n  copied?: string;\r\n  /** The screenshot in the window: an image, laid in at full width, top first. */\r\n  src?: string;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  fontFamily?: string;\r\n}\r\n\r\nexport function CaptureReveal({\r\n  headline = \"no more | keyframes\",\r\n  capturing = \"Capturing selection...\",\r\n  copied = \"Copied to clipboard.\",\r\n  src = \"https://kuchi-media.kalarislabs.com/components/art/art-03.svg\",\r\n  theme,\r\n  mode = \"light\",\r\n  fontFamily = \"Default\",\r\n}: CaptureRevealProps) {\r\n  const frame = useCurrentFrame();\r\n  const { fps, width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily) ?? `\"${FACE}\", ${DM_SANS}`;\r\n  const id = useId().replace(/:/g, \"\");\r\n  const image = src ? resolveSrc(src) : \"\";\r\n  const aspect = useAspect(image);\r\n  const [widths, probe] = useWidths([capturing, copied, \"100%\"], face);\r\n\r\n  const n = (frame / fps) * BEATS - REF_AT;\r\n  const u = Math.min(width / REF_W, height / REF_H);\r\n  const left = (width - REF_W * u) / 2;\r\n  const top = (height - REF_H * u) / 2;\r\n  // A Remotion render's `scale` is the page's devicePixelRatio.\r\n  const dpr = typeof window === \"undefined\" ? 1 : window.devicePixelRatio || 1;\r\n\r\n  /* — the page — */\r\n  const lineX = mixOklch(t.background, t.foreground, GRID.down);\r\n  const lineY = mixOklch(t.background, t.foreground, GRID.across);\r\n  const view = { x: -left / u, y: -top / u, w: width / u, h: height / u };\r\n  const cols: number[] = [];\r\n  for (\r\n    let x = GRID.x0 + Math.floor((view.x - GRID.x0) / GRID.dx) * GRID.dx;\r\n    x < view.x + view.w;\r\n    x += GRID.dx\r\n  )\r\n    cols.push(x);\r\n  const rows: number[] = [];\r\n  for (\r\n    let y = GRID.y0 + Math.floor((view.y - GRID.y0) / GRID.dy) * GRID.dy;\r\n    y < view.y + view.h;\r\n    y += GRID.dy\r\n  )\r\n    rows.push(y);\r\n\r\n  /* — the window — */\r\n  const win = windowAt(n);\r\n  const [ox, oy] = WIN_ORIGIN;\r\n  const winH = WIN.w * (aspect ?? 1.25);\r\n  const out = outroAt(n);\r\n  const winT = `translate(${ox} ${oy + win.drop + OUTRO_DROP * out.p}) scale(${win.scale}) translate(${-ox} ${-oy})`;\r\n\r\n  /* — the headline — */\r\n  const lines = headline\r\n    .split(\"|\")\r\n    .map((l) => l.trim())\r\n    .filter(Boolean);\r\n  const head = headlineAt(n);\r\n  const headType: CSSProperties = {\r\n    fontFamily: face,\r\n    fontSize: HEAD.size,\r\n    fontWeight: HEAD.weight,\r\n    fontVariationSettings: `\"opsz\" ${HEAD.opsz}`,\r\n    letterSpacing: HEAD.track,\r\n    fill: mixOklch(t.foreground, t.mutedForeground, HEAD.ink),\r\n    textAnchor: \"middle\",\r\n    // Unhinted outlines, so the sub-pixel `Line` blend moves the shape it drew.\r\n    textRendering: \"geometricPrecision\",\r\n  };\r\n\r\n  /* — the toast — */\r\n  const toast = toastAt(n);\r\n  const [wCapturing, wCopied, wFull] = widths ?? [0, 0, 0];\r\n  const capText = CAPTURING.text.x + (wCapturing ?? 0) + CAPTURING.gap;\r\n  const boxW = toast.copied\r\n    ? COPIED.text.x + (wCopied ?? 0) + COPIED.right\r\n    : capText + (wFull ?? 0) + CAPTURING.right;\r\n  const [cx, cy] = toast.copied ? COPIED.at : CAPTURING.at;\r\n  const boxL = cx - boxW / 2;\r\n  const s = toast.scale;\r\n  const toastType: CSSProperties = {\r\n    fontFamily: face,\r\n    fontSize: TOAST.size,\r\n    fontWeight: TOAST.weight,\r\n    fontVariationSettings: `\"opsz\" ${TOAST.opsz}`,\r\n    letterSpacing: TOAST.track,\r\n    textRendering: \"geometricPrecision\",\r\n  };\r\n  // Toast group: y_stage = cy + s·(y − cy) → device row = a·y + b.\r\n  const toastDev = { a: dpr * u * s, b: dpr * (top + u * cy * (1 - s)) };\r\n  // The push scales the block about its middle and carries that middle to the\r\n  // frame's: y_stage = m + k·(y − mid), so the rows map as a·y + b.\r\n  const k = 1 + (OUTRO_SCALE - 1) * out.p;\r\n  const m = HEAD.mid + (OUTRO_MID - HEAD.mid) * out.p;\r\n  const headT = `translate(${HEAD.x} ${m}) scale(${k}) translate(${-HEAD.x} ${-HEAD.mid})`;\r\n  const headDev = { a: dpr * u * k, b: dpr * (top + u * (m - k * HEAD.mid)) };\r\n  const ts = TOAST.shadow;\r\n\r\n  /* — the cursor — */\r\n  const [tx, ty] = cursorAt(n);\r\n\r\n  const muted = t.mutedForeground;\r\n  const inkCopied = mixOklch(t.foreground, muted, INK.copied);\r\n  const inkCapturing = mixOklch(t.foreground, muted, INK.capturing);\r\n  const inkPercent = mixOklch(muted, t.card, INK.percent);\r\n  const inkMark = mixOklch(muted, t.card, INK.mark);\r\n  const check = { x: boxL + COPIED.check.x, y: cy + COPIED.check.dy };\r\n\r\n  return (\r\n    <AbsoluteFill style={{ backgroundColor: t.background }}>\r\n      <svg\r\n        width={width}\r\n        height={height}\r\n        viewBox={`${view.x} ${view.y} ${view.w} ${view.h}`}\r\n        style={{ position: \"absolute\", inset: 0 }}\r\n      >\r\n        <defs>\r\n          <filter id={`${id}-win`} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\r\n            <feGaussianBlur stdDeviation={WIN_SHADOW.blur / 2} />\r\n          </filter>\r\n          <filter\r\n            id={`${id}-toast`}\r\n            x=\"-50%\"\r\n            y=\"-100%\"\r\n            width=\"200%\"\r\n            height=\"300%\"\r\n          >\r\n            <feGaussianBlur stdDeviation={ts.blur / 2} />\r\n          </filter>\r\n          <filter\r\n            id={`${id}-arrow`}\r\n            x=\"-50%\"\r\n            y=\"-50%\"\r\n            width=\"200%\"\r\n            height=\"200%\"\r\n          >\r\n            <feDropShadow\r\n              dx={ARROW_SHADOW.dx}\r\n              dy={ARROW_SHADOW.dy}\r\n              stdDeviation={ARROW_SHADOW.sigma}\r\n              floodColor=\"#000\"\r\n              floodOpacity={ARROW_SHADOW.alpha}\r\n            />\r\n          </filter>\r\n          <clipPath id={`${id}-clip`}>\r\n            <rect x={WIN.x} y={WIN.y} width={WIN.w} height={winH} rx={WIN.r} />\r\n          </clipPath>\r\n        </defs>\r\n\r\n        {/* The page's grid: hairlines, one reference pixel wide. */}\r\n        <g>\r\n          {cols.map((x) => (\r\n            <rect\r\n              key={`c${x}`}\r\n              x={x - 0.5}\r\n              y={view.y}\r\n              width={1}\r\n              height={view.h}\r\n              fill={lineX}\r\n            />\r\n          ))}\r\n          {rows.map((y) => (\r\n            <rect\r\n              key={`r${y}`}\r\n              x={view.x}\r\n              y={y - 0.5}\r\n              width={view.w}\r\n              height={1}\r\n              fill={lineY}\r\n            />\r\n          ))}\r\n        </g>\r\n\r\n        {/* The headline sits behind the window and rises out from under it. */}\r\n        {head.opacity > 0 && (\r\n          <g opacity={head.opacity} transform={headT}>\r\n            {lines.map((line, i) => (\r\n              <Line\r\n                key={`${i}-${line}`}\r\n                x={HEAD.x}\r\n                y={\r\n                  HEAD.mid +\r\n                  (i - (lines.length - 1) / 2) * HEAD.pitch +\r\n                  head.rise\r\n                }\r\n                dev={headDev}\r\n                style={headType}\r\n              >\r\n                {line}\r\n              </Line>\r\n            ))}\r\n          </g>\r\n        )}\r\n\r\n        {/* The window. */}\r\n        <g transform={winT}>\r\n          <rect\r\n            x={WIN.x - WIN_SHADOW.spread}\r\n            y={WIN.y + WIN_SHADOW.dy - WIN_SHADOW.spread}\r\n            width={WIN.w + 2 * WIN_SHADOW.spread}\r\n            height={winH + 2 * WIN_SHADOW.spread}\r\n            rx={Math.max(0, WIN.r + WIN_SHADOW.spread)}\r\n            fill=\"#000\"\r\n            opacity={WIN_SHADOW.alpha}\r\n            filter={`url(#${id}-win)`}\r\n          />\r\n          <g clipPath={`url(#${id}-clip)`}>\r\n            <rect\r\n              x={WIN.x}\r\n              y={WIN.y}\r\n              width={WIN.w}\r\n              height={winH}\r\n              fill={t.card}\r\n            />\r\n            {image && (\r\n              <image\r\n                href={image}\r\n                x={WIN.x}\r\n                y={WIN.y}\r\n                width={WIN.w}\r\n                height={winH}\r\n                preserveAspectRatio=\"xMidYMin slice\"\r\n              />\r\n            )}\r\n          </g>\r\n        </g>\r\n\r\n        {/* The toast. */}\r\n        {toast.opacity * out.fade > 0 && (\r\n          <g\r\n            opacity={toast.opacity * out.fade}\r\n            transform={`translate(${cx} ${cy}) scale(${s}) translate(${-cx} ${-cy})`}\r\n          >\r\n            <rect\r\n              x={cx - boxW / 2 - ts.spread}\r\n              y={cy - TOAST.h / 2 + ts.dy - ts.spread}\r\n              width={boxW + 2 * ts.spread}\r\n              height={TOAST.h + 2 * ts.spread}\r\n              rx={Math.max(0, TOAST.r + ts.spread)}\r\n              fill=\"#000\"\r\n              opacity={ts.alpha}\r\n              filter={`url(#${id}-toast)`}\r\n            />\r\n            <rect\r\n              x={cx - boxW / 2}\r\n              y={cy - TOAST.h / 2}\r\n              width={boxW}\r\n              height={TOAST.h}\r\n              rx={TOAST.r}\r\n              fill={t.card}\r\n            />\r\n            {toast.copied ? (\r\n              <>\r\n                <circle\r\n                  cx={check.x}\r\n                  cy={check.y}\r\n                  r={COPIED.check.r}\r\n                  fill={t.primary}\r\n                />\r\n                <polyline\r\n                  points={COPIED.tick\r\n                    .map(([a, b]) => `${check.x + a},${check.y + b}`)\r\n                    .join(\" \")}\r\n                  fill=\"none\"\r\n                  stroke={t.primaryForeground}\r\n                  strokeWidth={COPIED.check.stroke}\r\n                  strokeLinecap=\"round\"\r\n                  strokeLinejoin=\"round\"\r\n                />\r\n                <Line\r\n                  x={boxL + COPIED.text.x}\r\n                  y={cy + COPIED.text.base}\r\n                  dev={toastDev}\r\n                  style={{ ...toastType, fill: inkCopied }}\r\n                >\r\n                  {copied}\r\n                </Line>\r\n              </>\r\n            ) : (\r\n              <>\r\n                <Mark\r\n                  x={boxL + CAPTURING.icon.x}\r\n                  y={cy + CAPTURING.icon.dy}\r\n                  ink={inkMark}\r\n                />\r\n                <Line\r\n                  x={boxL + CAPTURING.text.x}\r\n                  y={cy + CAPTURING.text.base}\r\n                  dev={toastDev}\r\n                  style={{ ...toastType, fill: inkCapturing }}\r\n                >\r\n                  {capturing}\r\n                </Line>\r\n                <Line\r\n                  x={boxL + capText}\r\n                  y={cy + CAPTURING.percent.base}\r\n                  dev={toastDev}\r\n                  style={{ ...toastType, fill: inkPercent }}\r\n                >\r\n                  {`${percentAt(n)}%`}\r\n                </Line>\r\n              </>\r\n            )}\r\n          </g>\r\n        )}\r\n\r\n        {/* The cursor is the system's, not the app's: black on a white\r\n            outline in either mode, the way a real pointer is. */}\r\n        <polygon\r\n          opacity={out.fade}\r\n          points={ARROW.map(([a, b]) => `${tx + a},${ty + b}`).join(\" \")}\r\n          fill=\"#000000\"\r\n          stroke=\"#ffffff\"\r\n          strokeWidth={2 * ARROW_OUTLINE}\r\n          strokeLinejoin=\"round\"\r\n          paintOrder=\"stroke\"\r\n          filter={`url(#${id}-arrow)`}\r\n        />\r\n\r\n        {/* Width probes for the toast copy, in the real face, never painted. */}\r\n        <g ref={probe} visibility=\"hidden\" aria-hidden>\r\n          <Probe style={toastType} texts={[capturing, copied, \"100%\"]} />\r\n        </g>\r\n      </svg>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n\r\nfunction Probe({ style, texts }: { style: CSSProperties; texts: string[] }) {\r\n  return (\r\n    <>\r\n      {texts.map((s, i) => (\r\n        <text key={`${i}-${s}`} x={0} y={-1000} style={style}>\r\n          {s}\r\n        </text>\r\n      ))}\r\n    </>\r\n  );\r\n}\r\n\r\n/** The selection mark: a back sheet, and a front sheet with a hole in it. */\r\nfunction Mark({ x, y, ink }: { x: number; y: number; ink: string }) {\r\n  const k = MARK.size / MARK.width;\r\n  const left = x + MARK.cx - MARK.size / 2;\r\n  const top = y + MARK.cy - (MARK.height * k) / 2;\r\n  return (\r\n    <path\r\n      d={MARK.path}\r\n      fill={ink}\r\n      transform={`translate(${left} ${top}) scale(${k})`}\r\n    />\r\n  );\r\n}\r\n"}]}