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": "focus-pan-text",
"title": "Focus Pan Text",
"description": "Blurred earlier lines stack above while focus pans down to \"You're ready to launch.\" and a toolbar.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/focus-pan-text/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/InterTight\";\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n spring,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround, gshParams } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst inter = loadFont(\"normal\", {\n weights: [\"300\", \"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface FocusPanTextProps {\n lines?: string[];\n accentWord?: string;\n meta?: string;\n accent?: string;\n ink?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n firstHold?: number;\n}\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n kind: \"mist\",\n background: \"#efeeeb\",\n colors: [\"#ffffff\", \"#f5f4f1\", \"#dfe0e6\", \"#c3c8d6\"],\n blur: 0.8,\n warp: 0.3,\n seed: 5,\n grain: 0.16,\n};\n\nconst THEMES = {\n dark: {\n ink: \"#f2f1f6\",\n muted: \"rgba(242,241,246,0.5)\",\n accent: \"#7c90ff\",\n ground: \"europa\" as GshPresetId | undefined,\n groundParams: undefined as Partial<GradientParams> | undefined,\n groundOffset: 6,\n scrim: \"3,5,10\",\n scrimAlpha: 0.5,\n },\n light: {\n ink: \"#141418\",\n muted: \"rgba(20,20,24,0.46)\",\n accent: \"#3B5BFD\",\n ground: undefined as GshPresetId | undefined,\n groundParams: LIGHT_GROUND as Partial<GradientParams> | undefined,\n groundOffset: 3,\n scrim: \"248,247,244\",\n scrimAlpha: 0.4,\n },\n};\n\nconst BEAT = {\n decay: 0.8,\n minHold: 18,\n move: 14,\n payoffMove: 24,\n wordIn: 12,\n wordStagger: 3,\n accent: 20,\n meta: 24,\n hold: 48,\n};\n\nconst TRACK = -0.022;\nconst FONT_PX = 200;\nconst MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst TYPE_IN = Easing.bezier(0.32, 0.72, 0, 1);\nconst COLOR = Easing.bezier(0.83, 0, 0.17, 1);\nconst PUSH = Easing.bezier(0.33, 0, 0.2, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst DEFAULT_LINES = [\n \"The security scan is clean.\",\n \"All 48 checks passed.\",\n \"Your domain is live.\",\n \"You're ready to launch.\",\n];\n\nconst holdOf = (i: number, first: number) =>\n Math.max(BEAT.minHold, Math.round(first * BEAT.decay ** i));\n\nexport const focusPanTextLength = (\n lines: string[] = DEFAULT_LINES,\n firstHold = 30,\n) => {\n let t = 0;\n for (let i = 0; i < lines.length - 1; i++) t += holdOf(i, firstHold);\n return t + BEAT.payoffMove + BEAT.meta + BEAT.hold;\n};\n\nfunction buildMeasure(_version: number): (s: string) => number {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n const cache: Record<string, number> = {};\n return (s: string) => {\n if (cache[s] === undefined) {\n if (!ctx) return s.length * 0.5;\n ctx.font = `400 ${FONT_PX}px \"${inter.fontFamily}\"`;\n cache[s] =\n ctx.measureText(s).width / FONT_PX + TRACK * Array.from(s).length;\n }\n return cache[s];\n };\n}\n\nfunction useMeasure() {\n const [version, setVersion] = useState(0);\n const [handle] = useState(() => delayRender(\"focus-pan-text: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n const bump = () => {\n if (live) setVersion((v) => v + 1);\n };\n document.fonts.addEventListener(\"loadingdone\", bump);\n Promise.all([\n inter.waitUntilDone(),\n document.fonts.load(`400 ${FONT_PX}px \"${inter.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n bump();\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n document.fonts.removeEventListener(\"loadingdone\", bump);\n };\n }, [handle]);\n return useMemo(() => buildMeasure(version), [version]);\n}\n\nfunction Icon({\n size,\n color,\n children,\n}: {\n size: number;\n color: string;\n children: ReactNode;\n}) {\n return (\n <svg\n viewBox=\"0 0 24 24\"\n width={size}\n height={size}\n fill=\"none\"\n stroke={color}\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n style={{ display: \"block\", flexShrink: 0 }}\n aria-hidden\n >\n {children}\n </svg>\n );\n}\n\ninterface Row {\n words: string[];\n line: number;\n first: number;\n}\n\nexport function FocusPanText({\n lines = DEFAULT_LINES,\n accentWord,\n meta = \"Just now\",\n accent,\n ink,\n theme = \"dark\",\n ground,\n groundParams,\n firstHold = 30,\n}: FocusPanTextProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, fps } = useVideoConfig();\n const c = THEMES[theme];\n const inkC = ink ?? c.ink;\n const hi = accent ?? c.accent;\n const preset = ground ?? (groundParams ? undefined : c.ground);\n const gParams = groundParams ?? (ground ? undefined : c.groundParams);\n const bg = gshParams(preset, gParams).background;\n const portrait = H > W * 1.1;\n const u = Math.min(W, H) / 720;\n const m = useMeasure();\n\n const safeLines = lines.length > 0 ? lines : DEFAULT_LINES;\n const last = safeLines.length - 1;\n const widest = m ? Math.max(...safeLines.map((l) => m(l))) : 10;\n const F = portrait ? W * 0.1 : Math.min(H * 0.16, (W * 1.12) / widest);\n const LH = F * 1.3;\n const maxW = portrait ? W * 0.86 : Number.POSITIVE_INFINITY;\n\n const rows = useMemo(() => {\n if (!m) return [] as Row[];\n const out: Row[] = [];\n safeLines.forEach((ln, li) => {\n const words = ln.split(/\\s+/).filter(Boolean);\n let cur: string[] = [];\n let first = 0;\n words.forEach((w, wi) => {\n const next = [...cur, w].join(\" \");\n if (cur.length > 0 && m(next) * F > maxW) {\n out.push({ words: cur, line: li, first });\n cur = [w];\n first = wi;\n } else {\n cur.push(w);\n }\n });\n if (cur.length) out.push({ words: cur, line: li, first });\n });\n return out;\n }, [m, safeLines, F, maxW]);\n\n const lineCenter = (li: number) => {\n const idx = rows\n .map((r, i) => (r.line === li ? i : -1))\n .filter((i) => i >= 0);\n if (!idx.length) return li;\n return (idx[0] + idx[idx.length - 1]) / 2;\n };\n\n const moves = useMemo(() => {\n const out: { at: number; len: number; line: number }[] = [];\n let t = 0;\n for (let i = 1; i <= last; i++) {\n t += holdOf(i - 1, firstHold);\n out.push({\n at: t,\n len: i === last ? BEAT.payoffMove : BEAT.move,\n line: i,\n });\n }\n return out;\n }, [last, firstHold]);\n const payoffAt = moves.length ? moves[moves.length - 1].at : 0;\n\n if (!m || rows.length === 0) {\n return <AbsoluteFill style={{ background: bg }} />;\n }\n\n const focusAt = (t: number) => {\n let f = lineCenter(0);\n for (const mv of moves) {\n const from = f;\n const to = lineCenter(mv.line) + (mv.line === last ? 0.24 : 0);\n let p: number;\n if (mv.line === last) {\n p = spring({\n frame: t - mv.at,\n fps,\n config: { mass: 1, damping: 26, stiffness: 120 },\n durationInFrames: mv.len,\n });\n } else {\n p = MOVE(Math.min(1, Math.max(0, (t - mv.at) / mv.len)));\n }\n f = from + (to - from) * p;\n }\n return f;\n };\n const f = focusAt(frame);\n const vel = Math.abs(f - focusAt(frame - 1));\n const motionBlur = Math.min(4 * u, vel * 9 * u);\n\n const settle = interpolate(frame, [payoffAt, payoffAt + 40], [0, 1], {\n ...CLAMP,\n easing: MOVE,\n });\n const push = interpolate(\n frame,\n [0, payoffAt + BEAT.payoffMove + BEAT.meta + BEAT.hold],\n [0, 1],\n { ...CLAMP, easing: PUSH },\n );\n const rx = 14 - 6 * settle;\n const ry = 16 - 7 * settle;\n const rz = -2.4 + 1.2 * settle;\n const panX = -(f / Math.max(1, rows.length - 1)) * F * 0.28;\n const hinge = W * (portrait ? 0.1 : 0.085);\n const scale = 1 + 0.045 * push;\n\n const payoffWords = safeLines[last].split(/\\s+/).filter(Boolean);\n const accentIdx = (() => {\n if (accentWord) {\n const i = payoffWords.findIndex((w) =>\n w.toLowerCase().startsWith(accentWord.toLowerCase()),\n );\n if (i >= 0) return i;\n }\n return payoffWords.length - 1;\n })();\n const colorHit = interpolate(\n frame,\n [payoffAt + BEAT.accent, payoffAt + BEAT.accent + 10],\n [0, 1],\n { ...CLAMP, easing: COLOR },\n );\n const accentPunch = spring({\n frame: frame - payoffAt - BEAT.accent,\n fps,\n config: { mass: 0.5, damping: 12, stiffness: 200 },\n });\n const metaIn = spring({\n frame: frame - payoffAt - BEAT.meta,\n fps,\n config: { mass: 0.8, damping: 18, stiffness: 160 },\n });\n\n const mix = (a: string, b: string, t: number) =>\n t <= 0 ? a : t >= 1 ? b : `color-mix(in oklab, ${b} ${t * 100}%, ${a})`;\n\n const lastRowIdx = rows.length - 1;\n const metaSize = F * 0.44;\n\n const renderPlane = (key: string) => (\n <AbsoluteFill\n key={key}\n style={{ perspective: `${(portrait ? 1500 : 1100) * u}px` }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n transformStyle: \"preserve-3d\",\n transformOrigin: `${hinge}px 50%`,\n transform: `scale(${scale}) rotateZ(${rz}deg) rotateY(${ry}deg) rotateX(${rx}deg)`,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: hinge + panX,\n top: H * 0.5 - (f + 0.5) * LH,\n fontFamily: inter.fontFamily,\n fontWeight: 400,\n fontSize: F,\n lineHeight: `${LH}px`,\n letterSpacing: `${TRACK}em`,\n color: inkC,\n whiteSpace: \"nowrap\",\n }}\n >\n {rows.map((r, ri) => {\n const isPayoff = r.line === last;\n const dist = Math.abs(ri - f);\n const fade = 1 - 0.3 * Math.min(1, Math.max(0, dist - 0.6) / 2);\n return (\n <div\n key={`${r.line}-${r.first}`}\n style={{ height: LH, opacity: fade }}\n >\n {r.words.map((w, wi) => {\n const gi = r.first + wi;\n const space = wi < r.words.length - 1 ? \" \" : \"\";\n if (!isPayoff) {\n return (\n <span key={`${gi}-${w}`}>\n {w}\n {space}\n </span>\n );\n }\n const start = payoffAt + gi * BEAT.wordStagger;\n const p = TYPE_IN(\n Math.min(1, Math.max(0, (frame - start) / BEAT.wordIn)),\n );\n const isAccent = gi === accentIdx;\n const punch = isAccent\n ? 1 + 0.05 * Math.sin(Math.min(1, accentPunch) * Math.PI)\n : 1;\n return (\n <span key={`${gi}-${w}`}>\n <span\n style={{\n display: \"inline-block\",\n opacity: p,\n transform: `translateY(${(1 - p) * F * 0.42}px) scale(${punch})`,\n transformOrigin: \"50% 80%\",\n filter:\n p < 1 ? `blur(${(1 - p) * 6 * u}px)` : undefined,\n color: isAccent ? mix(inkC, hi, colorHit) : inkC,\n }}\n >\n {w}\n </span>\n {space}\n </span>\n );\n })}\n </div>\n );\n })}\n <div\n style={{\n display: \"flex\",\n alignItems: \"center\",\n gap: metaSize * 0.9,\n marginTop: LH * 0.12,\n fontSize: metaSize,\n lineHeight: 1,\n letterSpacing: \"-0.005em\",\n color: c.muted,\n opacity: Math.min(1, metaIn * 1.4) * (lastRowIdx >= 0 ? 1 : 0),\n transform: `translateY(${(1 - metaIn) * metaSize * 0.9}px)`,\n }}\n >\n <span>{meta}</span>\n <Icon size={metaSize * 1.05} color={c.muted}>\n <rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2.5\" />\n <path d=\"M16 8V6.5A2.5 2.5 0 0 0 13.5 4h-7A2.5 2.5 0 0 0 4 6.5v7A2.5 2.5 0 0 0 6.5 16H8\" />\n </Icon>\n <Icon size={metaSize * 1.05} color={c.muted}>\n <path d=\"M7 11v9H4.5A1.5 1.5 0 0 1 3 18.5v-6A1.5 1.5 0 0 1 4.5 11H7Z\" />\n <path d=\"M7 11l3.6-7.2A2 2 0 0 1 14.4 5l-.6 4h5a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.6 20H7\" />\n </Icon>\n <Icon size={metaSize * 1.05} color={c.muted}>\n <circle cx=\"5\" cy=\"12\" r=\"0.6\" />\n <circle cx=\"12\" cy=\"12\" r=\"0.6\" />\n <circle cx=\"19\" cy=\"12\" r=\"0.6\" />\n </Icon>\n </div>\n </div>\n </div>\n </AbsoluteFill>\n );\n\n const band = portrait ? [36, 44, 56, 64] : [28, 40, 60, 72];\n const sharpMask = `linear-gradient(178deg, transparent ${band[0]}%, #000 ${band[1]}%, #000 ${band[2]}%, transparent ${band[3]}%)`;\n const softMask = `linear-gradient(178deg, rgba(0,0,0,0.45) 0%, #000 ${band[0]}%, transparent ${band[1]}%, transparent ${band[2]}%, #000 ${band[3]}%, rgba(0,0,0,0.45) 100%)`;\n const vBlur = motionBlur > 0.1 ? `blur(${motionBlur}px)` : \"\";\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n <GshGround\n preset={preset}\n params={gParams}\n timeOffset={c.groundOffset}\n timeScale={0.5}\n />\n <AbsoluteFill\n style={{\n background: `radial-gradient(${portrait ? \"95% 55%\" : \"75% 70%\"} at 42% 50%, rgba(${c.scrim},${c.scrimAlpha}) 0%, rgba(${c.scrim},0) 100%)`,\n }}\n />\n <AbsoluteFill\n style={{\n filter: `blur(${7 * u + motionBlur}px)`,\n WebkitMaskImage: softMask,\n maskImage: softMask,\n }}\n >\n {renderPlane(\"soft\")}\n </AbsoluteFill>\n <AbsoluteFill\n style={{\n filter: vBlur || undefined,\n WebkitMaskImage: sharpMask,\n maskImage: sharpMask,\n }}\n >\n {renderPlane(\"sharp\")}\n </AbsoluteFill>\n </AbsoluteFill>\n );\n}\n\nexport default FocusPanText;\n",
"type": "registry:component",
"target": "components/remocn/focus-pan-text.tsx"
}
],
"type": "registry:component"
}