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": "Pulse Line",
"initialProps": null,
"slug": "pulse-line",
"sourceCode": "import { loadFont as loadInterTight } from \"@remotion/google-fonts/InterTight\";\nimport React, { forwardRef, useEffect, useId, 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 inter = loadInterTight(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\ninterface PulseLineProps {\n text?: string;\n highlight?: string;\n caption?: string;\n beats?: number;\n accent?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst AURORA = [\"#a0f0c8\", \"#3fb5a3\", \"#5147b6\", \"#b25c9c\"] as const;\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n ink: \"#F4F3F0\",\n flat: \"#9C9BA3\",\n muted: \"#8E8D94\",\n glow: [\"#F2FFF8\", AURORA[0], AURORA[1]],\n hl: (accent: string) =>\n `linear-gradient(100deg, ${AURORA[0]} 0%, ${AURORA[1]} 38%, ${accent} 78%, ${AURORA[3]} 100%)`,\n ground: (k: number) =>\n `radial-gradient(70% 55% at 50% 108%, rgba(63,181,163,${(0.1 + 0.1 * k).toFixed(3)}) 0%, rgba(81,71,182,${(0.06 + 0.05 * k).toFixed(3)}) 45%, transparent 75%)`,\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n ink: \"#111113\",\n flat: \"#55545A\",\n muted: \"#6E6C67\",\n glow: [\"#0B5E52\", \"#1E8C7C\", AURORA[2]],\n hl: (accent: string) =>\n `linear-gradient(100deg, #12806F 0%, #1E8C7C 30%, ${accent} 72%, #8C3A78 100%)`,\n ground: (k: number) =>\n `radial-gradient(70% 55% at 50% 108%, rgba(63,181,163,${(0.12 + 0.08 * k).toFixed(3)}) 0%, rgba(81,71,182,${(0.05 + 0.04 * k).toFixed(3)}) 45%, transparent 75%)`,\n grain: 0.035,\n },\n} as const;\n\nconst TRACK = -0.035;\nconst LINE_GAP = 1.1;\nconst FONT_PX = 200;\n\nconst WAVE = [\n { a: 0.1, c: 1.0, w: 0.5, tent: false },\n { a: -0.09, c: 2.25, w: 0.5, tent: true },\n { a: 0.62, c: 2.9, w: 0.85, tent: true },\n { a: -0.22, c: 3.6, w: 0.6, tent: true },\n { a: 0.16, c: 5.3, w: 0.85, tent: false },\n] as const;\nconst R_AT = 2.9;\nconst WAVE_LEN = 7.2;\nconst V = 0.42;\nconst FLAT_SCALE = 0.05;\nconst COOL = 11;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nfunction ecg(s: number) {\n let y = 0;\n for (const k of WAVE) {\n y += k.tent\n ? k.a * Math.max(0, 1 - Math.abs(s - k.c) / k.w)\n : k.a * Math.exp(-((s - k.c) ** 2) / (2 * k.w * k.w));\n }\n return y;\n}\n\nfunction mixHex(a: string, b: string, t: number) {\n const pa = Number.parseInt(a.slice(1), 16);\n const pb = Number.parseInt(b.slice(1), 16);\n const ch = (p: number, sh: number) => (p >> sh) & 255;\n const m = (sh: number) =>\n Math.round(ch(pa, sh) + (ch(pb, sh) - ch(pa, sh)) * t);\n return `rgb(${m(16)}, ${m(8)}, ${m(0)})`;\n}\n\nfunction heatColor(stops: readonly string[], ink: string, h: number) {\n const ramp = [ink, stops[2], stops[1], stops[0]];\n const x = Math.max(0, Math.min(1, h)) ** 1.4 * (ramp.length - 1);\n const i = Math.min(ramp.length - 2, Math.floor(x));\n return mixHex(ramp[i], ramp[i + 1], x - i);\n}\n\ninterface Metrics {\n width: (s: string) => number;\n offsets: (s: string) => number[];\n caption: number;\n baseline: number;\n}\n\nfunction useMetrics(caption: string) {\n const [m, setM] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"pulse-line: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n inter.waitUntilDone(),\n document.fonts.load(`500 100px \"${inter.fontFamily}\"`),\n document.fonts.load(`400 100px \"${inter.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"pulse-line: no 2d context\");\n ctx.font = `500 ${FONT_PX}px \"${inter.fontFamily}\"`;\n const fm = ctx.measureText(\"Hg\");\n const asc = fm.fontBoundingBoxAscent / FONT_PX;\n const desc = fm.fontBoundingBoxDescent / FONT_PX;\n const raw = (s: string) => ctx.measureText(s).width / FONT_PX;\n const width = (s: string) =>\n raw(s) + TRACK * Math.max(0, Array.from(s).length - 1);\n const offsets = (s: string) => {\n const chars = Array.from(s);\n return chars.map(\n (_, i) => raw(chars.slice(0, i).join(\"\")) + TRACK * i,\n );\n };\n ctx.font = `400 ${FONT_PX}px \"${inter.fontFamily}\"`;\n const cap = caption ? ctx.measureText(caption).width / FONT_PX : 0;\n setM({\n width,\n offsets,\n caption: cap,\n baseline: (1 - (asc + desc)) / 2 + asc,\n });\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [caption, handle]);\n return m;\n}\n\nfunction breakLines(words: string[], n: number, width: (s: string) => number) {\n if (n <= 1 || words.length <= 1) return [words.join(\" \")];\n let best: string[] = [words.join(\" \")];\n let bestW = Number.POSITIVE_INFINITY;\n const rec = (start: number, left: number, acc: string[]) => {\n if (left === 1) {\n const lines = [...acc, words.slice(start).join(\" \")];\n const w = Math.max(...lines.map(width));\n if (w < bestW) {\n bestW = w;\n best = lines;\n }\n return;\n }\n for (let k = start + 1; k <= words.length - left + 1; k++)\n rec(k, left - 1, [...acc, words.slice(start, k).join(\" \")]);\n };\n rec(0, Math.min(n, words.length), []);\n return best;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `pl${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{\n position: \"absolute\",\n inset: 0,\n opacity,\n mixBlendMode: \"overlay\",\n pointerEvents: \"none\",\n }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\n numOctaves={2}\n seed={11}\n />\n <feColorMatrix type=\"saturate\" values=\"0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\nfunction PulseLineBase({\n text = \"Every frame has a pulse.\",\n highlight = \"a pulse.\",\n caption = \"Motion components for Remotion. Copy one in, own every frame.\",\n beats = 2,\n accent = \"#3B5BFD\",\n speed = 1,\n theme = \"dark\",\n}: PulseLineProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const m = useMetrics(caption);\n\n const words = useMemo(() => text.split(/\\s+/).filter(Boolean), [text]);\n\n if (!m) {\n return <div style={{ position: \"absolute\", inset: 0, background: c.bg }} />;\n }\n\n const maxW = W * 0.86;\n const capH = caption ? 0.16 : 0;\n let lines: string[] = [text];\n let F = 0;\n for (let n = 1; n <= 3; n++) {\n const ls = breakLines(words, n, m.width);\n const wEm = Math.max(...ls.map(m.width));\n const hEm = (ls.length - 1) * LINE_GAP + 1.1;\n const f = Math.min(\n maxW / wEm,\n (H * (0.7 - capH)) / hEm,\n H * (n === 1 ? 0.24 : 0.19),\n );\n if (n === 1 || f > F * 1.15) {\n lines = ls;\n F = f;\n }\n if (n === 1 && f >= H * 0.17) break;\n }\n\n const hlStart = highlight ? text.indexOf(highlight) : -1;\n const hlEnd = hlStart >= 0 ? hlStart + highlight.length : -1;\n type G = {\n ch: string;\n line: number;\n x: number;\n adv: number;\n strip: number;\n hl: boolean;\n };\n const glyphs: G[] = [];\n let cursor = 0;\n const lineW = lines.map(m.width);\n const blockW = Math.max(...lineW);\n for (let li = 0; li < lines.length; li++) {\n const s = lines[li];\n const offs = m.offsets(s);\n const lw = lineW[li];\n const chars = Array.from(s);\n const at = text.indexOf(s, cursor);\n const pad = (blockW - lw) / 2;\n chars.forEach((ch, i) => {\n const next = i + 1 < chars.length ? offs[i + 1] : lw + TRACK;\n const adv = next - offs[i];\n const gi = at + i;\n glyphs.push({\n ch,\n line: li,\n x: offs[i],\n adv,\n strip: pad + offs[i] + adv / 2,\n hl: gi >= hlStart && gi < hlEnd,\n });\n });\n cursor = at + s.length;\n }\n const stripLen = blockW;\n const hlBox = new Map<number, { x0: number; x1: number }>();\n for (const g of glyphs) {\n if (!g.hl || g.ch === \" \") continue;\n const b = hlBox.get(g.line) ?? { x0: g.x, x1: g.x + g.adv };\n b.x0 = Math.min(b.x0, g.x);\n b.x1 = Math.max(b.x1, g.x + g.adv);\n hlBox.set(g.line, b);\n }\n\n const nBeats = Math.max(1, Math.min(4, Math.round(beats)));\n const run = (stripLen + WAVE_LEN + 1) / V;\n const period = Math.max(34, run + 4);\n const beatAt = (b: number) => 6 + b * period;\n const front = (b: number) => -1 + (t - beatAt(b)) * V;\n const endT = beatAt(nBeats - 1) + run;\n\n const blockH = (lines.length - 1) * LINE_GAP * F + F;\n const capGap = Math.max(F * 0.42, H * 0.06);\n const capSize = Math.min(\n Math.max(F * 0.17, H * 0.035),\n H * 0.044,\n (W * 0.86) / Math.max(0.1, m.caption),\n );\n const totalH = blockH + (caption ? capGap + capSize : 0);\n const top0 = (H - totalH) / 2;\n const capAt = beatAt(nBeats - 1) + run * 0.45;\n\n let breathe = 0;\n for (let b = 0; b < nBeats; b++) {\n const tr = beatAt(b) + (stripLen / 2 + R_AT + 1) / V;\n const d = t - tr;\n if (d > -4) breathe = Math.max(breathe, Math.exp(-((d + 0) ** 2) / 120));\n }\n\n const nodes: React.ReactNode[] = [];\n glyphs.forEach((g, i) => {\n if (g.ch === \" \") return;\n const lw = lineW[g.line];\n const left = (W - lw * F) / 2 + g.x * F;\n const baseY = top0 + g.line * LINE_GAP * F + m.baseline * F;\n\n let y = 0;\n let heat = 0;\n let alive = 0;\n let hlOn = 0;\n for (let b = 0; b < nBeats; b++) {\n const s = front(b) - g.strip;\n if (s < -0.5) continue;\n y += ecg(s);\n const since = (s - R_AT) / V;\n if (since > -1.5) {\n heat = Math.max(\n heat,\n since < 0 ? 1 + since / 1.5 : Math.exp(-since / COOL),\n );\n }\n if (b === 0)\n alive = interpolate(s, [R_AT - 0.35, R_AT + 0.25], [0, 1], CLAMP);\n if (b === nBeats - 1 && g.hl)\n hlOn = interpolate(since, [0, 12], [0, 1], CLAMP);\n }\n const spike = Math.max(0, y) / WAVE[2].a;\n const sy = FLAT_SCALE + (1 - FLAT_SCALE) * alive + spike * 0.22 * alive;\n const sx = 1 - spike * 0.06;\n const dy = -y * F * (lines.length > 1 ? 0.8 : 1);\n const ink = alive > 0.02 ? c.ink : c.flat;\n const restInk = mixHex(c.flat, c.ink, alive);\n const col =\n heat > 0.001\n ? heatColor(c.glow, ink === c.ink ? c.ink : restInk, heat)\n : restInk;\n\n const style: React.CSSProperties = {\n position: \"absolute\",\n left,\n top: baseY - m.baseline * F,\n fontFamily: inter.fontFamily,\n fontWeight: 500,\n fontSize: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n transformOrigin: `${((g.adv / 2) * F).toFixed(2)}px ${(m.baseline * F).toFixed(2)}px`,\n transform: `translateY(${dy.toFixed(2)}px) scale(${sx.toFixed(4)}, ${sy.toFixed(4)})`,\n };\n nodes.push(\n <div key={`g${i}`} style={{ ...style, color: col }}>\n {g.ch}\n </div>,\n );\n if (g.hl && hlOn > 0) {\n const box = hlBox.get(g.line);\n const bw = box ? (box.x1 - box.x0) * F : g.adv * F;\n const bx = box ? (g.x - box.x0) * F : 0;\n nodes.push(\n <div\n key={`h${i}`}\n style={{\n ...style,\n color: \"transparent\",\n backgroundImage: c.hl(accent),\n backgroundSize: `${bw.toFixed(2)}px 100%`,\n backgroundPosition: `${(-bx).toFixed(2)}px 0`,\n backgroundRepeat: \"no-repeat\",\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n opacity: hlOn * (1 - Math.min(1, heat * 0.6)),\n }}\n >\n {g.ch}\n </div>,\n );\n }\n });\n\n const capP = interpolate(t, [capAt, capAt + 20], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const settled = interpolate(t, [endT, endT + 30], [0, 1], CLAMP);\n\n return (\n <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: c.ground(Math.max(breathe, settled * 0.35)),\n }}\n />\n {nodes}\n {caption ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: top0 + blockH + capGap,\n textAlign: \"center\",\n fontFamily: inter.fontFamily,\n fontWeight: 400,\n fontSize: capSize,\n letterSpacing: \"-0.01em\",\n lineHeight: 1.2,\n color: c.muted,\n opacity: capP,\n transform: `translateY(${((1 - capP) * capSize * 0.7).toFixed(2)}px)`,\n }}\n >\n {caption}\n </div>\n ) : null}\n <Grain opacity={c.grain} />\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 accent: {\n type: \"color\",\n default: \"#3B5BFD\",\n description: \"Accent\",\n },\n text: {\n type: \"text-content\",\n default: \"Every frame has a pulse.\",\n description: \"Text\",\n },\n highlight: {\n type: \"text-content\",\n default: \"a pulse.\",\n description: \"Highlight\",\n },\n caption: {\n type: \"text-content\",\n default: \"Motion components for Remotion. Copy one in, own every frame.\",\n description: \"Caption\",\n },\n beats: {\n type: \"number\",\n default: 2,\n min: 0,\n max: 10,\n step: 1,\n description: \"Beats\",\n hiddenFromList: false,\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\",\"accent\",\"text\",\"highlight\",\"caption\",\"beats\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n text: \"Every frame has a pulse.\",\n highlight: \"a pulse.\",\n caption: \"Motion components for Remotion. Copy one in, own every frame.\",\n beats: 2,\n speed: 1,\n};\n\ntype PulseLineElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof PulseLineBase>;\n\nconst PulseLineInner = forwardRef<\n HTMLDivElement,\n PulseLineElementProps & { 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 ?? \"<PulseLine>\"}\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 <PulseLineBase\n {...(componentProps as unknown as ComponentProps<typeof PulseLineBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const PulseLine = Interactive.withSchema({\n Component: PulseLineInner,\n componentName: \"<PulseLine>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 103,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 103
}