Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "spotlight-text",
"title": "Spotlight Text",
"description": "A spotlight travels across a dark headline, 'Launch videos, in code.', with a mono eyebrow.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/spotlight-text/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadGeist } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport { type CSSProperties, 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 geist = loadGeist(\"normal\", {\n weights: [\"500\"],\n subsets: [\"latin\"],\n});\nconst geistMono = loadGeistMono(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface SpotlightTextProps {\n /** The headline the light travels across. One line. */\n title?: string;\n /** Tiny mono label above the headline's left edge. Empty to hide. */\n eyebrow?: string;\n /** Faint tint at the rim of the spotlight, and the eyebrow marker. */\n accent?: string;\n /** Playback multiplier. */\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0A\",\n dim: \"#2E2E31\",\n lit: \"#FFFFFF\",\n muted: \"#6E6E73\",\n /** How much accent goes into the spotlight's rim. */\n tint: 0.2,\n washAlpha: 0.05,\n },\n light: {\n bg: \"#FAFAF9\",\n dim: \"#DADAD7\",\n lit: \"#0A0A0A\",\n muted: \"#8E8E92\",\n tint: 0.22,\n washAlpha: 0.035,\n },\n} as const;\n\nconst MAX_SIZE = 128;\nconst FILL = 0.84; // headline width as a share of the frame\nconst TRACK = -0.045;\nconst LINE = 1.2;\nconst PAD_Y = 0.1; // em, so descenders stay inside the clip box\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_GLIDE = Easing.bezier(0.45, 0, 0.4, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst T = {\n inStart: 0,\n inDur: 26,\n glideStart: 14,\n glideEnd: 92,\n widenEnd: 132,\n};\n\nfunction hexToRgb(hex: string): [number, number, number] {\n const h = hex.replace(\"#\", \"\");\n const n = Number.parseInt(\n h.length === 3\n ? h\n .split(\"\")\n .map((ch) => ch + ch)\n .join(\"\")\n : h.slice(0, 6),\n 16,\n );\n return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction mix(a: string, b: string, t: number, alpha = 1) {\n const ca = hexToRgb(a);\n const cb = hexToRgb(b);\n const ch = ca.map((v, i) => Math.round(v + (cb[i] - v) * t));\n return `rgba(${ch[0]},${ch[1]},${ch[2]},${alpha})`;\n}\n\n/** Headline advance width in em at the display weight. */\nfunction useTitleWidth(title: string) {\n const [width, setWidth] = useState<number | null>(null);\n const [handle] = useState(() => delayRender(\"spotlight-text: measuring\"));\n const released = useRef(false);\n\n useEffect(() => {\n let live = true;\n const font = `500 100px \"${geist.fontFamily}\"`;\n Promise.all([geist.waitUntilDone(), document.fonts.load(font)])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n let w = [...title].length * 0.5;\n if (ctx) {\n ctx.font = font;\n w = ctx.measureText(title).width / 100 + TRACK * [...title].length;\n }\n setWidth(w);\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [title, handle]);\n\n return width ?? [...title].length * 0.5;\n}\n\nexport function SpotlightText({\n title = \"Launch videos, in code.\",\n eyebrow = \"remocn 2.0\",\n accent = \"#3B5BFD\",\n speed = 1,\n theme = \"dark\",\n}: SpotlightTextProps) {\n const frame = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const s = Math.min(W / 1280, H / 720);\n\n const em = useTitleWidth(title);\n const fontSize = Math.min(MAX_SIZE * s, (W * FILL) / em);\n // Clip box of the lit layer, in px. Tracking adds trailing space after the\n // last glyph; trim it so the box hugs the ink.\n const boxW = em * fontSize - TRACK * fontSize;\n const boxH = (LINE + PAD_Y * 2) * fontSize;\n const left = (W - boxW) / 2;\n const top = H / 2 - boxH / 2 + 0.04 * H;\n\n // Entrance of the dim line.\n const enter = interpolate(frame, [T.inStart, T.inStart + T.inDur], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n // Spotlight: glide left → right, then ease back to centre while widening.\n const r0 = 1.25 * fontSize;\n const glide = interpolate(frame, [T.glideStart, T.glideEnd], [0, 1], {\n ...CLAMP,\n easing: EASE_GLIDE,\n });\n const widen = interpolate(frame, [T.glideEnd - 6, T.widenEnd], [0, 1], {\n ...CLAMP,\n easing: EASE_IO,\n });\n const glideX = -0.14 * boxW + glide * 0.98 * boxW;\n const x = glideX + (0.5 * boxW - glideX) * widen;\n // A gentle vertical drift while it travels, gone once it widens.\n const drift = Math.sin(glide * Math.PI * 1.5) * 0.14 * fontSize * (1 - widen);\n const y = boxH / 2 + drift;\n const radius = r0 + (0.95 * boxW - r0) * widen;\n const core = 0.3 + (0.66 - 0.3) * widen;\n const rim = core + (1 - core) * 0.5;\n const lightIn = interpolate(\n frame,\n [T.glideStart - 4, T.glideStart + 14],\n [0, 1],\n CLAMP,\n );\n\n const tintRim = mix(c.lit, accent, c.tint, 0.85);\n const gradient = `radial-gradient(circle ${radius}px at ${x}px ${y}px, ${c.lit} 0%, ${c.lit} ${core * 100}%, ${tintRim} ${rim * 100}%, ${mix(c.lit, accent, c.tint, 0)} 100%)`;\n\n // A barely-there wash on the stage under the light.\n const washR = radius * 2.2;\n const washA = c.washAlpha * lightIn * (1 - 0.5 * widen);\n const wash = `radial-gradient(circle ${washR}px at ${left + x}px ${top + y}px, ${mix(c.bg, accent, 0.5, washA)} 0%, ${mix(c.bg, accent, 0.5, 0)} 70%)`;\n\n const eyebrowIn = interpolate(frame, [8, 30], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const textStyle: CSSProperties = {\n fontFamily: geist.fontFamily,\n fontWeight: 500,\n fontSize,\n letterSpacing: `${TRACK}em`,\n lineHeight: LINE,\n padding: `${PAD_Y}em 0`,\n whiteSpace: \"pre\",\n fontKerning: \"normal\",\n width: boxW,\n height: boxH,\n boxSizing: \"border-box\",\n };\n\n return (\n <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n <div style={{ position: \"absolute\", inset: 0, background: wash }} />\n\n {eyebrow ? (\n <div\n style={{\n position: \"absolute\",\n left: left + 0.04 * fontSize,\n top: top - 30 * s,\n display: \"flex\",\n alignItems: \"center\",\n gap: 8 * s,\n fontFamily: geistMono.fontFamily,\n fontWeight: 400,\n fontSize: 13 * s,\n letterSpacing: \"0.02em\",\n lineHeight: 1,\n color: c.muted,\n opacity: eyebrowIn,\n filter: `blur(${(1 - eyebrowIn) * 8 * s}px)`,\n transform: `translateY(${(1 - eyebrowIn) * 10 * s}px)`,\n }}\n >\n <span\n style={{\n width: 5 * s,\n height: 5 * s,\n background: accent,\n display: \"block\",\n }}\n />\n {eyebrow}\n </div>\n ) : null}\n\n <div\n style={{\n position: \"absolute\",\n left,\n top,\n width: boxW,\n height: boxH,\n opacity: enter,\n filter: `blur(${(1 - enter) * 10 * s}px)`,\n transform: `translateY(${(1 - enter) * 18 * s}px)`,\n }}\n >\n <div\n style={{ ...textStyle, position: \"absolute\", inset: 0, color: c.dim }}\n >\n {title}\n </div>\n <div\n style={{\n ...textStyle,\n position: \"absolute\",\n inset: 0,\n color: \"transparent\",\n backgroundImage: gradient,\n backgroundRepeat: \"no-repeat\",\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n opacity: lightIn,\n }}\n >\n {title}\n </div>\n </div>\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/spotlight-text.tsx"
}
],
"type": "registry:component"
}