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": "embargo-lift",
"title": "Embargo Lift",
"description": "\"remocn is free, open source and out today\" in condensed type with a green accent.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/embargo-lift/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/BigShoulders\";\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 shoulders = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface EmbargoLiftProps {\n lines?: string[];\n slug?: string;\n liftedSlug?: string;\n highlight?: number;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: { bg: \"#26231F\", ink: \"#F6F0E6\", accent: \"#2BD96B\" },\n light: { bg: \"#F5F5F2\", ink: \"#000000\", accent: \"#0E9F4B\" },\n} as const;\n\nconst WGHT = 500;\nconst PX = 200;\nconst LEAD = 1.2;\n\nconst T_SLUG = 50;\nconst T_LIFT = 58;\nconst LIFT_STEP = 14;\nconst LIFT_DUR = 16;\nconst HOLD = 34;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_LIFT = Easing.bezier(0.7, 0, 0.25, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Seg {\n text: string;\n hidden: boolean;\n bar: number;\n}\n\nfunction parseLine(line: string, start: number): Seg[] {\n const out: Seg[] = [];\n let bar = start;\n const re = /\\[([^\\]]*)\\]/g;\n let last = 0;\n for (let r = re.exec(line); r; r = re.exec(line)) {\n if (r.index > last)\n out.push({ text: line.slice(last, r.index), hidden: false, bar: -1 });\n out.push({ text: r[1], hidden: true, bar });\n bar += 1;\n last = r.index + r[0].length;\n }\n if (last < line.length)\n out.push({ text: line.slice(last), hidden: false, bar: -1 });\n return out;\n}\n\ninterface Metrics {\n w: Record<string, number>;\n asc: number;\n desc: number;\n cap: number;\n dsc: number;\n}\n\nfunction measureAll(texts: string[]): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"embargo-lift: no 2d context\");\n ctx.font = `${WGHT} ${PX}px \"${shoulders.fontFamily}\"`;\n const w: Record<string, number> = {};\n for (const s of texts) w[s] = ctx.measureText(s).width / PX;\n const fm = ctx.measureText(\"Hgp\");\n const h = ctx.measureText(\"Hbdl\");\n const g = ctx.measureText(\"gpy\");\n return {\n w,\n asc: fm.fontBoundingBoxAscent / PX,\n desc: fm.fontBoundingBoxDescent / PX,\n cap: h.actualBoundingBoxAscent / PX,\n dsc: g.actualBoundingBoxDescent / PX,\n };\n}\n\nfunction useMetrics(texts: string[]) {\n const key = texts.join(\"\\u0001\");\n const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n const [handle] = useState(() => delayRender(\"embargo-lift: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n shoulders.waitUntilDone(),\n document.fonts.load(`${WGHT} 100px \"${shoulders.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setState({ key, m: measureAll(key.split(\"\\u0001\")) });\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [key, handle]);\n return state && state.key === key ? state.m : null;\n}\n\nexport function EmbargoLift({\n lines = [\"remocn is [free],\", \"[open source]\", \"and [out today].\"],\n slug = \"Embargoed until 9:00 a.m.\",\n liftedSlug = \"Embargo lifted, 9:00 a.m.\",\n highlight,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: EmbargoLiftProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, durationInFrames } = useVideoConfig();\n const c = THEMES[theme];\n const hi = accent ?? c.accent;\n const stage =\n background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n const rows: Seg[][] = [];\n let barCount = 0;\n for (const l of lines.length > 0 ? lines : [\"[out today].\"]) {\n const segs = parseLine(l, barCount);\n barCount += segs.filter((s) => s.hidden).length;\n rows.push(segs);\n }\n const hiBar = highlight ?? barCount - 1;\n\n const naturalEnd =\n T_LIFT + Math.max(0, barCount - 1) * LIFT_STEP + LIFT_DUR + HOLD;\n const pace = Math.max(1, naturalEnd / Math.max(1, durationInFrames));\n const t = frame * speed * pace;\n\n const texts: string[] = [];\n for (const segs of rows) {\n let prefix = \"\";\n for (const s of segs) {\n texts.push(prefix, s.text);\n prefix += s.text;\n }\n texts.push(prefix);\n }\n texts.push(slug, liftedSlug);\n const m = useMetrics(texts);\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const portrait = H > W * 1.1;\n const marginX = W * (portrait ? 0.07 : 0.06);\n const lineTexts = rows.map((segs) => segs.map((s) => s.text).join(\"\"));\n const maxW = Math.max(0.1, ...lineTexts.map((l) => m.w[l]));\n const size = Math.min(\n (W - marginX * 2) / maxW,\n (H * (portrait ? 0.52 : 0.68)) / (rows.length * LEAD),\n );\n const slugSize = Math.max(H * (portrait ? 0.018 : 0.034), size * 0.13);\n const slugGap = slugSize * 1.6;\n const blockH = rows.length * LEAD * size;\n const totalH = slugSize + slugGap + blockH;\n const top = (H - totalH) / 2 + slugSize * 0.2;\n const firstBase = top + slugSize + slugGap + m.cap * size;\n\n const boxTop = (base: number, s: number) =>\n base - ((1 - m.asc - m.desc) / 2 + m.asc) * s;\n\n const textStyle = (s: number): React.CSSProperties => ({\n position: \"absolute\",\n height: s,\n lineHeight: `${s}px`,\n whiteSpace: \"pre\",\n fontFamily: shoulders.fontFamily,\n fontWeight: WGHT,\n fontSize: s,\n });\n\n const nodes: React.ReactNode[] = [];\n\n rows.forEach((segs, r) => {\n const lineW = m.w[lineTexts[r]] * size;\n const left = (W - lineW) / 2;\n const base = firstBase + r * LEAD * size;\n const p = interpolate(t, [2 + r * 4, 22 + r * 4], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const dy = (1 - p) * size * 0.22;\n nodes.push(\n <div\n key={`line-${r}`}\n style={{\n ...textStyle(size),\n left,\n top: boxTop(base, size),\n opacity: p,\n transform: `translateY(${dy.toFixed(2)}px)`,\n color: c.ink,\n }}\n >\n {segs.map((s, i) => (\n <span\n key={`${r}-${i}`}\n style={{ color: s.hidden && s.bar === hiBar ? hi : c.ink }}\n >\n {s.text}\n </span>\n ))}\n </div>,\n );\n let prefix = \"\";\n segs.forEach((s, i) => {\n const x0 = left + m.w[prefix] * size;\n prefix += s.text;\n if (!s.hidden) return;\n const tw = m.w[s.text] * size;\n const padX = size * 0.012;\n const barTop = base - (m.cap + 0.05) * size;\n const barBottom =\n base + (Math.min(Math.max(m.dsc, 0.1), 0.24) + 0.02) * size;\n const startAt = T_LIFT + s.bar * LIFT_STEP;\n const g = interpolate(t, [startAt, startAt + LIFT_DUR], [1, 0], {\n ...CLAMP,\n easing: EASE_LIFT,\n });\n if (g <= 0) return;\n nodes.push(\n <div\n key={`bar-${r}-${i}`}\n style={{\n position: \"absolute\",\n left: x0 - padX,\n top: barTop,\n width: tw + padX * 2,\n height: barBottom - barTop,\n background: c.ink,\n opacity: p,\n transform: `translateY(${dy.toFixed(2)}px) scaleX(${g.toFixed(4)})`,\n transformOrigin: \"100% 50%\",\n }}\n />,\n );\n });\n });\n\n const slugBase = top + m.cap * slugSize;\n const slugIn = interpolate(t, [10, 26], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const flip = interpolate(t, [T_SLUG, T_SLUG + 12], [0, 1], {\n ...CLAMP,\n easing: EASE_LIFT,\n });\n const slugClipTop = slugBase - (m.cap + 0.2) * slugSize;\n const slugClipH = (m.cap + 0.2 + 0.3) * slugSize;\n const slugLine = (text: string, y: number, o: number, key: string) => (\n <div\n key={key}\n style={{\n ...textStyle(slugSize),\n left: (W - m.w[text] * slugSize) / 2,\n top: boxTop(slugBase, slugSize) - slugClipTop,\n color: c.ink,\n opacity: o,\n transform: `translateY(${y.toFixed(2)}px)`,\n }}\n >\n {text}\n </div>\n );\n const travel = slugClipH;\n nodes.push(\n <div\n key=\"slug\"\n style={{\n position: \"absolute\",\n left: 0,\n right: 0,\n top: slugClipTop,\n height: slugClipH,\n overflow: \"hidden\",\n opacity: slugIn,\n }}\n >\n {flip < 1\n ? slugLine(slug, -flip * travel, 0.6 * (1 - flip * 0.5), \"old\")\n : null}\n {flip > 0\n ? slugLine(liftedSlug, (1 - flip) * travel, 0.6 + 0.4 * flip, \"new\")\n : null}\n </div>,\n );\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {nodes}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/embargo-lift.tsx"
}
],
"type": "registry:component"
}