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": "no-buts",
"title": "No Buts",
"description": "A hesitant \"But...\" is answered by a yellow \"Go on. We'll wait.\".",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/no-buts/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/HubotSans\";\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 hubot = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface NoButsExchange {\n objection: string;\n reply: string;\n}\n\nexport interface NoButsProps {\n exchanges?: NoButsExchange[];\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_EXCHANGES: NoButsExchange[] = [\n {\n objection: \"But I’m not a motion designer.\",\n reply: \"You don’t need to be.\",\n },\n { objection: \"But I’m busy.\", reply: \"It takes one lunch.\" },\n { objection: \"But…\", reply: \"Go on. We’ll wait.\" },\n];\n\nconst THEMES = {\n dark: {\n bg: \"#1C1C1E\",\n ink: \"#FFFFFF\",\n muted: \"#A9A9AE\",\n accent: \"#FFE14D\",\n },\n light: {\n bg: \"#FFFBEA\",\n ink: \"#17150F\",\n muted: \"#6E6857\",\n accent: \"#9A7A00\",\n },\n} as const;\n\nconst TRACK = -0.025;\nconst LH = 1.08;\nconst OBJ_WORD = 3;\nconst REPLY_WORD = 2.5;\nconst RISE = 13;\nconst EXIT = 10;\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 CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction breakLines(ws: number[], space: number, maxEm: number) {\n const n = ws.length;\n if (n === 0) return [] as number[][];\n let count = 1;\n let x = 0;\n for (let i = 0; i < n; i++) {\n if (x > 0 && x + space + ws[i] > maxEm) {\n count++;\n x = ws[i];\n } else {\n x += (x > 0 ? space : 0) + ws[i];\n }\n }\n if (count === 1) return [ws.map((_, i) => i)];\n const lineW = (i: number, j: number) => {\n let s = 0;\n for (let k = i; k < j; k++) s += ws[k] + (k > i ? space : 0);\n return s;\n };\n const avg = lineW(0, n) / count;\n const INF = 1e12;\n const dp = Array.from({ length: count + 1 }, () =>\n new Array<number>(n + 1).fill(INF),\n );\n const back = Array.from({ length: count + 1 }, () =>\n new Array<number>(n + 1).fill(0),\n );\n dp[0][0] = 0;\n for (let l = 1; l <= count; l++) {\n for (let j = 1; j <= n; j++) {\n for (let i = l - 1; i < j; i++) {\n if (dp[l - 1][i] >= INF) continue;\n const lw = lineW(i, j);\n if (lw > maxEm + 1e-6 && j - i > 1) continue;\n const cost = (lw - avg) ** 2;\n if (dp[l - 1][i] + cost < dp[l][j]) {\n dp[l][j] = dp[l - 1][i] + cost;\n back[l][j] = i;\n }\n }\n }\n }\n if (dp[count][n] >= INF) return [ws.map((_, i) => i)];\n const starts: number[] = [];\n let j = n;\n for (let l = count; l > 0; l--) {\n const i = back[l][j];\n starts.unshift(i);\n j = i;\n }\n return starts.map((s, l) => {\n const e = l + 1 < starts.length ? starts[l + 1] : n;\n return Array.from({ length: e - s }, (_, k) => s + k);\n });\n}\n\nfunction useWidths(specs: string[]) {\n const key = specs.join(\"\\u0001\");\n const [state, setState] = useState<{\n key: string;\n w: Record<string, number>;\n } | null>(null);\n const [handle] = useState(() => delayRender(\"no-buts: measuring\"));\n const released = useRef(false);\n const ref = useRef(specs);\n ref.current = specs;\n useEffect(() => {\n let live = true;\n Promise.all([\n hubot.waitUntilDone(),\n document.fonts.load(`400 100px \"${hubot.fontFamily}\"`),\n document.fonts.load(`500 100px \"${hubot.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n const w: Record<string, number> = {};\n for (const spec of ref.current) {\n const cut = spec.indexOf(\"|\");\n const weight = spec.slice(0, cut);\n const text = spec.slice(cut + 1);\n if (ctx) ctx.font = `${weight} 100px \"${hubot.fontFamily}\"`;\n w[spec] = ctx ? ctx.measureText(text).width / 100 : text.length * 0.5;\n }\n setState({ key, w });\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.w : null;\n}\n\ninterface Placed {\n text: string;\n x: number;\n line: number;\n}\n\nfunction layout(\n words: string[],\n adv: (s: string) => number,\n space: number,\n maxEm: number,\n align: \"left\" | \"right\",\n) {\n const ws = words.map(adv);\n const lines = breakLines(ws, space, maxEm);\n const placed: Placed[] = [];\n let widest = 0;\n lines.forEach((idx, line) => {\n let lw = 0;\n idx.forEach((k, m) => {\n lw += ws[k] + (m > 0 ? space : 0);\n });\n widest = Math.max(widest, lw);\n let x = align === \"right\" ? -lw : 0;\n idx.forEach((k, m) => {\n if (m > 0) x += space;\n placed.push({ text: words[k], x, line });\n x += ws[k];\n });\n });\n return { placed, lines: lines.length, widest };\n}\n\nexport function NoButs({\n exchanges = DEFAULT_EXCHANGES,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: NoButsProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, durationInFrames: T } = 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 list = exchanges.length > 0 ? exchanges : DEFAULT_EXCHANGES;\n const objWords = list.map((e) => e.objection.trim().split(/\\s+/));\n const replyWords = list.map((e) => e.reply.trim().split(/\\s+/));\n const specs = Array.from(\n new Set([\n \"400| \",\n \"500| \",\n ...objWords.flat().map((s) => `400|${s}`),\n ...replyWords.flat().map((s) => `500|${s}`),\n ]),\n );\n const w = useWidths(specs);\n\n if (!w) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const advO = (s: string) =>\n (w[`400|${s}`] ?? 0) + TRACK * Array.from(s).length;\n const advR = (s: string) =>\n (w[`500|${s}`] ?? 0) + TRACK * Array.from(s).length;\n const spaceO = (w[\"400| \"] ?? 0.25) + 0.04;\n const spaceR = (w[\"500| \"] ?? 0.25) + 0.04;\n\n const portrait = H > W * 1.1;\n const mx = W * (portrait ? 0.08 : 0.07);\n const my = H * (portrait ? 0.09 : 0.1);\n const objMax = W * (portrait ? 0.8 : 0.56);\n const replyMax = W * (portrait ? 0.84 : 0.72);\n const objLinesMax = portrait ? 4 : 3;\n const replyLinesMax = portrait ? 3 : 2;\n\n let Fo = portrait ? W * 0.09 : H * 0.095;\n let objLays = objWords.map((ws) =>\n layout(ws, advO, spaceO, objMax / Fo, \"right\"),\n );\n for (let k = 0; k < 60; k++) {\n if (Math.max(...objLays.map((l) => l.lines)) <= objLinesMax) break;\n Fo *= 0.96;\n objLays = objWords.map((ws) =>\n layout(ws, advO, spaceO, objMax / Fo, \"right\"),\n );\n }\n\n let Fr = portrait ? W * 0.13 : H * 0.16;\n let replyLays = replyWords.map((ws) =>\n layout(ws, advR, spaceR, replyMax / Fr, \"left\"),\n );\n for (let k = 0; k < 60; k++) {\n if (Math.max(...replyLays.map((l) => l.lines)) <= replyLinesMax) break;\n Fr *= 0.96;\n replyLays = replyWords.map((ws) =>\n layout(ws, advR, spaceR, replyMax / Fr, \"left\"),\n );\n }\n\n const objStart: number[] = [];\n const replyStart: number[] = [];\n const replyDone: number[] = [];\n let clock = 6;\n list.forEach((_, i) => {\n objStart.push(clock);\n const nO = objWords[i].length;\n clock += nO * OBJ_WORD + RISE;\n clock += nO <= 1 ? 22 : 4;\n replyStart.push(clock);\n clock += replyWords[i].length * REPLY_WORD + RISE;\n replyDone.push(clock);\n clock += i < list.length - 1 ? 26 : 0;\n });\n const room = Math.max(1, T - Math.max(30, T * 0.18));\n const k = clock > room ? room / clock : 1;\n\n const lineO = Fo * LH;\n const lineR = Fr * LH;\n\n return (\n <AbsoluteFill\n style={{\n background: stage,\n overflow: \"hidden\",\n fontFamily: hubot.fontFamily,\n }}\n >\n {list.map((_, i) => {\n const last = i === list.length - 1;\n const leaveAt = last ? 1e9 : (objStart[i + 1] - EXIT - 2) * k;\n const leave = interpolate(t, [leaveAt, leaveAt + EXIT * k], [0, 1], {\n ...CLAMP,\n easing: EASE_IN,\n });\n if (t < objStart[i] * k - 1 || leave >= 1) return null;\n const oLay = objLays[i];\n const rLay = replyLays[i];\n const rTop = H - my - rLay.lines * lineR;\n const replyColor = last ? hi : c.ink;\n return (\n <div\n key={`x${i}`}\n style={{\n position: \"absolute\",\n inset: 0,\n opacity: 1 - leave,\n transform: `translate(${(-leave * W * 0.025).toFixed(2)}px, ${(-leave * H * 0.05).toFixed(2)}px)`,\n }}\n >\n {oLay.placed.map((p, j) => {\n const at = (objStart[i] + j * OBJ_WORD) * k;\n const e = interpolate(t, [at, at + RISE], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n return (\n <div\n key={`o${j}`}\n style={{\n position: \"absolute\",\n left: W - mx + p.x * Fo,\n top: my + p.line * lineO,\n fontSize: Fo,\n lineHeight: `${lineO}px`,\n fontWeight: 400,\n letterSpacing: `${TRACK}em`,\n whiteSpace: \"pre\",\n color: c.muted,\n opacity: e,\n transform: `translateY(${((1 - e) * Fo * 0.3).toFixed(2)}px)`,\n }}\n >\n {p.text}\n </div>\n );\n })}\n {rLay.placed.map((p, j) => {\n const at = (replyStart[i] + j * REPLY_WORD) * k;\n const e = interpolate(t, [at, at + RISE], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n return (\n <div\n key={`r${j}`}\n style={{\n position: \"absolute\",\n left: mx + p.x * Fr,\n top: rTop + p.line * lineR,\n fontSize: Fr,\n lineHeight: `${lineR}px`,\n fontWeight: 500,\n letterSpacing: `${TRACK}em`,\n whiteSpace: \"pre\",\n color: replyColor,\n opacity: e,\n transform: `translateY(${((1 - e) * Fr * 0.22).toFixed(2)}px)`,\n }}\n >\n {p.text}\n </div>\n );\n })}\n </div>\n );\n })}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/no-buts.tsx"
}
],
"type": "registry:component"
}