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": "unmask-line",
"title": "Unmask Line",
"description": "A monospace line is unmasked letter by letter, 'Out of stealth.', the last word in green.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/unmask-line/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadPlexMono } from \"@remotion/google-fonts/IBMPlexMono\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nconst plex = loadPlexMono(\"normal\", {\n weights: [\"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface UnmaskLineProps {\n lines?: string[];\n highlight?: number;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst GREEN = { dark: \"#00C805\", light: \"#00873C\" } as const;\n\nconst THEMES = {\n dark: { bg: \"#000000\", ink: \"#FFFFFF\" },\n light: { bg: \"#FFFFFF\", ink: \"#000000\" },\n} as const;\n\nconst DOT_R = 0.1;\nconst LEADING = 1.08;\nconst DOT_GAP = 1.2;\nconst DOT_LEN = 10;\nconst BREATH_AT = 18;\nconst BREATH_GAP = 1.4;\nconst BREATH_LEN = 12;\nconst OPEN_AT = 38;\nconst OPEN_GAP = 2.2;\nconst OPEN_LEN = 12;\nconst LINE_LAG = 4;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_OPEN = Easing.bezier(0.33, 0, 0.15, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n adv: number;\n cap: number;\n xh: number;\n base: number;\n}\n\nfunction measure(): Metrics {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n if (!ctx) throw new Error(\"unmask-line: no 2d context\");\n ctx.font = `500 100px \"${plex.fontFamily}\"`;\n const m = ctx.measureText(\"HHHHHHHHHH\");\n const asc = m.fontBoundingBoxAscent / 100;\n const desc = m.fontBoundingBoxDescent / 100;\n return {\n adv: m.width / 1000,\n cap: m.actualBoundingBoxAscent / 100,\n xh: ctx.measureText(\"x\").actualBoundingBoxAscent / 100,\n base: (1 - (asc + desc)) / 2 + asc,\n };\n}\n\nfunction useMetrics() {\n const [m, setM] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"unmask-line: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n plex.waitUntilDone(),\n document.fonts.load(`500 100px \"${plex.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setM(measure());\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [handle]);\n return m;\n}\n\nexport function UnmaskLine({\n lines = [\"Out of\", \"stealth.\"],\n highlight = -1,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: UnmaskLineProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const green = accent ?? GREEN[theme];\n const m = useMetrics();\n\n const transparent = background === \"transparent\";\n const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const list = lines.length > 0 ? lines : [\" \"];\n const hl = highlight < 0 ? list.length + highlight : highlight;\n const portrait = H > W * 1.1;\n const margin = Math.min(W, H) * (portrait ? 0.08 : 0.09);\n const widest = Math.max(...list.map((l) => Array.from(l).length));\n const F = Math.min(\n (H * (portrait ? 0.4 : 0.66)) / (list.length * LEADING),\n (W - 2 * margin) / Math.max(1, widest * m.adv),\n );\n const lineH = F * LEADING;\n const blockH = lineH * (list.length - 1) + m.cap * F;\n const firstBase = (H - blockH) / 2 + m.cap * F;\n const cell = m.adv * F;\n\n let order = 0;\n const nodes: React.ReactNode[] = [];\n list.forEach((line, li) => {\n const baseY = firstBase + li * lineH;\n const color = li === hl ? green : c.ink;\n Array.from(line).forEach((ch, ci) => {\n if (ch === \" \") return;\n const i = order++;\n const x = margin + ci * cell;\n const cx = x + cell / 2;\n const cy = baseY - m.xh * F * 0.5;\n const arrive = interpolate(\n t,\n [li * LINE_LAG + i * DOT_GAP, li * LINE_LAG + i * DOT_GAP + DOT_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const bt = t - (BREATH_AT + i * BREATH_GAP);\n const breath =\n bt > 0 && bt < BREATH_LEN ? Math.sin((bt / BREATH_LEN) * Math.PI) : 0;\n const p = interpolate(\n t,\n [OPEN_AT + i * OPEN_GAP, OPEN_AT + i * OPEN_GAP + OPEN_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_OPEN },\n );\n const r0 = DOT_R * F * (0.5 + 0.5 * arrive) * (1 + 0.22 * breath);\n const rFull = Math.hypot(cell * 0.6, F * 0.8);\n const r = r0 + (rFull - r0) * p;\n const dotOpacity = arrive * interpolate(p, [0, 0.4], [1, 0], CLAMP);\n if (dotOpacity > 0.002) {\n nodes.push(\n <div\n key={`d${li}-${ci}`}\n style={{\n position: \"absolute\",\n left: cx - r,\n top: cy - r,\n width: r * 2,\n height: r * 2,\n borderRadius: \"50%\",\n background: color,\n opacity: dotOpacity,\n }}\n />,\n );\n }\n if (p > 0) {\n const top = baseY - m.base * F;\n nodes.push(\n <div\n key={`g${li}-${ci}`}\n style={{\n position: \"absolute\",\n left: x,\n top,\n height: F,\n lineHeight: `${F}px`,\n fontFamily: plex.fontFamily,\n fontWeight: 500,\n fontSize: F,\n whiteSpace: \"pre\",\n color,\n clipPath:\n p >= 0.999\n ? undefined\n : `circle(${r.toFixed(2)}px at ${(cx - x).toFixed(2)}px ${(cy - top).toFixed(2)}px)`,\n }}\n >\n {ch}\n </div>,\n );\n }\n });\n });\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {nodes}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/unmask-line.tsx"
}
],
"type": "registry:component"
}