{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "roman-edition",
  "title": "Roman Edition",
  "description": "A giant Roman numeral XIV sits on a yellow band under a Launch Week edition header.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/roman-edition/index.tsx",
      "content": "\"use client\";\n\nimport { loadVariableFont } from \"@remotion/google-fonts/Archivo\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst archivo = loadVariableFont(\"normal\", { subsets: [\"latin\"] });\n\nexport interface RomanEditionProps {\n  value?: number;\n  from?: number;\n  eyebrow?: string;\n  tagline?: string;\n  showNumber?: boolean;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#0E4D4A\",\n    ink: \"#F4E9D8\",\n    accent: \"#FF6B4A\",\n    band: \"#FFC93C\",\n    numeral: \"#0E4D4A\",\n  },\n  light: {\n    bg: \"#F4E9D8\",\n    ink: \"#0E4D4A\",\n    accent: \"#FF6B4A\",\n    band: \"#0E4D4A\",\n    numeral: \"#F4E9D8\",\n  },\n} as const;\n\nconst FVS_NUMERAL = '\"wdth\" 125, \"wght\" 500';\nconst FVS_TEXT = '\"wdth\" 125, \"wght\" 420';\n\nconst NUMERALS: [number, string][] = [\n  [1000, \"M\"],\n  [900, \"CM\"],\n  [500, \"D\"],\n  [400, \"CD\"],\n  [100, \"C\"],\n  [90, \"XC\"],\n  [50, \"L\"],\n  [40, \"XL\"],\n  [10, \"X\"],\n  [9, \"IX\"],\n  [5, \"V\"],\n  [4, \"IV\"],\n  [1, \"I\"],\n];\n\nfunction toRoman(n: number): string {\n  let v = Math.max(1, Math.min(3999, Math.round(n)));\n  let out = \"\";\n  for (const [k, s] of NUMERALS) {\n    while (v >= k) {\n      out += s;\n      v -= k;\n    }\n  }\n  return out;\n}\n\nfunction sequence(from: number, to: number): number[] {\n  const a = Math.max(1, Math.round(Math.min(from, to)));\n  const b = Math.max(1, Math.round(to));\n  if (b - a <= 15) {\n    return Array.from({ length: b - a + 1 }, (_, i) => a + i);\n  }\n  const out: number[] = [];\n  for (let v = a; v <= Math.min(b, a + 4); v++) out.push(v);\n  const steps = [5, 10, 50, 100, 500, 1000];\n  const unit = steps.find((u) => (b - a) / u <= 9) ?? 1000;\n  let v = Math.ceil((out[out.length - 1] + 1) / unit) * unit;\n  while (v < b) {\n    out.push(v);\n    v += unit;\n  }\n  out.push(b);\n  return out;\n}\n\nconst TRACK = 0.02;\nconst FONT_PX = 200;\n\nconst START = 16;\nconst SLOW = 8;\nconst FAST = 3.5;\nconst MOVE = 10;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN = Easing.bezier(0.5, 0, 0.75, 0);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n  adv: Record<string, number>;\n  capTop: number;\n  baseline: number;\n}\n\nfunction measure(): Metrics {\n  const probe = document.createElement(\"span\");\n  Object.assign(probe.style, {\n    position: \"absolute\",\n    left: \"-99999px\",\n    top: \"0\",\n    visibility: \"hidden\",\n    whiteSpace: \"pre\",\n    fontFamily: `\"${archivo.fontFamily}\"`,\n    fontVariationSettings: FVS_NUMERAL,\n    fontSize: `${FONT_PX}px`,\n    lineHeight: \"1\",\n  });\n  document.body.appendChild(probe);\n  const adv: Record<string, number> = {};\n  for (const ch of \"IVXLCDM\") {\n    probe.textContent = ch;\n    adv[ch] = probe.getBoundingClientRect().width / FONT_PX + TRACK;\n  }\n  probe.remove();\n  let capTop = 0.72;\n  let baseline = 0.8;\n  const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n  if (ctx) {\n    ctx.font = `500 ${FONT_PX}px \"${archivo.fontFamily}\"`;\n    const box = ctx.measureText(\"IVXLCDM\");\n    const asc = box.fontBoundingBoxAscent / FONT_PX;\n    const desc = box.fontBoundingBoxDescent / FONT_PX;\n    capTop = box.actualBoundingBoxAscent / FONT_PX;\n    baseline = (1 - (asc + desc)) / 2 + asc;\n  }\n  return { adv, capTop, baseline };\n}\n\nfunction useMetrics() {\n  const [metrics, setMetrics] = useState<Metrics | null>(null);\n  const [handle] = useState(() => delayRender(\"roman-edition: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      archivo.waitUntilDone(),\n      document.fonts.load(`500 100px \"${archivo.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setMetrics(measure());\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [handle]);\n  return metrics;\n}\n\ninterface Glyph {\n  key: string;\n  ch: string;\n  x: number;\n}\n\nfunction layout(str: string, adv: Record<string, number>): Glyph[] {\n  const seen: Record<string, number> = {};\n  const chars = Array.from(str);\n  const total = chars.reduce((s, ch) => s + (adv[ch] ?? 0.5), 0) - TRACK;\n  let x = -total / 2;\n  return chars.map((ch) => {\n    const n = seen[ch] ?? 0;\n    seen[ch] = n + 1;\n    const g = { key: `${ch}${n}`, ch, x };\n    x += adv[ch] ?? 0.5;\n    return g;\n  });\n}\n\nexport function RomanEdition({\n  value = 14,\n  from = 1,\n  eyebrow = \"Launch Week\",\n  tagline = \"Five days of new scenes, one every morning.\",\n  showNumber = true,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: RomanEditionProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const spot = accent ?? c.accent;\n  const bg = background ?? c.bg;\n  const m = useMetrics();\n\n  const seq = useMemo(() => sequence(from, value), [from, value]);\n  const romans = useMemo(() => seq.map(toRoman), [seq]);\n  const times = useMemo(() => {\n    const out: number[] = [];\n    let at = START;\n    const n = seq.length;\n    for (let k = 0; k < n; k++) {\n      out.push(at);\n      const p = n > 1 ? k / (n - 1) : 1;\n      const u = Math.abs(p - 0.5) * 2;\n      const gap = k < 3 ? SLOW + 1 : FAST + (SLOW - FAST) * u ** 2.2;\n      at += gap;\n    }\n    return out;\n  }, [seq]);\n\n  if (!m) {\n    return <div style={{ position: \"absolute\", inset: 0, background: bg }} />;\n  }\n\n  const layouts = romans.map((r) => layout(r, m.adv));\n  const widest = Math.max(\n    ...romans.map(\n      (r) => Array.from(r).reduce((s, ch) => s + (m.adv[ch] ?? 0.5), 0) - TRACK,\n    ),\n  );\n  const portrait = H > W * 1.1;\n  const M = Math.min(W, H) * 0.075;\n  const F = Math.min(\n    (W * (portrait ? 0.84 : 0.72)) / widest,\n    (H * (portrait ? 0.2 : 0.34)) / m.capTop,\n  );\n\n  let k = 0;\n  for (let q = 1; q < times.length; q++) if (t >= times[q]) k = q;\n  const lastAt = times[times.length - 1];\n\n  const capPx = m.capTop * F;\n  const bandH = capPx * 1.56;\n  const bandTop = H / 2 - bandH / 2 - (portrait ? 0 : H * 0.02);\n  const baseY = bandTop + bandH / 2 + capPx / 2;\n  const lineTop = baseY - m.baseline * F;\n  const bandP = interpolate(t, [0, 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IN_OUT,\n  });\n  const intro = interpolate(t, [START - 8, START + 8], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const smallSize = portrait ? W * 0.044 : H * 0.042;\n  const tagSize = portrait ? W * 0.06 : H * 0.058;\n  const tagAt = lastAt + 8;\n\n  const glyphStyle = (x: number, y: number, opacity: number) => ({\n    position: \"absolute\" as const,\n    left: W / 2 + x * F,\n    top: lineTop - bandTop + y,\n    fontFamily: archivo.fontFamily,\n    fontVariationSettings: FVS_NUMERAL,\n    fontSize: F,\n    lineHeight: `${F}px`,\n    whiteSpace: \"pre\" as const,\n    color: c.numeral,\n    opacity,\n  });\n\n  const nodes: React.ReactNode[] = [];\n  const cur = layouts[k];\n  if (k === 0) {\n    for (const g of cur) {\n      const y = (1 - intro) * bandH * 0.9;\n      nodes.push(\n        <div key={`c-${g.key}`} style={glyphStyle(g.x, y, 1)}>\n          {g.ch}\n        </div>,\n      );\n    }\n  } else {\n    const prev = layouts[k - 1];\n    const T = times[k];\n    const room = k < times.length - 1 ? times[k + 1] - T : MOVE + 4;\n    const span = Math.min(MOVE, room);\n    const dOut = Math.max(1.5, span * 0.42);\n    const inAt = T + span * 0.34;\n    const pm = interpolate(t, [T, T + span], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IN_OUT,\n    });\n    const pin = interpolate(t, [inAt, T + span], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    const pout = interpolate(t, [T, T + dOut], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IN,\n    });\n    const prevMap = new Map(prev.map((g) => [g.key, g]));\n    const curMap = new Map(cur.map((g) => [g.key, g]));\n    for (const g of cur) {\n      const p = prevMap.get(g.key);\n      if (p) {\n        const x = p.x + (g.x - p.x) * pm;\n        nodes.push(\n          <div key={`c-${g.key}`} style={glyphStyle(x, 0, 1)}>\n            {g.ch}\n          </div>,\n        );\n      } else {\n        const y = (1 - pin) * bandH * 0.7;\n        nodes.push(\n          <div\n            key={`c-${g.key}`}\n            style={glyphStyle(g.x, y, Math.min(1, pin * 1.6))}\n          >\n            {g.ch}\n          </div>,\n        );\n      }\n    }\n    for (const g of prev) {\n      if (curMap.has(g.key)) continue;\n      if (pout >= 1) continue;\n      const y = -pout * bandH * 0.6;\n      nodes.push(\n        <div key={`o-${g.key}`} style={glyphStyle(g.x, y, 1 - pout)}>\n          {g.ch}\n        </div>,\n      );\n    }\n  }\n\n  const arabic = seq[k];\n  const digits = String(Math.round(value)).length;\n  const numLabel = `No. ${String(arabic).padStart(Math.max(2, digits), \"0\")}`;\n  const tagWords = tagline ? tagline.split(\" \") : [];\n  const textBase = {\n    fontFamily: archivo.fontFamily,\n    fontVariationSettings: FVS_TEXT,\n    lineHeight: 1.15,\n    letterSpacing: \"-0.01em\",\n    whiteSpace: \"pre\" as const,\n  };\n\n  return (\n    <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          top: bandTop,\n          width: W,\n          height: bandH,\n          background: c.band,\n          overflow: \"hidden\",\n          clipPath: `inset(0 ${((1 - bandP) * 50).toFixed(3)}% 0 ${((1 - bandP) * 50).toFixed(3)}%)`,\n        }}\n      >\n        {nodes}\n      </div>\n      {eyebrow ? (\n        <div\n          style={{\n            ...textBase,\n            position: \"absolute\",\n            left: M,\n            top: bandTop - smallSize * 1.7,\n            fontSize: smallSize,\n            color: c.ink,\n            opacity: intro,\n            transform: `translateY(${((1 - intro) * smallSize * 0.6).toFixed(2)}px)`,\n          }}\n        >\n          {eyebrow}\n        </div>\n      ) : null}\n      {showNumber ? (\n        <div\n          style={{\n            ...textBase,\n            position: \"absolute\",\n            right: M,\n            top: bandTop - smallSize * 1.7,\n            fontSize: smallSize,\n            fontFeatureSettings: '\"tnum\" 1',\n            color: spot,\n            opacity: intro,\n            transform: `translateY(${((1 - intro) * smallSize * 0.6).toFixed(2)}px)`,\n          }}\n        >\n          {numLabel}\n        </div>\n      ) : null}\n      {tagWords.length > 0 ? (\n        <div\n          style={{\n            ...textBase,\n            position: \"absolute\",\n            left: M,\n            width: portrait ? W - M * 2 : W * 0.62,\n            top: bandTop + bandH + tagSize * 0.7,\n            fontSize: tagSize,\n            whiteSpace: \"normal\",\n            textWrap: \"balance\",\n            color: c.ink,\n          }}\n        >\n          {tagWords.map((w, i) => {\n            const p = interpolate(\n              t,\n              [tagAt + i * 3, tagAt + i * 3 + 16],\n              [0, 1],\n              { ...CLAMP, easing: EASE_OUT },\n            );\n            return (\n              <span key={`${w}-${i}`}>\n                <span\n                  style={{\n                    display: \"inline-block\",\n                    opacity: p,\n                    transform: `translateY(${((1 - p) * tagSize * 0.6).toFixed(2)}px)`,\n                  }}\n                >\n                  {w}\n                </span>\n                {i < tagWords.length - 1 ? \" \" : \"\"}\n              </span>\n            );\n          })}\n        </div>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/roman-edition.tsx"
    }
  ],
  "type": "registry:component"
}
