{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tldr-on-top",
  "title": "Tldr on Top",
  "description": "A TL;DR summary sits on top of a long body paragraph that fades off.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/tldr-on-top/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Rubik\";\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 rubik = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface TldrOnTopProps {\n  text?: string;\n  label?: string;\n  lines?: string[];\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#2A1033\", ink: \"#FFFFFF\", accent: \"#7CC4FF\" },\n  light: { bg: \"#F3EEF5\", ink: \"#2A1033\", accent: \"#2B7BD6\" },\n} as const;\n\nconst DEFAULT_TEXT =\n  \"Last spring we had a launch on Thursday and no video. The timeline editor crashed twice, every export took forty minutes, and each copy change meant opening the project, finding the layer and rendering the whole thing again. So we tried something else: we wrote the video the way we write the product. Every scene became a React component, with props for its words and its colors. The brand moved into one config file, so a new color reached every shot at once. A typo turned into a one-line commit. Transitions became functions you could read, review and reuse. The film now lives in the same repo as the code, gets reviewed in pull requests like everything else, and renders on the laptop it was written on. You install a scene with one command, change its words, and every file is yours to keep. That’s the whole story, more or less, and it took us a lot longer to tell than it will take you to try.\";\n\nconst DEFAULT_LINES = [\n  \"Every scene is a component.\",\n  \"Your brand is one file.\",\n  \"It renders on your laptop.\",\n];\n\nconst WGHT = 500;\nconst TRACK = -0.03;\nconst LH = 1.08;\nconst WALL_LH = 1.42;\nconst LABEL = 0.4;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ntype Metrics = Record<string, number>;\n\nfunction measureAll(texts: string[], wall: string): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"tldr-on-top: no 2d context\");\n  ctx.font = `${WGHT} 100px \"${rubik.fontFamily}\"`;\n  const w: Metrics = {};\n  for (const s of texts) {\n    w[s] = ctx.measureText(s).width / 100 + TRACK * Array.from(s).length;\n  }\n  ctx.font = `400 100px \"${rubik.fontFamily}\"`;\n  w[\"\\u0002wall\"] = ctx.measureText(wall).width / 100;\n  return w;\n}\n\nfunction useMetrics(texts: string[], wall: string) {\n  const key = `${texts.join(\"\\u0001\")}\\u0003${wall}`;\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"tldr-on-top: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      rubik.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${rubik.fontFamily}\"`),\n      document.fonts.load(`400 100px \"${rubik.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        const [head, body] = key.split(\"\\u0003\");\n        setState({ key, m: measureAll(head.split(\"\\u0001\"), body) });\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\nfunction splitTwo(text: string, m: Metrics): string[] {\n  const words = text.split(\" \").filter(Boolean);\n  if (words.length < 2) return [text];\n  let best: string[] = [text];\n  let bestW = Number.POSITIVE_INFINITY;\n  for (let cut = 1; cut < words.length; cut++) {\n    const a = words.slice(0, cut).join(\" \");\n    const b = words.slice(cut).join(\" \");\n    const w = Math.max(m[a], m[b]);\n    if (w < bestW) {\n      bestW = w;\n      best = [a, b];\n    }\n  }\n  return best;\n}\n\nfunction prefixes(text: string): string[] {\n  const words = text.split(\" \").filter(Boolean);\n  const out: string[] = [];\n  for (let i = 1; i <= words.length; i++) {\n    out.push(words.slice(0, i).join(\" \"));\n    out.push(words.slice(i).join(\" \"));\n  }\n  return out;\n}\n\nexport function TldrOnTop({\n  text = DEFAULT_TEXT,\n  label = \"TL;DR\",\n  lines = DEFAULT_LINES,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: TldrOnTopProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n  const list = lines.length > 0 ? lines : DEFAULT_LINES;\n  const m = useMetrics([label, ...list.flatMap(prefixes)], text);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const portrait = H > W * 1.1;\n  const mX = W * (portrait ? 0.08 : 0.065);\n  const mY = H * (portrait ? 0.07 : 0.09);\n  const colW = W - mX * 2;\n\n  let F = 0;\n  let blocks: string[][] = [];\n  for (const L of [1, 2]) {\n    const b = list.map((s) => (L === 1 ? [s] : splitTwo(s, m)));\n    const widest = Math.max(0.1, ...b.flat().map((r) => m[r]));\n    const rows = b.reduce((a, x) => a + x.length, 0);\n    const size = Math.min(\n      H * (portrait ? 0.068 : 0.112),\n      (colW * 0.98) / widest,\n      (H * 0.66) / (rows * LH + LABEL * 1.6 + 0.3),\n    );\n    if (size > F * 1.12) {\n      F = size;\n      blocks = b;\n    }\n  }\n\n  const availWall = H - mY * 2;\n  const wallUnits = m[\"\\u0002wall\"] * 1.08;\n  const s = Math.min(\n    H * (portrait ? 0.03 : 0.044),\n    Math.max(\n      H * (portrait ? 0.016 : 0.024),\n      Math.sqrt((availWall * colW) / (wallUnits * WALL_LH)),\n    ),\n  );\n  const wallRowH = s * WALL_LH;\n\n  const labelS = F * LABEL;\n  const heights = [\n    labelS * 1.6,\n    ...blocks.map((b, i) => b.length * F * LH + (i === 0 ? F * 0.06 : 0)),\n  ];\n  const headGap = F * 0.5;\n\n  const span = durationInFrames * speed;\n  const READ = 34;\n  const STEP = Math.min(30, Math.max(18, (span - READ - 110) / list.length));\n  const insertAt = (k: number) => READ + k * STEP;\n  const OPEN = 18;\n  const opens = heights.map((_, k) =>\n    interpolate(t, [insertAt(k), insertAt(k) + OPEN], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IN_OUT,\n    }),\n  );\n  const headTotal = heights.reduce((a, h, k) => a + h * opens[k], 0);\n  const gapNow = headGap * opens[0];\n  const restTop = mY + heights.reduce((a, h) => a + h, 0) + headGap;\n  const sliverTop = Math.min(H - wallRowH * 3.4, restTop + H * 0.12);\n  const pushStart = insertAt(heights.length - 1) + OPEN - 4;\n  const push = interpolate(t, [pushStart, pushStart + 26], [0, 1], {\n    ...CLAMP,\n    easing: Easing.bezier(0.5, 0, 0.2, 1),\n  });\n  const wallTop =\n    mY + headTotal + gapNow + Math.max(0, sliverTop - restTop) * push;\n\n  const wallIn = interpolate(t, [0, 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const dim = interpolate(\n    headTotal / heights.reduce((a, h) => a + h, 0),\n    [0, 1],\n    [0.86, 0.42],\n  );\n\n  const nodes: React.ReactNode[] = [];\n  let y = mY;\n  for (let k = 0; k < heights.length; k++) {\n    const h = heights[k];\n    const open = opens[k];\n    if (open <= 0) {\n      continue;\n    }\n    const reveal = interpolate(\n      t,\n      [insertAt(k) + 8, insertAt(k) + OPEN + 8],\n      [0, 1],\n      { ...CLAMP, easing: EASE_OUT },\n    );\n    const content =\n      k === 0 ? (\n        <div\n          style={{\n            fontFamily: rubik.fontFamily,\n            fontWeight: WGHT,\n            fontSize: labelS,\n            lineHeight: `${labelS * 1.2}px`,\n            letterSpacing: \"0.01em\",\n            color: hi,\n            whiteSpace: \"pre\",\n          }}\n        >\n          {label}\n        </div>\n      ) : (\n        blocks[k - 1].map((r) => (\n          <div\n            key={r}\n            style={{\n              height: F * LH,\n              fontFamily: rubik.fontFamily,\n              fontWeight: WGHT,\n              fontSize: F,\n              lineHeight: `${F * LH}px`,\n              letterSpacing: `${TRACK}em`,\n              color: c.ink,\n              whiteSpace: \"pre\",\n            }}\n          >\n            {r}\n          </div>\n        ))\n      );\n    nodes.push(\n      <div\n        key={`h-${k}`}\n        style={{\n          position: \"absolute\",\n          left: mX - F * 0.1,\n          top: y,\n          width: colW + F * 0.2,\n          height: h * open + F * 0.2,\n          overflow: \"hidden\",\n          paddingLeft: F * 0.1,\n        }}\n      >\n        <div\n          style={{\n            paddingTop: k === 0 ? 0 : F * 0.06,\n            opacity: reveal,\n            transform: `translateY(${((1 - reveal) * -h * 0.35).toFixed(2)}px)`,\n          }}\n        >\n          {content}\n        </div>\n      </div>,\n    );\n    y += h * open;\n  }\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: mX,\n          top: wallTop,\n          width: colW,\n          fontFamily: rubik.fontFamily,\n          fontWeight: 400,\n          fontSize: s,\n          lineHeight: `${wallRowH}px`,\n          letterSpacing: \"-0.005em\",\n          color: c.ink,\n          opacity: wallIn * dim,\n          transform: `translateY(${((1 - wallIn) * s).toFixed(2)}px)`,\n          textWrap: \"pretty\",\n        }}\n      >\n        {text}\n      </div>\n      {nodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/tldr-on-top.tsx"
    }
  ],
  "type": "registry:component"
}
