Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [
{
"name": "@remotion/google-fonts",
"version": null
}
],
"dimensions": null,
"displayName": "Coy Denial",
"initialProps": null,
"slug": "coy-denial",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/FunnelDisplay\";\nimport { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, continueRender, delayRender, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst funnel = loadFont(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\ninterface CoyDenialRound {\n say: string;\n aside: string;\n}\n\ninterface CoyDenialProps {\n rounds?: CoyDenialRound[];\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_ROUNDS: CoyDenialRound[] = [\n { say: \"Nothing is launching on Thursday.\", aside: \"(Something is.)\" },\n { say: \"Don’t check the site at nine.\", aside: \"(Do.)\" },\n];\n\nconst THEMES = {\n dark: { bg: \"#0B0B0F\", ink: \"#FFFFFF\", accent: \"#B79CFF\" },\n light: { bg: \"#FAFAFA\", ink: \"#121216\", accent: \"#6B4FD8\" },\n} as const;\n\nconst SAY_W = 500;\nconst ASIDE_W = 400;\nconst TRACK = -0.035;\nconst ASIDE_TRACK = -0.01;\nconst PITCH = 1.0;\nconst MEASURE_PX = 100;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN = Easing.bezier(0.55, 0, 0.8, 0.2);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst SAY_LEN = 15;\nconst SAY_STAGGER = 3;\nconst ASIDE_AT = 48;\nconst ASIDE_GAP = 7;\nconst ASIDE_LEN = 10;\nconst OUT_MIN = 84;\nconst READ_HOLD = 28;\nconst ROUND_GAP = 12;\nconst OUT_LEN = 10;\nconst MIN_HOLD = 36;\n\nlet measureCtx: CanvasRenderingContext2D | null = null;\n\nfunction em(s: string, weight: number, track: number) {\n if (!measureCtx) {\n measureCtx = document.createElement(\"canvas\").getContext(\"2d\");\n }\n if (!measureCtx) throw new Error(\"coy-denial: no 2d context\");\n measureCtx.font = `${weight} ${MEASURE_PX}px \"${funnel.fontFamily}\"`;\n return (\n measureCtx.measureText(s).width / MEASURE_PX + track * Array.from(s).length\n );\n}\n\nfunction useFontsReady() {\n const [ready, setReady] = useState(false);\n const [handle] = useState(() => delayRender(\"coy-denial: fonts\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n funnel.waitUntilDone(),\n document.fonts.load(`${SAY_W} 100px \"${funnel.fontFamily}\"`),\n document.fonts.load(`${ASIDE_W} 100px \"${funnel.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (live) setReady(true);\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [handle]);\n return ready;\n}\n\ninterface Row {\n words: { text: string; x: number }[];\n w: number;\n}\n\nfunction split(s: string) {\n return s.split(/\\s+/).filter(Boolean);\n}\n\nfunction sayW(words: string[]) {\n return em(words.join(\" \"), SAY_W, TRACK);\n}\n\nfunction toRow(words: string[], weight: number, track: number): Row {\n const space = em(\" \", weight, track);\n let x = 0;\n const out = words.map((text) => {\n const at = x;\n x += em(text, weight, track) + space;\n return { text, x: at };\n });\n return { words: out, w: em(words.join(\" \"), weight, track) };\n}\n\nfunction balanced(words: string[], n: number): string[][] {\n if (n <= 1) return [words];\n let best: string[][] = [words];\n let bestW = Number.POSITIVE_INFINITY;\n let bestSlack = Number.POSITIVE_INFINITY;\n const walk = (start: number, left: number, acc: string[][]) => {\n if (left === 1) {\n const rows = [...acc, words.slice(start)];\n const widths = rows.map(sayW);\n const w = Math.max(...widths);\n const slack = widths.reduce((a, x) => a + (w - x) ** 2, 0);\n if (w < bestW - 0.01 || (w < bestW + 0.01 && slack < bestSlack)) {\n bestW = Math.min(w, bestW);\n bestSlack = slack;\n best = rows;\n }\n return;\n }\n for (let i = start + 1; i <= words.length - left + 1; i++) {\n walk(i, left - 1, [...acc, words.slice(start, i)]);\n }\n };\n walk(0, n, []);\n return best;\n}\n\nfunction wrapAside(s: string, maxEm: number): Row[] {\n const rows: string[][] = [];\n let cur: string[] = [];\n for (const w of split(s)) {\n const next = [...cur, w];\n if (cur.length > 0 && em(next.join(\" \"), ASIDE_W, ASIDE_TRACK) > maxEm) {\n rows.push(cur);\n cur = [w];\n } else {\n cur = next;\n }\n }\n if (cur.length) rows.push(cur);\n return rows.map((r) => toRow(r, ASIDE_W, ASIDE_TRACK));\n}\n\nfunction fitSay(say: string, W: number, H: number, portrait: boolean) {\n const words = split(say);\n const maxN = Math.min(words.length, portrait ? 6 : 3);\n let rows: string[][] = [words];\n let F = 0;\n for (let n = 1; n <= maxN; n++) {\n const cand = balanced(words, n);\n const w = Math.max(...cand.map(sayW));\n const f = Math.min(\n (W * (portrait ? 0.84 : 0.86)) / w,\n (H * (portrait ? 0.46 : 0.6)) / ((n - 1) * PITCH + 1),\n );\n if (f > F * 1.08) {\n F = f;\n rows = cand;\n }\n }\n return { rows, F };\n}\n\nfunction buildLayout(rounds: CoyDenialRound[], W: number, H: number) {\n const portrait = H > W * 1.1;\n const fits = rounds.map((r) => fitSay(r.say, W, H, portrait));\n const F = Math.min(...fits.map((f) => f.F));\n const says = fits.map((f) => f.rows.map((r) => toRow(r, SAY_W, TRACK)));\n const FA = Math.min(W, H) * (portrait ? 0.05 : 0.046);\n const asides = rounds.map((r) =>\n wrapAside(r.aside, (W * (portrait ? 0.6 : 0.36)) / FA),\n );\n return { says, asides, F, FA, portrait };\n}\n\nfunction CoyDenialBase({\n rounds = DEFAULT_ROUNDS,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: CoyDenialProps) {\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 const ready = useFontsReady();\n\n const layout = useMemo(\n () => (ready ? buildLayout(rounds, W, H) : null),\n [ready, rounds, W, H],\n );\n\n if (!layout) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const { F, FA, portrait } = layout;\n const n = layout.says.length;\n const plan = layout.asides.map((rows) => {\n const words = rows.reduce((acc, r) => acc + r.words.length, 0);\n const gap = Math.max(3, Math.min(ASIDE_GAP, 36 / Math.max(1, words)));\n const end = ASIDE_AT + (words - 1) * gap + ASIDE_LEN;\n return { gap, end, out: Math.max(OUT_MIN, end + READ_HOLD) };\n });\n const starts: number[] = [];\n plan.reduce((acc, p) => {\n starts.push(acc);\n return acc + p.out + ROUND_GAP;\n }, 0);\n const motionEnd = starts[n - 1] + plan[n - 1].end;\n const room = durationInFrames * speed - MIN_HOLD;\n const k = Math.max(0.6, Math.min(1, room / motionEnd));\n const t = (frame * speed) / k;\n\n const mx = W * (portrait ? 0.08 : 0.065);\n const my = H * (portrait ? 0.07 : 0.1);\n const rowH = F * 1.18;\n const clipTop = -F * 0.06;\n\n const nodes = layout.says.map((rows, ri) => {\n const s = starts[ri];\n const { gap: aGap, out: outAt } = plan[ri];\n const local = t - s;\n const isLast = ri === n - 1;\n if (local < -2) return null;\n if (!isLast && local > outAt + OUT_LEN + 4) return null;\n\n const out = isLast\n ? 0\n : interpolate(local, [outAt, outAt + OUT_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_IN,\n });\n\n let wi = 0;\n const sayNodes = rows.map((row, li) => (\n <div\n key={`s-${ri}-${li}`}\n style={{\n position: \"absolute\",\n left: mx - F * 0.1,\n top: my + li * PITCH * F + clipTop,\n width: row.w * F + F * 0.3,\n height: rowH,\n overflow: \"hidden\",\n }}\n >\n {row.words.map((w) => {\n const i = wi++;\n const q = interpolate(\n local,\n [i * SAY_STAGGER, i * SAY_STAGGER + SAY_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const dy = (1 - q) * rowH - out * rowH;\n return (\n <div\n key={`sw-${ri}-${i}`}\n style={{\n position: \"absolute\",\n left: w.x * F + F * 0.1,\n top: -clipTop,\n height: F,\n fontFamily: funnel.fontFamily,\n fontWeight: SAY_W,\n fontSize: F,\n lineHeight: `${F}px`,\n letterSpacing: `${TRACK}em`,\n whiteSpace: \"pre\",\n color: c.ink,\n transform: `translateY(${dy.toFixed(2)}px)`,\n }}\n >\n {w.text}\n </div>\n );\n })}\n </div>\n ));\n\n const asideRows = layout.asides[ri];\n const asideFade = isLast\n ? 1\n : interpolate(local, [outAt - 6, outAt + 2], [1, 0], CLAMP);\n let ai = 0;\n const asideNodes = asideRows.flatMap((arow, ar) => {\n const ax = W - mx - arow.w * FA;\n const ay = H - my - FA - (asideRows.length - 1 - ar) * FA * 1.22;\n return arow.words.map((w) => {\n const i = ai++;\n const at = ASIDE_AT + i * aGap;\n const q = interpolate(local, [at, at + ASIDE_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n return (\n <div\n key={`a-${ri}-${i}`}\n style={{\n position: \"absolute\",\n left: ax + w.x * FA,\n top: ay,\n height: FA,\n fontFamily: funnel.fontFamily,\n fontWeight: ASIDE_W,\n fontSize: FA,\n lineHeight: `${FA}px`,\n letterSpacing: `${ASIDE_TRACK}em`,\n whiteSpace: \"pre\",\n color: hi,\n opacity: q * asideFade,\n transform: `translateY(${((1 - q) * FA * 0.35).toFixed(2)}px)`,\n }}\n >\n {w.text}\n </div>\n );\n });\n });\n\n return (\n <div key={`r-${ri}`} style={{ position: \"absolute\", inset: 0 }}>\n {sayNodes}\n {asideNodes}\n </div>\n );\n });\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {nodes}\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n theme: {\n type: \"enum\",\n default: \"dark\",\n variants: {\n dark: {},\n light: {},\n },\n description: \"Theme\",\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"theme\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n speed: 1,\n};\n\ntype CoyDenialElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CoyDenialBase>;\n\nconst CoyDenialInner = forwardRef<\n HTMLDivElement,\n CoyDenialElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<CoyDenial>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <CoyDenialBase\n {...(componentProps as unknown as ComponentProps<typeof CoyDenialBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CoyDenial = Interactive.withSchema({\n Component: CoyDenialInner,\n componentName: \"<CoyDenial>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 144,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 144
}