{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "yes-run",
  "title": "Yes Run",
  "description": "\"Free?\" is answered by a black \"Yes.\" tag on bright orange.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/yes-run/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Unbounded\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst unbounded = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface YesRunProps {\n  questions?: string[];\n  answer?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_QUESTIONS = [\n  \"Vertical?\",\n  \"Captions?\",\n  \"Your fonts?\",\n  \"Dark mode?\",\n  \"Transitions?\",\n  \"Renders in CI?\",\n  \"In your repo?\",\n  \"Free?\",\n];\n\nconst FONT_PX = 200;\nconst WGHT = 500;\nconst TRACK = -0.03;\nconst GAP = 0.3;\nconst PAD_X = 0.26;\nconst LINE = 1.16;\nconst ROW_GAP = 0.06;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_PUSH = Easing.bezier(0.5, 0, 0.1, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst FIRST_DWELL = 32;\nconst RATIO = 0.8;\nconst MIN_DWELL = 10;\nconst LAST_PUSH = 11;\nconst LAST_MIN = 44;\n\ninterface Split {\n  head: string;\n  tail: string;\n  hw: number;\n  tw: number;\n}\n\ninterface Metrics {\n  q: number[];\n  splits: Split[][];\n  a: number;\n  asc: number;\n  desc: number;\n  cap: number;\n}\n\nfunction measure(questions: string[], answer: string): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"yes-run: no 2d context\");\n  ctx.font = `${WGHT} ${FONT_PX}px \"${unbounded.fontFamily}\"`;\n  const em = (s: string) =>\n    ctx.measureText(s).width / FONT_PX +\n    TRACK * Math.max(0, Array.from(s).length - 1);\n  const fm = ctx.measureText(\"Hgy\");\n  return {\n    q: questions.map(em),\n    splits: questions.map((q) => {\n      const words = q.split(\" \");\n      const out: Split[] = [];\n      for (let i = 1; i < words.length; i++) {\n        const head = words.slice(0, i).join(\" \");\n        const tail = words.slice(i).join(\" \");\n        out.push({ head, tail, hw: em(head), tw: em(tail) });\n      }\n      return out;\n    }),\n    a: em(answer),\n    asc: fm.fontBoundingBoxAscent / FONT_PX,\n    desc: fm.fontBoundingBoxDescent / FONT_PX,\n    cap: ctx.measureText(\"H\").actualBoundingBoxAscent / FONT_PX,\n  };\n}\n\nfunction useMetrics(questions: string[], answer: string) {\n  const key = `${answer}\\u0001${questions.join(\"\\u0002\")}`;\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"yes-run: measuring\"));\n  const released = useRef(false);\n  const input = useRef({ questions, answer });\n  input.current = { questions, answer };\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      unbounded.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${unbounded.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({\n          key,\n          m: measure(input.current.questions, input.current.answer),\n        });\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [key, handle]);\n  return state && state.key === key ? state.m : null;\n}\n\ninterface Row {\n  text: string;\n  w: number;\n  yes: boolean;\n}\n\ninterface Exchange {\n  start: number;\n  push: number;\n  yesAt: number;\n  yesLen: number;\n  size: number;\n  rows: Row[];\n  h: number;\n}\n\nfunction chooseRows(\n  q: string,\n  qw: number,\n  splits: Split[],\n  bw: number,\n  measureW: number,\n  fMax: number,\n  inlineBias: number,\n): { rows: Row[]; size: number } {\n  const fitOf = (rows: Row[]) =>\n    Math.min(\n      fMax,\n      measureW /\n        Math.max(\n          ...rows.map((r) => r.w + (r.yes ? (r.w > 0 ? GAP : 0) + bw : 0)),\n        ),\n    );\n  const inline: Row[] = [{ text: q, w: qw, yes: true }];\n  const options: Row[][] = [\n    inline,\n    [\n      { text: q, w: qw, yes: false },\n      { text: \"\", w: 0, yes: true },\n    ],\n  ];\n  for (const s of splits) {\n    options.push([\n      { text: s.head, w: s.hw, yes: false },\n      { text: s.tail, w: s.tw, yes: true },\n    ]);\n  }\n  const inlineFit = fitOf(inline);\n  let best = inline;\n  let bestFit = inlineFit;\n  for (const o of options) {\n    const f = fitOf(o);\n    if (f > bestFit) {\n      best = o;\n      bestFit = f;\n    }\n  }\n  if (inlineFit >= bestFit * inlineBias)\n    return { rows: inline, size: inlineFit };\n  return { rows: best, size: bestFit };\n}\n\nexport function YesRun({\n  questions = DEFAULT_QUESTIONS,\n  answer = \"Yes.\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: YesRunProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const dark = theme === \"dark\";\n  const field = dark ? (accent ?? \"#FF5A1F\") : \"#FFFFFF\";\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? field);\n  const ink = \"#000000\";\n  const block = dark ? \"#000000\" : (accent ?? \"#E8480F\");\n  const blockInk = dark ? field : \"#FFFFFF\";\n\n  const qs = questions.length > 0 ? questions : DEFAULT_QUESTIONS;\n  const m = useMetrics(qs, answer);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const n = qs.length;\n  const total = durationInFrames * speed;\n  const natural = Array.from({ length: n - 1 }, (_, k) =>\n    Math.max(MIN_DWELL, FIRST_DWELL * RATIO ** k),\n  );\n  const sum = natural.reduce((s, d) => s + d, 0);\n  const fit = sum > 0 ? Math.min(1, (total - LAST_MIN) / sum) : 1;\n  const dwells = natural.map((d) => Math.max(7, Math.round(d * fit)));\n\n  const portrait = H > W * 1.1;\n  const fMax = Math.min(\n    H * (portrait ? 0.1 : 0.22),\n    W * (portrait ? 0.16 : 0.13),\n  );\n  const measureW = W * (portrait ? 0.84 : 0.86);\n  const bwEm = m.a + PAD_X * 2;\n\n  const exchanges: Exchange[] = [];\n  let at = 0;\n  for (let k = 0; k < n; k++) {\n    const last = k === n - 1;\n    const dwell = last ? total - at : dwells[k];\n    const push = last\n      ? LAST_PUSH\n      : Math.max(4, Math.min(9, Math.round(dwell * 0.4)));\n    const yesAt = last\n      ? push + 5\n      : push + Math.round((dwell - push) * (k === 0 ? 0.3 : 0.18));\n    const yesLen = last\n      ? 8\n      : Math.max(3, Math.min(6, Math.round(dwell * 0.22)));\n    const { rows, size } = chooseRows(\n      qs[k],\n      m.q[k],\n      m.splits[k],\n      bwEm,\n      measureW,\n      fMax,\n      portrait ? 0.82 : 0.6,\n    );\n    const h = (rows.length * LINE + (rows.length - 1) * ROW_GAP) * size;\n    exchanges.push({ start: at, push, yesAt, yesLen, size, rows, h });\n    at += dwell;\n  }\n\n  let cur = 0;\n  for (let k = 0; k < n; k++) if (t >= exchanges[k].start) cur = k;\n  const e = exchanges[cur];\n  const prev = cur > 0 ? exchanges[cur - 1] : null;\n  const p = interpolate(t, [e.start - 2, e.start + e.push], [0, 1], {\n    ...CLAMP,\n    easing: EASE_PUSH,\n  });\n\n  const cy = H / 2;\n  const gapV = Math.max(e.size, prev?.size ?? 0) * 0.5;\n  const dist = prev ? (prev.h + e.h) / 2 + gapV : e.h + gapV;\n  const winH = prev ? prev.h + (e.h - prev.h) * p : e.h;\n\n  const renderExchange = (x: Exchange, dy: number, reveal: number) => {\n    const F = x.size;\n    const blockW = bwEm * F;\n    const lineBox = LINE * F;\n    const baseOff = (lineBox - (m.asc + m.desc) * F) / 2 + m.asc * F;\n    const blockTop = -(m.cap + 0.24) * F;\n    const blockH = (m.cap + 0.24 + 0.3) * F;\n    const text = (\n      s: string,\n      left: number,\n      baseline: number,\n      color: string,\n      key: string,\n    ) => (\n      <div\n        key={key}\n        style={{\n          position: \"absolute\",\n          left,\n          top: baseline - baseOff,\n          height: lineBox,\n          lineHeight: `${lineBox}px`,\n          fontFamily: unbounded.fontFamily,\n          fontWeight: WGHT,\n          fontSize: F,\n          letterSpacing: `${TRACK}em`,\n          whiteSpace: \"pre\",\n          color,\n        }}\n      >\n        {s}\n      </div>\n    );\n\n    const top = cy + dy - x.h / 2;\n    const out: React.ReactNode[] = [];\n    x.rows.forEach((row, i) => {\n      const base = top + i * (LINE + ROW_GAP) * F + baseOff;\n      const qW = row.w * F;\n      if (!row.yes) {\n        out.push(text(row.text, W / 2 - qW / 2, base, ink, `r${i}`));\n        return;\n      }\n      const alone = row.w === 0;\n      const lineW = alone ? blockW : qW + (GAP * F + blockW) * reveal;\n      const left = W / 2 - lineW / 2;\n      if (!alone) out.push(text(row.text, left, base, ink, `r${i}`));\n      if (reveal <= 0) return;\n      const bLeft = alone ? left : left + qW + GAP * F;\n      const side = (1 - reveal) * 50;\n      const clip = alone\n        ? `inset(0 ${side.toFixed(2)}% 0 ${side.toFixed(2)}%)`\n        : `inset(0 ${((1 - reveal) * 100).toFixed(2)}% 0 0)`;\n      const nudge = alone ? 0 : (1 - reveal) * F * 0.12;\n      out.push(\n        <div\n          key={`b${i}`}\n          style={{\n            position: \"absolute\",\n            left: bLeft - nudge,\n            top: base + blockTop,\n            width: blockW,\n            height: blockH,\n            clipPath: clip,\n          }}\n        >\n          <div\n            style={{\n              position: \"absolute\",\n              inset: 0,\n              background: block,\n              borderRadius: F * 0.08,\n            }}\n          />\n          {text(answer, PAD_X * F, -blockTop, blockInk, \"a\")}\n        </div>,\n      );\n    });\n    return (\n      <div key={x.start} style={{ position: \"absolute\", inset: 0 }}>\n        {out}\n      </div>\n    );\n  };\n\n  const reveal = interpolate(\n    t,\n    [e.start + e.yesAt, e.start + e.yesAt + e.yesLen],\n    [0, 1],\n    { ...CLAMP, easing: EASE_OUT },\n  );\n\n  const nodes: React.ReactNode[] = [];\n  if (prev && p < 1) nodes.push(renderExchange(prev, -dist * p, 1));\n  nodes.push(renderExchange(e, dist * (1 - p), reveal));\n\n  const padTop = Math.max(e.size, prev?.size ?? 0) * 0.08;\n  const padBottom = Math.max(e.size, prev?.size ?? 0) * 0.14;\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          clipPath: `inset(${(cy - winH / 2 - padTop).toFixed(1)}px 0 ${(H - cy - winH / 2 - padBottom).toFixed(1)}px 0)`,\n        }}\n      >\n        {nodes}\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/yes-run.tsx"
    }
  ],
  "type": "registry:component"
}
