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": "macro-letter-pan",
"title": "Macro Letter Pan",
"description": "The camera pans in macro across letters to land the phrase \"Ready to launch.\".",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/macro-letter-pan/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Geist\";\nimport { 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 geist = loadFont(\"normal\", {\n weights: [\"300\", \"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface MacroLetterPanProps {\n line?: string;\n word?: string;\n accent?: string;\n ink?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n firstShot?: number;\n maxShots?: number;\n}\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n kind: \"mist\",\n background: \"#e9e8e4\",\n colors: [\"#ffffff\", \"#f6f5f2\", \"#d8d9df\", \"#b9bdc9\"],\n blur: 0.75,\n warp: 0.35,\n seed: 11,\n grain: 0.18,\n};\n\nconst THEMES = {\n dark: {\n ink: \"#f3f2f7\",\n muted: \"rgba(243,242,247,0.46)\",\n accent: \"#6f86ff\",\n ground: \"nightfold\" as GshPresetId | undefined,\n groundParams: undefined as Partial<GradientParams> | undefined,\n groundOffset: 4,\n scrim: \"5,4,12\",\n scrimAlpha: 0.5,\n },\n light: {\n ink: \"#111114\",\n muted: \"rgba(17,17,20,0.4)\",\n accent: \"#3B5BFD\",\n ground: undefined as GshPresetId | undefined,\n groundParams: LIGHT_GROUND as Partial<GradientParams> | undefined,\n groundOffset: 2,\n scrim: \"246,245,242\",\n scrimAlpha: 0.55,\n },\n};\n\nconst BEAT = {\n decay: 0.8,\n minShot: 6,\n settle: 3,\n pullLen: 30,\n accentAt: 16,\n hold: 42,\n};\n\nconst TRACK = -0.035;\nconst FONT_PX = 200;\nconst DRIFT = Easing.bezier(0.45, 0, 0.55, 1);\nconst HOLD = Easing.bezier(0.33, 0, 0.2, 1);\nconst COLOR = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n width: (s: string) => number;\n cap: number;\n asc: number;\n xh: number;\n}\n\nfunction buildMetrics(_version: number): Metrics {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n const font = `400 ${FONT_PX}px \"${geist.fontFamily}\"`;\n const box = (s: string) => {\n if (!ctx) return 0.7;\n ctx.font = font;\n return ctx.measureText(s).actualBoundingBoxAscent / FONT_PX;\n };\n const cache: Record<string, number> = {};\n return {\n width: (s: string) => {\n if (cache[s] === undefined) {\n if (!ctx) return s.length * 0.55;\n ctx.font = font;\n cache[s] =\n ctx.measureText(s).width / FONT_PX + TRACK * Array.from(s).length;\n }\n return cache[s];\n },\n cap: box(\"H\"),\n asc: box(\"l\"),\n xh: box(\"x\"),\n };\n}\n\nfunction useMetrics() {\n const [version, setVersion] = useState(0);\n const [handle] = useState(() => delayRender(\"macro-letter-pan: 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 geist.waitUntilDone(),\n document.fonts.load(`400 ${FONT_PX}px \"${geist.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(() => buildMetrics(version), [version]);\n}\n\nexport const macroLetterPanLength = (\n word = \"launch\",\n firstShot = 15,\n maxShots = 6,\n portrait = false,\n) => {\n const unit = portrait ? 1 : 2;\n const n = Math.max(1, Math.min(maxShots, word.length - unit + 1));\n let total = 0;\n for (let k = 0; k < n; k++) {\n total += Math.max(BEAT.minShot, Math.round(firstShot * BEAT.decay ** k));\n }\n return total + BEAT.pullLen + BEAT.hold;\n};\n\nexport function MacroLetterPan({\n line = \"Ready to launch.\",\n word = \"launch\",\n accent,\n ink,\n theme = \"dark\",\n ground,\n groundParams,\n firstShot = 15,\n maxShots = 6,\n}: MacroLetterPanProps) {\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 = useMetrics();\n\n const found = word ? line.indexOf(word) : -1;\n const text = found >= 0 ? line : word || line;\n const ws = found >= 0 ? found : 0;\n const we = ws + (word ? word.length : text.length);\n const before = text.slice(0, ws);\n const target = text.slice(ws, we);\n const after = text.slice(we);\n const period = /[.!?]$/.test(after) ? after.slice(-1) : \"\";\n const tail = period ? after.slice(0, -1) : after;\n\n const unit = portrait ? 1 : 2;\n const nShots = Math.max(1, Math.min(maxShots, target.length - unit + 1));\n const shots = useMemo(() => {\n const out: { start: number; len: number; from: number }[] = [];\n let t = 0;\n const span = Math.max(0, target.length - unit);\n for (let k = 0; k < nShots; k++) {\n const len = Math.max(\n BEAT.minShot,\n Math.round(firstShot * BEAT.decay ** k),\n );\n const from = nShots === 1 ? 0 : Math.round((k * span) / (nShots - 1));\n out.push({ start: t, len, from });\n t += len;\n }\n return out;\n }, [nShots, target.length, unit, firstShot]);\n const pullStart = shots[shots.length - 1].start + shots[shots.length - 1].len;\n\n const layout = useMemo(() => {\n if (!m) return null;\n const rows =\n portrait && before.trim()\n ? [\n { text: before.trimEnd(), offset: 0 },\n { text: text.slice(ws), offset: ws },\n ]\n : [{ text, offset: 0 }];\n const widest = Math.max(...rows.map((r) => m.width(r.text)));\n const F = Math.min(\n (W * (portrait ? 0.84 : 0.78)) / widest,\n (H * (portrait ? 0.22 : 0.2)) / m.cap,\n );\n const lh = F * 1.04;\n const blockH = m.cap * F + lh * (rows.length - 1);\n const top = (H - blockH) / 2 + m.cap * F;\n const placed = rows.map((r, i) => ({\n ...r,\n x: (W - m.width(r.text) * F) / 2,\n y: top + i * lh,\n }));\n const rowOf = placed[placed.length - 1];\n const charX = (i: number) =>\n rowOf.x + m.width(text.slice(rowOf.offset, i)) * F;\n return { F, rows: placed, base: rowOf.y, charX };\n }, [m, portrait, before, text, ws, W, H]);\n\n if (!m || !layout) {\n return <AbsoluteFill style={{ background: bg }} />;\n }\n const { F, rows, base, charX } = layout;\n\n const camAt = (t: number) => {\n let k = 0;\n for (let i = 0; i < shots.length; i++) if (t >= shots[i].start) k = i;\n const s = shots[k];\n const a = ws + s.from;\n const b = a + unit;\n const x0 = charX(a);\n const x1 = charX(b) - TRACK * F;\n const pairW = x1 - x0;\n const scale = Math.min(\n (W * (portrait ? 0.84 : 0.86)) / pairW,\n (H * (portrait ? 0.46 : 0.96)) / (m.xh * F),\n );\n const p = DRIFT(Math.min(1, Math.max(0, (t - s.start) / s.len)));\n const cx = (x0 + x1) / 2 + pairW * (-0.09 + 0.18 * p);\n const cy = base - m.xh * F * 0.56;\n return { cx, cy, scale: scale * (1 + 0.035 * p), k };\n };\n\n const lastEnd = camAt(pullStart - 0.001);\n const pull = spring({\n frame: frame - pullStart,\n fps,\n config: { mass: 1, damping: 26, stiffness: 120 },\n durationInFrames: BEAT.pullLen,\n });\n const pullPrev = spring({\n frame: frame - 1 - pullStart,\n fps,\n config: { mass: 1, damping: 26, stiffness: 120 },\n durationInFrames: BEAT.pullLen,\n });\n const hold = interpolate(\n frame,\n [pullStart + BEAT.pullLen - 6, pullStart + BEAT.pullLen + BEAT.hold],\n [0, 1],\n { ...CLAMP, easing: HOLD },\n );\n\n let scale: number;\n let ox: number;\n let oy: number;\n let blur = 0;\n if (frame < pullStart) {\n const cam = camAt(frame);\n scale = cam.scale;\n ox = W / 2 - cam.cx * scale;\n oy = H / 2 - cam.cy * scale;\n const s = shots[cam.k];\n blur =\n cam.k > 0\n ? interpolate(frame - s.start, [0, BEAT.settle], [5 * u, 0], CLAMP)\n : 0;\n } else {\n const s0 = lastEnd.scale;\n const s1 = 1 + 0.025 * hold;\n const cx1 = W / 2;\n const cy1 = H / 2;\n const px = (lastEnd.cx * s0 - cx1 * 1) / (s0 - 1);\n const py = (lastEnd.cy * s0 - cy1 * 1) / (s0 - 1);\n const sx = W / 2 + (px - lastEnd.cx) * s0;\n const sy = H / 2 + (py - lastEnd.cy) * s0;\n const sPull = Math.exp(Math.log(s0) * (1 - pull));\n scale = sPull * s1;\n ox = sx - px * sPull;\n oy = sy - py * sPull;\n ox = W / 2 + (ox - W / 2) * s1;\n oy = H / 2 + (oy - H / 2) * s1;\n const v = Math.abs(pull - pullPrev) * Math.log(s0);\n blur = Math.min(7 * u, v * 26 * u);\n }\n\n const dof = interpolate(frame, [pullStart, pullStart + 16], [1, 0], {\n ...CLAMP,\n easing: COLOR,\n });\n const reveal = interpolate(frame, [pullStart + 4, pullStart + 20], [0, 1], {\n ...CLAMP,\n easing: COLOR,\n });\n const colorHit = interpolate(\n frame,\n [pullStart + BEAT.accentAt, pullStart + BEAT.accentAt + 9],\n [0, 1],\n { ...CLAMP, easing: COLOR },\n );\n const dot = spring({\n frame: frame - pullStart - BEAT.accentAt - 3,\n fps,\n config: { mass: 0.5, damping: 12, stiffness: 200 },\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 const wordFill = mix(inkC, hi, colorHit);\n const mutedFill = mix(inkC, c.muted, reveal);\n\n const fs = F * scale;\n const toX = (x: number) => ox + x * scale;\n const toY = (y: number) => oy + y * scale;\n const periodX = charX(we + tail.length);\n\n const renderText = (key: string) => (\n <svg\n key={key}\n width={W}\n height={H}\n viewBox={`0 0 ${W} ${H}`}\n style={{ position: \"absolute\", inset: 0, overflow: \"visible\" }}\n aria-hidden\n >\n {rows.map((r, ri) => {\n const isLast = ri === rows.length - 1;\n const segs = isLast\n ? [\n ...(r.offset === 0 && before\n ? [{ t: before, fill: mutedFill }]\n : []),\n { t: target, fill: wordFill },\n { t: tail, fill: mutedFill },\n ]\n : [{ t: r.text, fill: mutedFill }];\n return (\n <text\n key={r.offset}\n x={toX(r.x)}\n y={toY(r.y)}\n fontFamily={geist.fontFamily}\n fontWeight={400}\n fontSize={fs}\n letterSpacing={`${TRACK}em`}\n style={{ fontKerning: \"normal\" }}\n >\n {segs.map((sg) => (\n <tspan key={sg.t + sg.fill} fill={sg.fill}>\n {sg.t}\n </tspan>\n ))}\n </text>\n );\n })}\n {period ? (\n <g\n transform={`translate(${toX(periodX + m.width(period) * F * 0.32)} ${toY(base)}) scale(${0.35 + 0.65 * dot}) translate(${-m.width(period) * fs * 0.32} 0)`}\n >\n <text\n x={0}\n y={0}\n fontFamily={geist.fontFamily}\n fontWeight={400}\n fontSize={fs}\n fill={mix(inkC, hi, colorHit)}\n opacity={interpolate(dot, [0, 0.3], [0, 1], CLAMP)}\n >\n {period}\n </text>\n </g>\n ) : null}\n </svg>\n );\n\n const ell = portrait ? \"62% 34%\" : \"46% 62%\";\n const sharpMask = `radial-gradient(${ell} at 50% 48%, #000 ${44 + 56 * (1 - dof)}%, transparent 100%)`;\n const softMask = `radial-gradient(${ell} at 50% 48%, transparent ${44 + 56 * (1 - dof)}%, #000 100%)`;\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.55}\n />\n <AbsoluteFill\n style={{\n background: `radial-gradient(${portrait ? \"92% 50%\" : \"70% 66%\"} at 50% 50%, rgba(${c.scrim},${c.scrimAlpha}) 0%, rgba(${c.scrim},0) 100%)`,\n }}\n />\n <AbsoluteFill\n style={{\n filter: `blur(${16 * dof * u + blur}px)`,\n opacity: dof > 0.001 ? 1 : 0,\n WebkitMaskImage: softMask,\n maskImage: softMask,\n }}\n >\n {renderText(\"soft\")}\n </AbsoluteFill>\n <AbsoluteFill\n style={{\n filter: blur > 0.05 ? `blur(${blur}px)` : undefined,\n WebkitMaskImage: dof > 0.001 ? sharpMask : undefined,\n maskImage: dof > 0.001 ? sharpMask : undefined,\n }}\n >\n {renderText(\"sharp\")}\n </AbsoluteFill>\n </AbsoluteFill>\n );\n}\n\nexport default MacroLetterPan;\n",
"type": "registry:component",
"target": "components/remocn/macro-letter-pan.tsx"
}
],
"type": "registry:component"
}