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": "spell-out",
"title": "Spell Out",
"description": "\"remocn\" spells out in big lowercase letters with \"Say it once. Remember it.\" beneath.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/spell-out/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Nunito\";\nimport type React from \"react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nconst nunito = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface SpellOutProps {\n name?: string;\n line?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#133A24\",\n ink: \"#EAF7EC\",\n accent: \"#FFD23F\",\n line: \"#FFD23F\",\n },\n light: {\n bg: \"#FFD23F\",\n ink: \"#133A24\",\n accent: \"#FFFFFF\",\n line: \"#133A24\",\n },\n} as const;\n\nconst FONT_PX = 200;\nconst TRACK = -0.03;\nconst LINE_TRACK = -0.01;\nconst SPELL_AT = 4;\nconst LETTER_GAP = 8;\nconst FALL = 7;\nconst HOLD_SPELLED = 14;\nconst CLOSE_LEN = 20;\nconst LINE_DELAY = 14;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN = Easing.bezier(0.55, 0, 0.85, 0.35);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.25, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n adv: number[];\n pos: number[];\n width: number;\n hyphen: number;\n hyphenInk: number;\n asc: number;\n desc: number;\n top: number;\n xh: number;\n lineW: number;\n lineCap: number;\n}\n\nfunction measure(chars: string[], line: string): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"spell-out: no 2d context\");\n const fam = `\"${nunito.fontFamily}\"`;\n ctx.font = `500 ${FONT_PX}px ${fam}`;\n const adv = chars.map((ch) => ctx.measureText(ch).width / FONT_PX);\n const pos: number[] = [];\n let prefix = \"\";\n for (let i = 0; i < chars.length; i++) {\n pos.push(prefix ? ctx.measureText(prefix).width / FONT_PX + TRACK * i : 0);\n prefix += chars[i];\n }\n const width =\n ctx.measureText(prefix).width / FONT_PX + TRACK * (chars.length - 1);\n const hm = ctx.measureText(\"-\");\n const fm = ctx.measureText(prefix || \"x\");\n const metrics = ctx.measureText(\"Hg\");\n ctx.font = `500 ${FONT_PX}px ${fam}`;\n const lm = ctx.measureText(line || \" \");\n return {\n adv,\n pos,\n width,\n hyphen: hm.width / FONT_PX,\n hyphenInk: (hm.actualBoundingBoxRight + hm.actualBoundingBoxLeft) / FONT_PX,\n asc: metrics.fontBoundingBoxAscent / FONT_PX,\n desc: metrics.fontBoundingBoxDescent / FONT_PX,\n top: fm.actualBoundingBoxAscent / FONT_PX,\n xh: ctx.measureText(\"x\").actualBoundingBoxAscent / FONT_PX,\n lineW:\n lm.width / FONT_PX +\n LINE_TRACK * Math.max(0, Array.from(line).length - 1),\n lineCap: ctx.measureText(\"H\").actualBoundingBoxAscent / FONT_PX,\n };\n}\n\nfunction useMetrics(chars: string[], line: string) {\n const key = chars.join(\"\");\n const [metrics, setMetrics] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"spell-out: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n nunito.waitUntilDone(),\n document.fonts.load(`500 100px \"${nunito.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setMetrics(measure(Array.from(key), line));\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [key, line, handle]);\n return metrics;\n}\n\nfunction impact(u: number) {\n if (u < 0) return 0;\n return Math.exp(-u / 3.6) * Math.cos(u * 0.55);\n}\n\nexport function SpellOut({\n name = \"remocn\",\n line = \"Say it once. Remember it.\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: SpellOutProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const bg = background ?? c.bg;\n const dash = accent ?? c.accent;\n const chars = useMemo(() => Array.from(name.replace(/\\s+/g, \"\")), [name]);\n const m = useMetrics(chars, line);\n\n if (!m || chars.length === 0) {\n return <div style={{ position: \"absolute\", inset: 0, background: bg }} />;\n }\n\n const n = chars.length;\n const gap = 0.07;\n const unit = m.hyphen + gap * 2;\n const spelled: number[] = [];\n let run = 0;\n for (let i = 0; i < n; i++) {\n spelled.push(run);\n run += m.adv[i] + (i < n - 1 ? unit : 0);\n }\n const spelledW = run;\n const S = Math.min((W * 0.9) / spelledW, H * 0.3);\n const lineSize0 = line ? Math.min(H * 0.088, (W * 0.8) / m.lineW) : 0;\n const F0 = Math.min((W * 0.84) / m.width, H * 0.42);\n const lineGap = line ? F0 * 0.34 : 0;\n const blockH = m.top * F0 + lineGap + (line ? m.lineCap * lineSize0 : 0);\n const F = F0;\n const finalBase = (H - blockH) / 2 + m.top * F;\n const spellBase = H / 2 + (m.xh * S) / 2;\n const R = Math.max(S, F);\n const lh = R * 1.4;\n const bo = (lh - (m.asc + m.desc) * R) / 2 + m.asc * R;\n\n const lastLand = SPELL_AT + (n - 1) * LETTER_GAP + FALL;\n const closeAt = lastLand + HOLD_SPELLED;\n const close = interpolate(t, [closeAt, closeAt + CLOSE_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_IN_OUT,\n });\n const size = S + (F - S) * close;\n const spellLeft = (W - spelledW * S) / 2;\n const finalLeft = (W - m.width * F) / 2;\n const base = spellBase + (finalBase - spellBase) * close;\n\n const nodes: React.ReactNode[] = [];\n for (let i = 0; i < n; i++) {\n const landAt = SPELL_AT + i * LETTER_GAP + FALL;\n const fall = interpolate(t, [landAt - FALL, landAt], [0, 1], {\n ...CLAMP,\n easing: EASE_IN,\n });\n if (t < landAt - FALL) continue;\n const x0 = spellLeft + spelled[i] * S;\n const x1 = finalLeft + m.pos[i] * F;\n const x = x0 + (x1 - x0) * close;\n const dy = (1 - fall) * -S * 0.9;\n const air = fall < 1 ? Math.sin(fall * Math.PI * 0.5) : 1;\n const stretch = fall < 1 ? 0.22 * air : 0;\n const q = impact(t - landAt);\n const centre = (n - 1) / 2;\n const settleAt = closeAt + CLOSE_LEN - 2 + Math.abs(i - centre) * 1.5;\n const q2 = impact(t - settleAt) * 0.6;\n const sy = 1 + stretch - 0.2 * q - 0.12 * q2;\n const sx = 1 - stretch * 0.5 + 0.12 * q + 0.08 * q2;\n const s = size / R;\n const o = interpolate(fall, [0, 0.35], [0, 1], CLAMP);\n nodes.push(\n <div\n key={`l${i}`}\n style={{\n position: \"absolute\",\n left: x + (m.adv[i] * (size - R)) / 2,\n top: base - bo + dy,\n height: lh,\n fontFamily: nunito.fontFamily,\n fontWeight: 500,\n fontSize: R,\n lineHeight: `${lh}px`,\n whiteSpace: \"pre\",\n color: c.ink,\n opacity: o,\n transform: `scale(${(s * sx).toFixed(4)}, ${(s * sy).toFixed(4)})`,\n transformOrigin: `${((m.adv[i] * R) / 2).toFixed(1)}px ${bo.toFixed(1)}px`,\n }}\n >\n {chars[i]}\n </div>,\n );\n if (i < n - 1) {\n const born = landAt + 1;\n const hp = interpolate(t, [born, born + 7], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const shrink = 1 - close;\n if (hp > 0 && shrink > 0.001) {\n const nextX0 = spellLeft + spelled[i + 1] * S;\n const nextX1 = finalLeft + m.pos[i + 1] * F;\n const nx = nextX0 + (nextX1 - nextX0) * close;\n const mid = (x + m.adv[i] * size + nx) / 2;\n const barH = S * 0.1;\n const barW = Math.max(\n barH * shrink,\n m.hyphenInk * S * shrink * (0.4 + 0.6 * hp),\n );\n nodes.push(\n <div\n key={`h${i}`}\n style={{\n position: \"absolute\",\n left: mid - barW / 2,\n top: base - m.xh * size * 0.5 - (barH * shrink) / 2,\n width: barW,\n height: barH * Math.max(0.3, shrink),\n borderRadius: barH,\n background: dash,\n opacity: hp * Math.min(1, shrink * 2.5),\n }}\n />,\n );\n }\n }\n }\n\n const lineAt = closeAt + CLOSE_LEN - 4 + LINE_DELAY - 10;\n const lp = interpolate(t, [lineAt, lineAt + 18], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const lineBase = finalBase + lineGap + m.lineCap * lineSize0;\n const llh = lineSize0 * 1.45;\n const lbo = (llh - (m.asc + m.desc) * lineSize0) / 2 + m.asc * lineSize0;\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n {nodes}\n {line ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: lineBase - lbo,\n height: llh,\n overflow: \"hidden\",\n display: \"flex\",\n justifyContent: \"center\",\n }}\n >\n <div\n style={{\n fontFamily: nunito.fontFamily,\n fontWeight: 500,\n fontSize: lineSize0,\n lineHeight: `${llh}px`,\n letterSpacing: `${LINE_TRACK}em`,\n color: c.line,\n whiteSpace: \"pre\",\n transform: `translateY(${((1 - lp) * llh).toFixed(2)}px)`,\n }}\n >\n {line}\n </div>\n </div>\n ) : null}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/spell-out.tsx"
}
],
"type": "registry:component"
}