{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rsvp",
  "title": "Rsvp",
  "description": "\"You're invited.\" with a what/when/where table ending on an RSVP install command.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/rsvp/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Lexend\";\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 lexend = loadFont(\"normal\", {\n  weights: [\"300\", \"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface RsvpField {\n  label: string;\n  value: string;\n}\n\nexport interface RsvpProps {\n  headline?: string;\n  fields?: RsvpField[];\n  rsvpLabel?: string;\n  rsvp?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#E8392B\", ink: \"#FFFFFF\", accent: \"#0A0A0A\" },\n  light: { bg: \"#FFFFFF\", ink: \"#0A0A0A\", accent: \"#E8392B\" },\n} as const;\n\nconst TRACK = -0.035;\nconst ROW_TRACK = -0.012;\nconst LH = 1.04;\nconst ROW_LH = 1.2;\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface Spec {\n  text: string;\n  weight: number;\n}\n\nfunction useWidths(specs: Spec[]) {\n  const key = specs.map((s) => `${s.weight}|${s.text}`).join(\"\\u0001\");\n  const [state, setState] = useState<{\n    key: string;\n    w: Record<string, number>;\n  } | null>(null);\n  const [handle] = useState(() => delayRender(\"rsvp: measuring\"));\n  const released = useRef(false);\n  const ref = useRef(specs);\n  ref.current = specs;\n  useEffect(() => {\n    let live = true;\n    const weights = Array.from(new Set(ref.current.map((s) => s.weight)));\n    Promise.all([\n      lexend.waitUntilDone(),\n      ...weights.map((wt) =>\n        document.fonts.load(`${wt} 100px \"${lexend.fontFamily}\"`),\n      ),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n        const w: Record<string, number> = {};\n        for (const s of ref.current) {\n          const k = `${s.weight}|${s.text}`;\n          if (ctx) {\n            ctx.font = `${s.weight} 100px \"${lexend.fontFamily}\"`;\n            w[k] = ctx.measureText(s.text).width / 100;\n          } else {\n            w[k] = s.text.length * 0.56;\n          }\n        }\n        setState({ key, w });\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.w : null;\n}\n\nfunction greedy(\n  words: string[],\n  adv: (s: string) => number,\n  space: number,\n  maxEm: number,\n) {\n  const lines: string[][] = [];\n  let line: string[] = [];\n  let x = 0;\n  for (const word of words) {\n    const w = adv(word);\n    if (line.length > 0 && x + space + w > maxEm) {\n      lines.push(line);\n      line = [word];\n      x = w;\n    } else {\n      x += (line.length > 0 ? space : 0) + w;\n      line.push(word);\n    }\n  }\n  if (line.length > 0) lines.push(line);\n  return lines;\n}\n\nfunction balanced(\n  words: string[],\n  adv: (s: string) => number,\n  space: number,\n  maxEm: number,\n) {\n  const base = greedy(words, adv, space, maxEm);\n  if (base.length <= 1) return base;\n  let lo = 0;\n  let hi = maxEm;\n  for (let k = 0; k < 24; k++) {\n    const mid = (lo + hi) / 2;\n    if (greedy(words, adv, space, mid).length <= base.length) hi = mid;\n    else lo = mid;\n  }\n  return greedy(words, adv, space, hi);\n}\n\nconst splitWords = (s: string) => s.split(/\\s+/).filter(Boolean);\n\nconst DEFAULT_FIELDS: RsvpField[] = [\n  { label: \"What\", value: \"Your launch film\" },\n  { label: \"When\", value: \"Whenever you’re ready\" },\n  { label: \"Where\", value: \"Your own repo\" },\n  { label: \"Bring\", value: \"The story. We brought the parts.\" },\n];\n\nexport function Rsvp({\n  headline = \"You’re invited.\",\n  fields = DEFAULT_FIELDS,\n  rsvpLabel = \"RSVP\",\n  rsvp = \"npx shadcn add @remocn/whip-pan\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: RsvpProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const Tt = durationInFrames * speed;\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n  const rows = [\n    ...fields.filter((f) => f.label || f.value),\n    ...(rsvp ? [{ label: rsvpLabel, value: rsvp }] : []),\n  ];\n  const headWords = splitWords(headline);\n  const rowWords = rows.map((r) => splitWords(r.value));\n  const w = useWidths([\n    { text: \" \", weight: 500 },\n    { text: \" \", weight: 400 },\n    ...headWords.map((text) => ({ text, weight: 500 })),\n    ...rows.map((r) => ({ text: r.label, weight: 400 })),\n    ...rowWords.flat().map((text) => ({ text, weight: 400 })),\n  ]);\n\n  if (!w) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const headAdv = (s: string) =>\n    (w[`500|${s}`] ?? s.length * 0.56) + TRACK * Array.from(s).length;\n  const rowAdv = (s: string) =>\n    (w[`400|${s}`] ?? s.length * 0.56) + ROW_TRACK * Array.from(s).length;\n  const headSpace = w[\"500| \"] ?? 0.25;\n  const rowSpace = w[\"400| \"] ?? 0.25;\n\n  const portrait = H > W * 1.1;\n  const mx = W * (portrait ? 0.08 : 0.07);\n  const availW = W - mx * 2;\n  const labelEm = Math.max(0, ...rows.map((r) => rowAdv(r.label)));\n\n  let fH = portrait ? W * 0.2 : H * 0.2;\n  let fR = portrait ? W * 0.064 : H * 0.054;\n  const labelH = portrait ? ROW_LH * 0.72 : 0;\n  const build = () => {\n    const headLines = balanced(headWords, headAdv, headSpace, availW / fH);\n    const labelCol = portrait\n      ? 0\n      : Math.max(labelEm * fR + fR * 1.4, availW * 0.2);\n    const valueW = availW - labelCol;\n    const valueLines = rowWords.map((ws) =>\n      balanced(ws, rowAdv, rowSpace, valueW / fR),\n    );\n    const headH = headLines.length * LH * fH;\n    const gapHR = fH * (portrait ? 0.5 : 0.36);\n    const rowGap = fR * (portrait ? 0.9 : 0.62);\n    const rowHs = valueLines.map(\n      (ls) => (labelH + Math.max(1, ls.length) * ROW_LH) * fR,\n    );\n    const rowsH =\n      rowHs.reduce((a, b) => a + b, 0) + rowGap * Math.max(0, rowHs.length - 1);\n    return {\n      headLines,\n      labelCol,\n      valueLines,\n      headH,\n      gapHR,\n      rowGap,\n      rowHs,\n      rowsH,\n      total: headH + gapHR + rowsH,\n    };\n  };\n  let B = build();\n  const maxH = H * (portrait ? 0.76 : 0.82);\n  for (let k = 0; k < 80; k++) {\n    if (B.total <= maxH && B.headLines.length <= (portrait ? 3 : 2)) break;\n    fH *= 0.96;\n    fR *= 0.97;\n    B = build();\n  }\n\n  const top = portrait\n    ? (H - B.total) / 2 - H * 0.02\n    : Math.max(H * 0.09, (H - B.total) / 2 - H * 0.04);\n  const rowsTop = top + B.headH + B.gapHR;\n\n  const n = rows.length;\n  const rowStart = 26;\n  const span = Math.max(n * 10, Math.min(Tt * 0.5, Tt - 70) - rowStart);\n  const rowStep = Math.min(16, span / Math.max(1, n));\n  const rowAt = (k: number) =>\n    rowStart + k * rowStep + (rsvp && k === n - 1 ? 10 : 0);\n  const lastAt = rowAt(n - 1);\n  const focus = rsvp\n    ? interpolate(t, [lastAt + 12, lastAt + 30], [0, 1], {\n        ...CLAMP,\n        easing: EASE_IO,\n      })\n    : 0;\n\n  let wordIndex = 0;\n  const headNodes = B.headLines.map((line, li) => (\n    <div\n      key={`h${li}`}\n      style={{\n        position: \"absolute\",\n        left: mx,\n        top: top + li * LH * fH,\n        height: LH * fH,\n        lineHeight: `${LH * fH}px`,\n        fontSize: fH,\n        fontWeight: 500,\n        whiteSpace: \"pre\",\n        letterSpacing: `${TRACK}em`,\n        color: c.ink,\n      }}\n    >\n      {line.map((word, wi) => {\n        const s = 3 + wordIndex * 4;\n        wordIndex++;\n        const e = interpolate(t, [s, s + 20], [0, 1], {\n          ...CLAMP,\n          easing: EASE_OUT,\n        });\n        return (\n          <span key={`hw${wi}`}>\n            {wi > 0 ? \" \" : \"\"}\n            <span\n              style={{\n                display: \"inline-block\",\n                opacity: e,\n                transform: `translateY(${((1 - e) * fH * 0.3).toFixed(2)}px)`,\n              }}\n            >\n              {word}\n            </span>\n          </span>\n        );\n      })}\n    </div>\n  ));\n\n  let y = rowsTop;\n  const rowNodes = rows.map((row, k) => {\n    const rowTop = y;\n    y += B.rowHs[k] + B.rowGap;\n    const at = rowAt(k);\n    const le = interpolate(t, [at, at + 14], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    const isRsvp = Boolean(rsvp) && k === n - 1;\n    const dim = isRsvp ? 1 : 1 - 0.45 * focus;\n    return (\n      <div\n        key={`r${k}`}\n        style={{\n          position: \"absolute\",\n          left: mx,\n          top: rowTop,\n          width: availW,\n          height: B.rowHs[k],\n          fontSize: fR,\n          lineHeight: `${ROW_LH * fR}px`,\n          letterSpacing: `${ROW_TRACK}em`,\n          whiteSpace: \"pre\",\n          opacity: dim,\n        }}\n      >\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            top: 0,\n            fontSize: portrait ? fR * 0.62 : fR,\n            lineHeight: `${(portrait ? labelH : ROW_LH) * fR}px`,\n            fontWeight: 400,\n            color: hi,\n            opacity: le,\n            transform: `translateY(${((1 - le) * fR * 0.5).toFixed(2)}px)`,\n          }}\n        >\n          {row.label}\n        </div>\n        <div\n          style={{\n            position: \"absolute\",\n            left: B.labelCol,\n            top: labelH * fR,\n            fontWeight: 400,\n            color: isRsvp ? hi : c.ink,\n          }}\n        >\n          {B.valueLines[k].map((line, li) => {\n            const before = B.valueLines[k]\n              .slice(0, li)\n              .reduce((a, l) => a + l.length, 0);\n            return (\n              <div key={`v${li}`}>\n                {line.map((word, wi) => {\n                  const s = at + 5 + (before + wi) * 2;\n                  const e = interpolate(t, [s, s + 16], [0, 1], {\n                    ...CLAMP,\n                    easing: EASE_OUT,\n                  });\n                  return (\n                    <span key={`vw${wi}`}>\n                      {wi > 0 ? \" \" : \"\"}\n                      <span\n                        style={{\n                          display: \"inline-block\",\n                          opacity: e,\n                          transform: `translateY(${((1 - e) * fR * 0.55).toFixed(2)}px)`,\n                        }}\n                      >\n                        {word}\n                      </span>\n                    </span>\n                  );\n                })}\n              </div>\n            );\n          })}\n        </div>\n      </div>\n    );\n  });\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: stage,\n        overflow: \"hidden\",\n        fontFamily: lexend.fontFamily,\n      }}\n    >\n      {headNodes}\n      {rowNodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/rsvp.tsx"
    }
  ],
  "type": "registry:component"
}
