{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "title-sweep",
  "title": "Title Sweep",
  "description": "An end title lit by a gradient that travels through the letters, cuts in the dark, and a second title takes over",
  "dependencies": [
    "remotion",
    "@remotion/google-fonts"
  ],
  "registryDependencies": [
    "https://snapcn.dev/r/snap-cn-ui.json"
  ],
  "files": [
    {
      "path": "registry/snap-cn/title-sweep/index.tsx",
      "content": "// Title Sweep · snapcn — https://snapcn.dev/docs/text/title-sweep\n\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Inter\";\nimport { useEffect, useId, useMemo, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  getRemotionEnvironment,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport { resolveFont } from \"@/lib/snap-cn-ui\";\nimport { DEFAULT_STOPS, SWEEP_FIRST, SWEEP_LAST, type SweepStop } from \"./data\";\n\n/**\n * Title Sweep: a centred title lit by a warm gradient that travels across it.\n * The type never fades. It arrives and leaves because the gradient's dark ends\n * pass over it, so a title goes dark from one side and the next one is cut in\n * while the frame is black. The whole shot pulls back on one slow clock.\n *\n * The defaults are measured off a 1920x1080 reference at 30fps. The sweep is one\n * rigid gradient moved by a measured table: fast at both ends, slow through the\n * pale band.\n */\n\nconst { fontFamily: INTER } = loadFont(\"normal\", {\n  weights: [\"300\", \"400\", \"500\", \"600\", \"700\", \"800\"],\n  subsets: [\"latin\"],\n});\n\nconst STAGE_W = 1920;\nconst STAGE_H = 1080;\n/** Widest a title may get, as a fraction of the stage. */\nconst MAX_LINE = 0.9;\n/** A title longer than this many em stretches the sweep so it still crosses it. */\nconst REF_LINE = 7.6;\n/** Frames between one title's cut and the next. */\nexport const TITLE_FRAMES = 36;\n/** Scale lost per frame by the pull-back. */\nconst PULL_BACK = 0.00119;\n/** The text baseline sits this far below the stage centre, em. */\nconst BASELINE = 0.267;\n\nexport interface TitleSweepProps {\n  /** Shown in order, each cut in on black. One title is fine. */\n  titles?: string[];\n  /** A family from `fonts.ts`, or a CSS family you have loaded yourself. */\n  fontFamily?: string;\n  /** Type size, px on a 1920 stage. Long copy shrinks from here to fit. */\n  fontSize?: number;\n  fontWeight?: number;\n  /** Letter spacing, em. */\n  tracking?: number;\n  /** Extra space between words, em. */\n  wordSpacing?: number;\n  /** Horizontal offset per title, px on a 1920 stage. */\n  nudge?: number[];\n  /** Size multiplier per title, for a line set a touch larger than the last. */\n  titleScale?: number[];\n  /** The gradient, in em from its centre. Start and end it on `background`. */\n  stops?: SweepStop[];\n  background?: string;\n  speed?: number;\n}\n\n/** Piecewise-linear lookup in a per-frame table, held at the ends. */\nexport const sample = (table: readonly number[], at: number) => {\n  const i = Math.min(Math.max(Math.floor(at), 0), table.length - 1);\n  const from = table[i] ?? 0;\n  const to = table[i + 1] ?? from;\n  return from + (to - from) * Math.min(1, Math.max(0, at - i));\n};\n\n/** Which title is on screen at `f`, and how long it has been up. */\nexport const titleAt = (f: number, count: number) => {\n  const index = Math.min(\n    Math.floor(Math.max(0, f) / TITLE_FRAMES),\n    Math.max(0, count - 1),\n  );\n  return { index, age: Math.max(0, f) - index * TITLE_FRAMES };\n};\n\n/** The last of several titles holds warm; any other title is swept off. */\nexport const sweepFor = (index: number, count: number) =>\n  count > 1 && index === count - 1 ? SWEEP_LAST : SWEEP_FIRST;\n\n/** Scale of the slow pull-back at `f`. */\nexport const pullBack = (f: number) => Math.max(0.5, 1 - PULL_BACK * f);\n\n/** Scale that keeps a line of `lineWidth` on a stage of `stageWidth`. */\nexport const fitLine = (lineWidth: number, stageWidth: number) =>\n  Math.min(1, (MAX_LINE * stageWidth) / Math.max(1, lineWidth));\n\nexport const TitleSweep = ({\n  titles = [\"snapcn Pro\", \"snapcn.dev\"],\n  fontFamily = \"Inter\",\n  fontSize = 110.96,\n  fontWeight = 500,\n  tracking = -0.0165,\n  wordSpacing = -0.0769,\n  nudge,\n  titleScale,\n  stops = DEFAULT_STOPS,\n  background = \"#000000\",\n  speed = 1,\n}: TitleSweepProps) => {\n  const f = useCurrentFrame() * speed;\n  const { width, height } = useVideoConfig();\n  const id = useId().replace(/:/g, \"\");\n  const family = resolveFont(fontFamily) ?? INTER;\n\n  // A width measured before the face lands is a width for the fallback, so the\n  // fit waits on it; a render holds its first frame until that has re-rendered.\n  const [fontTick, setFontTick] = useState(0);\n  const [handle] = useState(() =>\n    getRemotionEnvironment().isRendering\n      ? delayRender(\"title-sweep: loading the face\")\n      : null,\n  );\n  const fontSpec = `${fontWeight} 100px ${family}`;\n  useEffect(() => {\n    let alive = true;\n    document.fonts\n      .load(fontSpec)\n      .catch(() => [])\n      .then(() => {\n        if (alive) setFontTick((n) => n + 1);\n      });\n    return () => {\n      alive = false;\n    };\n  }, [fontSpec]);\n  useEffect(() => {\n    if (fontTick > 0 && handle != null) continueRender(handle);\n  }, [fontTick, handle]);\n\n  const { index, age } = titleAt(f, titles.length);\n  const text = titles[index] ?? \"\";\n\n  // Advance width in em, tracking and word spacing included.\n  const lineEm = useMemo(() => {\n    void fontTick;\n    const ctx =\n      typeof document === \"undefined\"\n        ? null\n        : document.createElement(\"canvas\").getContext(\"2d\");\n    if (!ctx) return text.length * 0.55;\n    ctx.font = fontSpec;\n    const spaces = text.split(\" \").length - 1;\n    return (\n      ctx.measureText(text).width / 100 +\n      text.length * tracking +\n      spaces * wordSpacing\n    );\n  }, [fontTick, fontSpec, text, tracking, wordSpacing]);\n\n  const fit = fitLine(lineEm * fontSize, STAGE_W);\n  const size = fontSize * fit * (titleScale?.[index] ?? 1);\n  const reach = Math.max(1, lineEm / REF_LINE) * size;\n  const cx = STAGE_W / 2 + (nudge?.[index] ?? 0);\n  const centre =\n    STAGE_W / 2 + sample(sweepFor(index, titles.length), age) * reach;\n  const first = stops[0]?.at ?? 0;\n  const span = (stops[stops.length - 1]?.at ?? 1) - first || 1;\n  const zoom = pullBack(f);\n  const paint = `${id}sweep`;\n\n  return (\n    <AbsoluteFill style={{ background }}>\n      <svg\n        viewBox={`0 0 ${STAGE_W} ${STAGE_H}`}\n        width={width}\n        height={height}\n        style={{ position: \"absolute\", inset: 0, overflow: \"hidden\" }}\n      >\n        <defs>\n          <linearGradient\n            id={paint}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={centre + first * reach}\n            x2={centre + (first + span) * reach}\n            y1={0}\n            y2={0}\n          >\n            {stops.map((s) => (\n              <stop\n                key={s.at}\n                offset={(s.at - first) / span}\n                stopColor={s.color}\n              />\n            ))}\n          </linearGradient>\n        </defs>\n        <g transform={`translate(960 540) scale(${zoom}) translate(-960 -540)`}>\n          <text\n            x={cx}\n            y={STAGE_H / 2 + BASELINE * size}\n            textAnchor=\"middle\"\n            fill={`url(#${paint})`}\n            style={{\n              fontFamily: family,\n              fontWeight,\n              fontSize: size,\n              letterSpacing: `${tracking}em`,\n              wordSpacing: `${wordSpacing}em`,\n              textRendering: \"geometricPrecision\",\n            }}\n          >\n            {text}\n          </text>\n        </g>\n      </svg>\n    </AbsoluteFill>\n  );\n};\n\nexport default TitleSweep;\n",
      "type": "registry:component",
      "target": "components/snap-cn/title-sweep/index.tsx"
    },
    {
      "path": "registry/snap-cn/title-sweep/data.ts",
      "content": "// Title Sweep · snapcn — https://snapcn.dev/docs/text/title-sweep\nexport interface SweepStop {\n  /** Position in em from the gradient's centre. Positive leads the sweep. */\n  at: number;\n  /** A concrete colour: this paints in a render. */\n  color: string;\n}\n\n/** Measured off the reference: black, deep red, orange, a pale band, and back. */\nexport const DEFAULT_STOPS: SweepStop[] = [\n  { at: -17.52, color: \"#000000\" },\n  { at: -16.727, color: \"#030200\" },\n  { at: -15.934, color: \"#0d0600\" },\n  { at: -15.141, color: \"#160a00\" },\n  { at: -14.348, color: \"#210c01\" },\n  { at: -13.482, color: \"#2d1001\" },\n  { at: -12.689, color: \"#431502\" },\n  { at: -11.896, color: \"#581902\" },\n  { at: -11.103, color: \"#631d08\" },\n  { at: -10.31, color: \"#88300f\" },\n  { at: -9.517, color: \"#9e3f18\" },\n  { at: -8.724, color: \"#ce5c22\" },\n  { at: -7.931, color: \"#d86629\" },\n  { at: -7.066, color: \"#eb7535\" },\n  { at: -6.273, color: \"#e3793d\" },\n  { at: -5.479, color: \"#db7f47\" },\n  { at: -4.686, color: \"#e6935b\" },\n  { at: -3.893, color: \"#f0a771\" },\n  { at: -3.1, color: \"#f4b784\" },\n  { at: -2.307, color: \"#f1bd8d\" },\n  { at: -1.514, color: \"#eebd8f\" },\n  { at: -0.721, color: \"#e3ae7f\" },\n  { at: 0.144, color: \"#e4a471\" },\n  { at: 0.937, color: \"#ef9c62\" },\n  { at: 1.73, color: \"#eb8c4f\" },\n  { at: 2.523, color: \"#e77f42\" },\n  { at: 3.317, color: \"#e37537\" },\n  { at: 4.11, color: \"#dc6d31\" },\n  { at: 4.903, color: \"#d5652b\" },\n  { at: 5.696, color: \"#d16127\" },\n  { at: 6.489, color: \"#af4c1e\" },\n  { at: 7.354, color: \"#943917\" },\n  { at: 8.147, color: \"#7a2810\" },\n  { at: 8.94, color: \"#671e09\" },\n  { at: 9.733, color: \"#561905\" },\n  { at: 10.526, color: \"#461604\" },\n  { at: 11.319, color: \"#3d1404\" },\n  { at: 12.112, color: \"#2a0f02\" },\n  { at: 12.906, color: \"#1f0d01\" },\n  { at: 13.771, color: \"#130901\" },\n  { at: 14.564, color: \"#0d0601\" },\n  { at: 15.357, color: \"#070400\" },\n  { at: 16.15, color: \"#030100\" },\n  { at: 16.943, color: \"#000000\" },\n];\n\n/** Gradient centre per frame of a title, in em from the stage centre. Swept off. */\nexport const SWEEP_FIRST = [\n  -6.625, -6.007, -5.192, -4.403, -3.78, -3.342, -2.969, -2.554, -2.033, -1.439,\n  -0.862, -0.383, -0.01, 0.344, 0.662, 0.895, 1.061, 1.148, 1.198, 1.326, 1.55,\n  1.781, 2.079, 2.506, 3.078, 3.821, 4.705, 5.657, 6.652, 7.781, 9.099, 10.546,\n  12.024, 13.444, 14.647, 15.396,\n];\n\n/** The same for the last of several titles, which never leaves. */\nexport const SWEEP_LAST = [\n  -17.907, -17.152, -16.058, -14.785, -13.36, -11.904, -10.494, -9.072, -7.668,\n  -6.398, -5.281, -4.343, -3.632, -3.026, -2.412, -1.792, -1.193, -0.646,\n  -0.196, 0.192, 0.518, 0.747, 0.918, 1.008, 1.048, 1.148, 1.359, 1.621, 1.879,\n  2.148, 2.495, 2.889, 3.31, 3.745, 4.168, 4.589, 5.014, 5.441, 5.859, 6.193,\n];\n",
      "type": "registry:component",
      "target": "components/snap-cn/title-sweep/data.ts"
    }
  ],
  "docs": "Docs and props: https://snapcn.dev/docs/text/title-sweep?ref=cli — 76 frames at 30fps. — 82 Pro components too — charts, launch scenes, device shots: https://snapcn.dev/docs/pricing?ref=cli-docs",
  "type": "registry:component"
}
