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