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": "headline-to-line",
"title": "Headline to Line",
"description": "A headline settles and its phrase collapses toward a single line over a glowing horizon.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/headline-to-line/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Geist\";\nimport {\n type CSSProperties,\n useEffect,\n useMemo,\n useRef,\n useState,\n} 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\"],\n subsets: [\"latin\"],\n});\n\nexport interface HeadlineToLineProps {\n words?: string[];\n accentIndex?: number;\n continuation?: string;\n accent?: string;\n ink?: string;\n background?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n}\n\nconst THEMES = {\n dark: {\n ink: \"#eef2ff\",\n accent: \"#8fb4ff\",\n caret: \"#b9cdff\",\n ground: \"earthshine\" as GshPresetId,\n groundOffset: 4,\n scrim: \"2,4,10\",\n scrimAlpha: 0.5,\n },\n light: {\n ink: \"#14161c\",\n accent: \"#3B5BFD\",\n caret: \"#3B5BFD\",\n ground: \"paper-crease\" as GshPresetId,\n groundOffset: 2,\n scrim: \"238,236,232\",\n scrimAlpha: 0.55,\n },\n} as const;\n\nconst FONT_PX = 200;\nconst TRACK_BIG = -0.045;\nconst TRACK_SMALL = -0.02;\nconst POP_SCALE = 0.12;\n\nconst BEAT = {\n wordStep: 6,\n enter: 12,\n pop: 24,\n shrink: 48,\n shrinkLen: 18,\n wordLag: 1,\n type: 66,\n charsPerFrame: 1,\n rise: 42,\n riseLen: 42,\n};\n\nconst ENTER = Easing.bezier(0.22, 1, 0.36, 1);\nconst LIGHT_IN = Easing.bezier(0.32, 0.72, 0, 1);\nconst CAMERA = Easing.bezier(0.87, 0, 0.13, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ntype Measure = (s: string, track: number) => number;\n\nfunction buildMeasure(_version: number): Measure {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n const cache: Record<string, number> = {};\n return (s: string, track: number) => {\n const key = `${track}|${s}`;\n if (cache[key] === undefined) {\n if (!ctx) return s.length * 0.55;\n ctx.font = `300 ${FONT_PX}px \"${geist.fontFamily}\"`;\n cache[key] =\n ctx.measureText(s).width / FONT_PX + track * Array.from(s).length;\n }\n return cache[key];\n };\n}\n\nfunction useMeasure() {\n const [version, setVersion] = useState(0);\n const [handle] = useState(() => delayRender(\"headline-to-line: 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(`300 100px \"${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(() => buildMeasure(version), [version]);\n}\n\ninterface Slot {\n x: number;\n y: number;\n line: number;\n}\n\ninterface Line {\n start: number;\n end: number;\n width: number;\n}\n\nfunction wrapWords(\n words: string[],\n room: number,\n w: (s: string) => number,\n): string[][] {\n const lines: string[][] = [];\n let cur: string[] = [];\n for (const word of words) {\n if (cur.length > 0 && w([...cur, word].join(\" \")) > room) {\n lines.push(cur);\n cur = [];\n }\n cur.push(word);\n }\n if (cur.length > 0) lines.push(cur);\n return lines;\n}\n\nexport function HeadlineToLine({\n words = [\"Your\", \"launch\", \"video\"],\n accentIndex = 1,\n continuation = \", built from blocks you own\",\n accent,\n ink,\n background,\n theme = \"dark\",\n ground,\n groundParams,\n}: HeadlineToLineProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, fps, durationInFrames } = useVideoConfig();\n const c = THEMES[theme];\n const inkC = ink ?? c.ink;\n const hi = accent ?? c.accent;\n const preset = ground ?? c.ground;\n const bg = background ?? gshParams(preset, groundParams).background;\n const m = useMeasure();\n const t = frame;\n\n const rise = interpolate(t, [BEAT.rise, BEAT.rise + BEAT.riseLen], [0, 1], {\n ...CLAMP,\n easing: LIGHT_IN,\n });\n const portrait = H > W * 1.1;\n const push = interpolate(frame, [0, durationInFrames], [1, 1.03], CLAMP);\n const groundShift = (1 - rise) * (portrait ? 0.16 : 0.26);\n const scrimA = c.scrimAlpha * (1 - 0.45 * rise);\n\n let content: React.ReactNode = <div />;\n if (m && words.length > 0) {\n const head = words.join(\" \");\n const full = head + continuation;\n const marginX = W * (portrait ? 0.08 : 0.07);\n const room = W - marginX * 2;\n const cx = W / 2;\n const cy = H * (portrait ? 0.46 : 0.47);\n\n const wb = (s: string) => m(s, TRACK_BIG);\n const ws = (s: string) => m(s, TRACK_SMALL);\n const longest = Math.max(...words.map((w) => wb(w)));\n const oneLine = (room * 0.92) / wb(head);\n const minOne = portrait ? W * 0.2 : H * 0.15;\n const cap = portrait ? W * 0.27 : H * 0.28;\n const B =\n oneLine >= minOne\n ? Math.min(cap, oneLine)\n : Math.min(cap, room / longest);\n const bigLines =\n oneLine >= minOne ? [words] : wrapWords(words, room / B, wb);\n const bigLH = B * 1.02;\n const multi = bigLines.length > 1;\n const bigSlots: Slot[] = [];\n bigLines.forEach((line, li) => {\n const lw = wb(line.join(\" \")) * B;\n let x = cx - lw / 2;\n const y = cy + (li - (bigLines.length - 1) / 2) * bigLH;\n line.forEach((word, wi) => {\n const ww = wb(word) * B;\n bigSlots.push({ x: x + ww / 2, y, line: li });\n x += ww + (wi < line.length - 1 ? wb(\" \") * B : 0);\n });\n });\n\n const s = Math.max(H * 0.026, portrait ? W * 0.068 : H * 0.068);\n const tokens = full.split(\" \");\n const lines: Line[] = [];\n let pos = 0;\n let cur = \"\";\n let curStart = 0;\n for (const tok of tokens) {\n const next = cur.length > 0 ? `${cur} ${tok}` : tok;\n if (cur.length > 0 && ws(next) * s > room) {\n lines.push({\n start: curStart,\n end: curStart + cur.length,\n width: ws(cur) * s,\n });\n curStart = pos;\n cur = tok;\n } else {\n cur = next;\n }\n pos += tok.length + 1;\n }\n lines.push({\n start: curStart,\n end: curStart + cur.length,\n width: ws(cur) * s,\n });\n const smallLH = s * 1.3;\n const lineX = (i: number) => cx - lines[i].width / 2;\n const lineY = (i: number) => cy + (i - (lines.length - 1) / 2) * smallLH;\n const lineOf = (ch: number) => {\n for (let i = 0; i < lines.length; i++) {\n if (ch <= lines[i].end) return i;\n }\n return lines.length - 1;\n };\n const charX = (ch: number) => {\n const li = lineOf(ch);\n return lineX(li) + ws(full.slice(lines[li].start, ch)) * s;\n };\n\n const smallSlots: Slot[] = [];\n let at = 0;\n for (const word of words) {\n const li = lineOf(at);\n const x0 = charX(at);\n smallSlots.push({ x: x0 + (ws(word) * s) / 2, y: lineY(li), line: li });\n at += word.length + 1;\n }\n\n const k1 = s / B;\n const centroid = (sl: Slot[]): Slot => ({\n line: 0,\n x: sl.reduce((a, q) => a + q.x, 0) / sl.length,\n y: sl.reduce((a, q) => a + q.y, 0) / sl.length,\n });\n const bigC = centroid(bigSlots);\n const smallC = centroid(smallSlots);\n const validAccent = accentIndex >= 0 && accentIndex < words.length;\n const accentW = validAccent ? wb(words[accentIndex]) * B : 0;\n const shrinkP = (i: number, tt: number) => {\n const at0 = BEAT.shrink + i * (multi ? BEAT.wordLag * 3 : BEAT.wordLag);\n return interpolate(tt, [at0, at0 + BEAT.shrinkLen], [0, 1], {\n ...CLAMP,\n easing: CAMERA,\n });\n };\n const popSpring = spring({\n frame: t - BEAT.pop,\n fps,\n config: { mass: 0.5, damping: 12, stiffness: 200 },\n });\n const popNow = validAccent ? popSpring * (1 - shrinkP(accentIndex, t)) : 0;\n const popShift = (i: number) => {\n if (!validAccent || i === accentIndex) return 0;\n if (bigSlots[i].line !== bigSlots[accentIndex].line) return 0;\n const extra = POP_SCALE * popNow * accentW * 0.5 + B * 0.03 * popNow;\n return i < accentIndex ? -extra : extra;\n };\n const wordNodes = words.map((word, i) => {\n const enterAt = i * BEAT.wordStep - 4;\n const e = interpolate(t, [enterAt, enterAt + BEAT.enter], [0, 1], {\n ...CLAMP,\n easing: ENTER,\n });\n const p = shrinkP(i, t);\n const pPrev = shrinkP(i, t - 1);\n const k = Math.exp(Math.log(k1) * p);\n const relX =\n (bigSlots[i].x - bigC.x) * (1 - p) +\n ((smallSlots[i].x - smallC.x) / k1) * p;\n const relY =\n (bigSlots[i].y - bigC.y) * (1 - p) +\n ((smallSlots[i].y - smallC.y) / k1) * p;\n const x = multi\n ? bigSlots[i].x + (smallSlots[i].x - bigSlots[i].x) * p\n : bigC.x + (smallC.x - bigC.x) * p + (relX + popShift(i)) * k;\n const y = multi\n ? bigSlots[i].y + (smallSlots[i].y - bigSlots[i].y) * p\n : bigC.y + (smallC.y - bigC.y) * p + relY * k;\n const speed = Math.abs(p - pPrev);\n const blurScreen = Math.min(6, speed * 36) + (1 - e) * 6;\n\n const isAccent = i === accentIndex;\n const popAmt = isAccent ? popNow : 0;\n const lifted = -0.14 * popAmt;\n const popScale = 1 + POP_SCALE * popAmt;\n const tint = isAccent\n ? interpolate(t - BEAT.pop, [0, 6], [0, 1], {\n ...CLAMP,\n easing: LIGHT_IN,\n })\n : 0;\n const color =\n tint > 0\n ? `color-mix(in oklab, ${hi} ${(tint * 100).toFixed(1)}%, ${inkC})`\n : inkC;\n\n const style: CSSProperties = {\n position: \"absolute\",\n left: 0,\n top: 0,\n fontSize: B,\n lineHeight: 1,\n whiteSpace: \"pre\",\n fontFamily: geist.fontFamily,\n fontWeight: 300,\n letterSpacing: `${TRACK_BIG + (TRACK_SMALL - TRACK_BIG) * p}em`,\n color,\n transform: `translate(${x.toFixed(2)}px, ${y.toFixed(2)}px) translate(-50%, -50%) scale(${k.toFixed(5)})`,\n clipPath: \"inset(-80% -30% -0.26em -30%)\",\n };\n return (\n <div key={`w${i}`} style={style}>\n <div\n style={{\n transform: `translateY(${((1 - e) * 0.62 + lifted).toFixed(4)}em) scale(${popScale.toFixed(4)})`,\n transformOrigin: \"50% 80%\",\n opacity: e,\n filter:\n blurScreen > 0.05\n ? `blur(${(blurScreen / k).toFixed(2)}px)`\n : undefined,\n }}\n >\n {word}\n </div>\n </div>\n );\n });\n\n const landed =\n BEAT.shrink +\n BEAT.shrinkLen +\n (words.length - 1) * BEAT.wordLag * (multi ? 3 : 1);\n const typeAt = Math.max(BEAT.type, landed);\n const typed = Math.max(\n 0,\n Math.min(\n continuation.length,\n Math.floor((t - typeAt) * BEAT.charsPerFrame),\n ),\n );\n const typeEnd =\n typeAt + Math.ceil(continuation.length / BEAT.charsPerFrame);\n const headLen = head.length;\n const caretCh = headLen + typed;\n const textNodes = lines.map((ln, li) => {\n const from = Math.max(ln.start, headLen);\n const to = Math.min(ln.end, caretCh);\n if (to <= from) return null;\n return (\n <div\n key={`l${li}`}\n style={{\n position: \"absolute\",\n left: charX(from),\n top: lineY(li) - s / 2,\n fontSize: s,\n lineHeight: 1,\n whiteSpace: \"pre\",\n fontFamily: geist.fontFamily,\n fontWeight: 300,\n letterSpacing: `${TRACK_SMALL}em`,\n color: inkC,\n }}\n >\n {full.slice(from, to)}\n </div>\n );\n });\n\n const caretIn = interpolate(t, [landed - 6, landed], [0, 1], CLAMP);\n const blinkOn =\n t < typeEnd + 6 || Math.floor((t - typeEnd - 6) / 15) % 2 === 1;\n const caretLine = lineOf(caretCh);\n const caretX = charX(caretCh) + s * 0.06;\n const caret = (\n <div\n style={{\n position: \"absolute\",\n left: caretX,\n top: lineY(caretLine) - s * 0.56,\n width: Math.max(2, s * 0.05),\n height: s * 1.12,\n borderRadius: s,\n background: c.caret,\n opacity: caretIn * (blinkOn ? 1 : 0),\n }}\n />\n );\n\n content = (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n transform: `scale(${push.toFixed(5)})`,\n }}\n >\n {wordNodes}\n {textNodes}\n {caret}\n </div>\n );\n }\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n <AbsoluteFill\n style={{\n transform: `translateY(${(groundShift * 100).toFixed(3)}%) scale(${(1.08 - 0.04 * rise).toFixed(4)})`,\n }}\n >\n <GshGround\n preset={preset}\n params={groundParams}\n timeOffset={c.groundOffset}\n timeScale={0.25}\n />\n </AbsoluteFill>\n <AbsoluteFill\n style={{\n background: `radial-gradient(70% 46% at 50% ${portrait ? 46 : 47}%, rgba(${c.scrim},${scrimA.toFixed(3)}) 0%, rgba(${c.scrim},0) 100%)`,\n }}\n />\n {content}\n </AbsoluteFill>\n );\n}\n\nexport default HeadlineToLine;\n",
"type": "registry:component",
"target": "components/remocn/headline-to-line.tsx"
}
],
"type": "registry:component"
}