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": "parallax-lockup",
"title": "Parallax Lockup",
"description": "A three-line headline locks up with parallax, the last line in a gradient.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/parallax-lockup/index.tsx",
"content": "\"use client\";\n\nimport { loadVariableFont } from \"@remotion/google-fonts/BricolageGrotesque\";\nimport { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n interpolateColors,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\n/** Variable cut, so display sizes pick up the tight, ink-trapped optical size. */\nconst display = loadVariableFont(\"normal\", { subsets: [\"latin\"] });\n\nexport interface ParallaxLockupProps {\n /**\n * The statement, one string per line. Each line is sized so all lines end\n * flush on both sides; shorter lines come out bigger. Three lines of\n * falling length read best.\n */\n lines?: string[];\n /** Index of the line that lands in the gradient fill. -1 for none. */\n accentLine?: number;\n accent?: string;\n /** Playback multiplier. */\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\n// Beat sheet (30fps):\n// 0–8 lines already crossing the frame, cropped by its edges\n// 0–94 one scroll: lines slide in alternate directions, each at its own\n// parallax rate (bigger type travels further, so it moves faster,\n// both across and up), so the leading closes as they lock on the\n// same frame\n// 80–98 the accent line takes its gradient as the block locks\n// 94–150 poster: a solid justified block, slow push\nconst SCROLL_END = 94;\nconst ACCENT_AT = 80;\nconst ACCENT_END = 98;\n\nconst SCROLL = Easing.bezier(0.3, 0.42, 0.1, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst WEIGHT = 500;\nconst PROBE = 200;\n/** Display tracking, in em. */\nconst TRACK = -0.035;\n\n/**\n * The accent line fills with the gradients.sh \"fluted\" palette: the accent\n * blue running into ember and cream on dark, deeper stops on light. Blue and\n * ember are near-complements and go grey when mixed in sRGB, so the hand-off\n * runs through their OKLCH midpoint instead.\n */\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n fg: \"#F5F4F0\",\n fluted: (accent: string): [string, number][] => [\n [accent, 0],\n [\"#2F7BFF\", 0.28],\n [\"#D65FC9\", 0.5],\n [\"#FF7A3D\", 0.72],\n [\"#FFE2C4\", 1],\n ],\n },\n light: {\n bg: \"#F5F4F0\",\n fg: \"#111113\",\n fluted: (accent: string): [string, number][] => [\n [\"#1D2A8F\", 0],\n [accent, 0.28],\n [\"#C841B4\", 0.52],\n [\"#E8622B\", 0.76],\n [\"#FF7A3D\", 1],\n ],\n },\n} as const;\n\n/** Ink box of one line, in em at font-size 1, relative to the text origin. */\ninterface LineInk {\n left: number;\n right: number;\n ascent: number;\n descent: number;\n}\n\nfunction measure(lines: string[]): LineInk[] {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n return lines.map((text) => {\n const n = [...text].length;\n if (!ctx) {\n return { left: 0, right: n * 0.56, ascent: 0.73, descent: 0 };\n }\n ctx.font = `${WEIGHT} ${PROBE}px \"${display.fontFamily}\"`;\n const m = ctx.measureText(text);\n return {\n left: -m.actualBoundingBoxLeft / PROBE,\n // tracking shifts every glyph after the first\n right: m.actualBoundingBoxRight / PROBE + TRACK * (n - 1),\n ascent: m.actualBoundingBoxAscent / PROBE,\n descent: Math.max(0, m.actualBoundingBoxDescent / PROBE),\n };\n });\n}\n\nfunction useInk(lines: string[]) {\n const [ink, setInk] = useState<LineInk[] | null>(null);\n const [handle] = useState(() =>\n delayRender(\"parallax-lockup: measuring lines\"),\n );\n const released = useRef(false);\n\n useEffect(() => {\n let live = true;\n Promise.all([\n display.waitUntilDone(),\n document.fonts.load(`${WEIGHT} ${PROBE}px \"${display.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setInk(measure(lines));\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [lines, handle]);\n\n return ink;\n}\n\nexport function ParallaxLockup({\n lines = [\"Every launch\", \"deserves\", \"a film\"],\n accentLine = 2,\n accent = \"#3B5BFD\",\n speed = 1,\n theme = \"dark\",\n}: ParallaxLockupProps) {\n const frame = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n\n const key = lines.join(\"\\n\");\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed on content\n const stable = useMemo(() => lines, [key]);\n const ink = useInk(stable);\n\n const layout = useMemo(() => {\n if (!ink) return null;\n // Size every line to one ink width, then fit the block to the frame.\n const widths = ink.map((l) => Math.max(0.1, l.right - l.left));\n const unit = (block: number) => {\n const sizes = widths.map((w) => block / w);\n const gap = block * 0.042;\n const tops: number[] = [];\n const bases: number[] = [];\n let y = 0;\n sizes.forEach((s, i) => {\n if (i > 0) {\n const prev = sizes[i - 1];\n y += Math.max(gap, ink[i - 1].descent * prev + gap * 0.4);\n }\n tops.push(y);\n y += ink[i].ascent * s;\n bases.push(y);\n });\n return { sizes, tops, bases, height: y };\n };\n let block = W * 0.6;\n const probe = unit(block);\n const maxH = H * 0.74;\n if (probe.height > maxH) block *= maxH / probe.height;\n const set = unit(block);\n const left = (W - block) / 2;\n const top = (H - set.height) / 2;\n const maxSize = Math.max(...set.sizes);\n return {\n lines: set.sizes.map((s, i) => ({\n size: s,\n x: left - ink[i].left * s,\n y: top + set.bases[i],\n rate: s / maxSize,\n })),\n };\n }, [ink, W, H]);\n\n const scroll = interpolate(frame, [0, SCROLL_END], [0, 1], {\n ...CLAMP,\n easing: SCROLL,\n });\n const rest = 1 - scroll;\n const rise = H * 0.05 * rest;\n const push = interpolate(frame, [SCROLL_END - 30, 150], [1, 1.018], {\n ...CLAMP,\n easing: Easing.bezier(0.33, 0, 0.67, 1),\n });\n const accentIn = interpolate(frame, [ACCENT_AT, ACCENT_END], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n return (\n <AbsoluteFill style={{ backgroundColor: c.bg, overflow: \"hidden\" }}>\n {layout ? (\n <svg\n width={W}\n height={H}\n viewBox={`0 0 ${W} ${H}`}\n style={{\n position: \"absolute\",\n inset: 0,\n transform: `scale(${push})`,\n transformOrigin: \"50% 50%\",\n }}\n aria-hidden\n >\n <defs>\n <linearGradient\n id={`f${uid}`}\n x1=\"0\"\n y1=\"0.2\"\n x2=\"1\"\n y2={0.8 + Math.sin(frame / 40) * 0.15}\n >\n {c.fluted(accent).map(([col, offset]) => (\n <stop\n key={offset}\n offset={offset}\n stopColor={interpolateColors(accentIn, [0, 1], [c.fg, col])}\n />\n ))}\n </linearGradient>\n </defs>\n {layout.lines.map((l, i) => {\n const dir = i % 2 === 0 ? 1 : -1;\n const travel = dir * W * 0.66 * l.rate * rest;\n const color = i === accentLine ? `url(#f${uid})` : c.fg;\n return (\n <text\n key={`${i}-${stable[i]}`}\n x={l.x + travel}\n // nearer (bigger) lines also climb further: the leading\n // closes as the scroll lands\n y={l.y + rise + H * 0.09 * l.rate * rest}\n fill={color}\n style={{\n fontFamily: display.fontFamily,\n fontWeight: WEIGHT,\n fontSize: l.size,\n letterSpacing: `${TRACK}em`,\n }}\n >\n {stable[i]}\n </text>\n );\n })}\n </svg>\n ) : null}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/parallax-lockup.tsx"
}
],
"type": "registry:component"
}