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": "Comet Headline",
"initialProps": null,
"slug": "comet-headline",
"sourceCode": "import { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadSora } from \"@remotion/google-fonts/Sora\";\nimport React, { forwardRef, useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst sora = loadSora(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\nconst mono = loadGeistMono(\"normal\", {\n weights: [\"500\"],\n subsets: [\"latin\"],\n});\n\ninterface CometHeadlineProps {\n eyebrow?: string;\n headline?: string;\n highlight?: string;\n subhead?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst LIMB = [\"#e9ecff\", \"#8a8bff\", \"#4b2bd6\", \"#160c3a\"] as const;\n\nconst PALETTES = {\n dark: {\n bg: \"#0A0A0B\",\n fg: \"#F4F3F0\",\n muted: \"#8E8D94\",\n trail: LIMB[1],\n head: \"#FFFFFF\",\n highlight: (accent: string) =>\n `linear-gradient(90deg, ${LIMB[0]} 0%, #b7b8ff 30%, ${LIMB[1]} 60%, color-mix(in oklab, ${accent} 55%, ${LIMB[1]}) 85%, ${LIMB[0]} 100%)`,\n ground: [\n `radial-gradient(75% 95% at 106% 112%, color-mix(in oklab, ${LIMB[2]} 42%, transparent) 0%, color-mix(in oklab, ${LIMB[3]} 55%, transparent) 42%, transparent 78%)`,\n `radial-gradient(28% 40% at 98% 104%, color-mix(in oklab, ${LIMB[1]} 22%, transparent) 0%, transparent 80%)`,\n ],\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n fg: \"#111113\",\n muted: \"#6E6C67\",\n trail: LIMB[2],\n head: LIMB[2],\n highlight: (accent: string) =>\n `linear-gradient(90deg, ${LIMB[2]} 0%, ${accent} 36%, #6f6ff0 64%, ${LIMB[1]} 84%, ${LIMB[2]} 100%)`,\n ground: [\n `radial-gradient(75% 95% at 106% 112%, color-mix(in oklab, ${LIMB[1]} 26%, transparent) 0%, color-mix(in oklab, ${LIMB[0]} 50%, transparent) 45%, transparent 78%)`,\n ],\n grain: 0.035,\n },\n} as const;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_FLIGHT = Easing.bezier(0.33, 0.1, 0.12, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst SORA_500 = [\n 222, 303, 452, 702, 652, 864, 702, 264, 382, 382, 568, 592, 266, 506, 266,\n 365, 750, 423, 623, 620, 652, 630, 668, 585, 647, 668, 266, 266, 592, 590,\n 592, 556, 1124, 765, 684, 797, 788, 598, 560, 832, 803, 320, 641, 703, 549,\n 937, 858, 865, 649, 865, 710, 682, 602, 785, 719, 1052, 705, 654, 652, 382,\n 365, 382, 587, 581, 300, 581, 694, 608, 694, 616, 380, 679, 644, 317, 324,\n 595, 296, 973, 644, 678, 694, 694, 414, 543, 429, 634, 572, 873, 574, 555,\n 493, 382, 375, 382, 511,\n];\nconst ASC = 0.97;\nconst DESC = 0.29;\nconst TRACK = -0.035;\nconst LINE = 1.06;\n\nfunction textEm(text: string, tracking = TRACK) {\n let w = 0;\n for (const ch of text) {\n const c = ch.charCodeAt(0);\n w += (c >= 32 && c <= 126 ? SORA_500[c - 32] : 640) / 1000 + tracking;\n }\n return w;\n}\n\ninterface Word {\n text: string;\n index: number;\n line: number;\n x: number;\n w: number;\n hl: [number, number] | null;\n}\n\nfunction layout(headline: string, highlight: string, maxEm: number) {\n const lower = headline.toLowerCase();\n const hStart = highlight ? lower.indexOf(highlight.toLowerCase()) : -1;\n const hEnd = hStart >= 0 ? hStart + highlight.length : -1;\n const hLen = Math.max(1, hEnd - hStart);\n const space = textEm(\" \");\n const words: Word[] = [];\n let line = 0;\n let x = 0;\n let index = 0;\n const re = /\\S+|\\n/g;\n for (let m = re.exec(headline); m; m = re.exec(headline)) {\n if (m[0] === \"\\n\") {\n if (x > 0) line += 1;\n x = 0;\n continue;\n }\n const w = textEm(m[0]);\n if (x > 0 && x + space + w > maxEm) {\n line += 1;\n x = 0;\n }\n const left = x > 0 ? x + space : 0;\n const a = m.index;\n const b = a + m[0].length;\n const inside = hStart >= 0 && a < hEnd && b > hStart;\n words.push({\n text: m[0],\n index: index++,\n line,\n x: left,\n w,\n hl: inside\n ? [\n (Math.max(a, hStart) - hStart) / hLen,\n (Math.min(b, hEnd) - hStart) / hLen,\n ]\n : null,\n });\n x = left + w;\n }\n const lines = words.length ? words[words.length - 1].line + 1 : 1;\n const widths = Array.from({ length: lines }, (_, l) =>\n words\n .filter((w) => w.line === l)\n .reduce((m, w) => Math.max(m, w.x + w.w), 0),\n );\n return { words, lines, widths };\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\n numOctaves={2}\n seed={11}\n stitchTiles=\"stitch\"\n />\n <feColorMatrix values=\"0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0.9 0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\ntype Pt = { x: number; y: number };\n\nfunction quad(a: Pt, c: Pt, b: Pt, t: number): Pt {\n const u = 1 - t;\n return {\n x: u * u * a.x + 2 * u * t * c.x + t * t * b.x,\n y: u * u * a.y + 2 * u * t * c.y + t * t * b.y,\n };\n}\n\nfunction quadSlice(a: Pt, c: Pt, b: Pt, t0: number, t1: number) {\n const p0 = quad(a, c, b, t0);\n const p1 = quad(a, c, b, t1);\n const blossom = (s: number, t: number) => ({\n x:\n (1 - s) * (1 - t) * a.x + ((1 - s) * t + s * (1 - t)) * c.x + s * t * b.x,\n y:\n (1 - s) * (1 - t) * a.y + ((1 - s) * t + s * (1 - t)) * c.y + s * t * b.y,\n });\n const q = blossom(t0, t1);\n return `M ${p0.x.toFixed(2)} ${p0.y.toFixed(2)} Q ${q.x.toFixed(2)} ${q.y.toFixed(2)} ${p1.x.toFixed(2)} ${p1.y.toFixed(2)}`;\n}\n\nfunction highlightFill(\n [a, b]: [number, number],\n drift: number,\n image: string,\n): React.CSSProperties {\n const f = Math.max(0.02, b - a);\n const K = 1.6 / f;\n const o = drift * 0.35;\n const P = (a / f + o * K) / (K - 1);\n return {\n backgroundImage: image,\n backgroundSize: `${K * 100}% 100%`,\n backgroundPosition: `${P * 100}% 0%`,\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n color: \"transparent\",\n };\n}\n\nfunction CometHeadlineBase({\n eyebrow = \"New in remocn\",\n headline = \"Every launch beat, already in orbit.\",\n highlight = \"in orbit\",\n subhead = \"Reveals, feature heads and stats as drop-in Remotion scenes.\",\n accent = \"#3B5BFD\",\n background,\n speed = 1,\n theme = \"dark\",\n}: CometHeadlineProps) {\n const raw = useCurrentFrame();\n const frame = raw * speed;\n const { width, height, durationInFrames } = useVideoConfig();\n const p = PALETTES[theme];\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n\n const portrait = height > width * 1.1;\n const s = portrait\n ? (width / 1280) * 1.55\n : Math.min(width / 1280, height / 720);\n const padX = width * (portrait ? 0.08 : 0.09);\n const maxW = Math.min(width - padX * 2, (portrait ? 2000 : 1060) * s);\n\n const flat = headline.replace(/\\n/g, \" \");\n const baseFs = (portrait ? 108 : 96) * s;\n const estEm = textEm(flat) * 1.04;\n const hardLines = headline.split(\"\\n\").length;\n const fitLines = portrait ? 3 : 2;\n const linesAtBase = Math.max(hardLines, Math.ceil((estEm * baseFs) / maxW));\n const fs =\n linesAtBase <= fitLines\n ? baseFs\n : Math.max(baseFs * 0.7, (maxW * fitLines) / Math.max(estEm, 1));\n const { words, lines } = layout(headline, highlight, maxW / fs);\n const lh = fs * LINE;\n const baseline = ((LINE - (ASC + DESC)) / 2 + ASC) * fs;\n\n const eyeFs = 17 * s * (portrait ? 1.25 : 1);\n const eyeH = eyebrow ? eyeFs * 1.3 + fs * 0.4 : 0;\n const subFs = (portrait ? 30 : 25) * s;\n const subGap = fs * 0.36;\n const subMax = Math.min(maxW * 0.8, 720 * s * (portrait ? 1.35 : 1));\n const subLines = subhead\n ? Math.max(1, Math.ceil((textEm(subhead, -0.008) * subFs * 1.02) / subMax))\n : 0;\n const subH = subhead ? subGap + subLines * subFs * 1.4 : 0;\n const blockH = eyeH + lines * lh + subH;\n const top = (height - blockH) / 2 - (portrait ? 0 : 6 * s);\n const left = padX;\n const headTop = top + eyeH;\n\n const n = words.length;\n const stagger = n > 1 ? Math.min(5, 34 / (n - 1)) : 0;\n const FLIGHT = 26;\n const launch = (i: number) => 6 + i * stagger;\n const land = (i: number) => launch(i) + FLIGHT;\n const lastLand = land(Math.max(0, n - 1));\n const eyeT = interpolate(frame, [0, 16], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const subT = interpolate(frame, [lastLand - 2, lastLand + 20], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const cool = interpolate(frame, [lastLand, lastLand + 24], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const drift = interpolate(raw, [0, durationInFrames], [0, 1], CLAMP);\n\n const origin: Pt = portrait\n ? { x: width * 1.1, y: height * 0.96 }\n : { x: width * 1.05, y: height * 1.12 };\n const peakY = Math.max(\n height * 0.02,\n headTop - (portrait ? 0.2 : 0.3) * height,\n );\n const orbit = (w: Word) => {\n const target: Pt = {\n x: left + (w.x + w.w / 2) * fs,\n y: headTop + w.line * lh + baseline - fs * 0.36,\n };\n const k = n > 1 ? 1 - w.index / (n - 1) : 0;\n const control: Pt = {\n x: target.x + (origin.x - target.x) * (0.34 - 0.06 * k),\n y: peakY - (0.04 + 0.12 * k) * height,\n };\n return { target, control };\n };\n\n const transparent = background === \"transparent\";\n const trailW = Math.max(1, 1.3 * s);\n\n return (\n <AbsoluteFill\n style={{\n background: transparent ? \"transparent\" : (background ?? p.bg),\n overflow: \"hidden\",\n }}\n >\n {!transparent && background === undefined ? (\n <>\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: p.ground.join(\", \"),\n transform: `translate(${(-drift * 2).toFixed(3)}%, ${(-drift * 1.5).toFixed(3)}%) scale(1.06)`,\n }}\n />\n <Grain opacity={p.grain} />\n </>\n ) : null}\n\n <svg\n width={width}\n height={height}\n style={{ position: \"absolute\", inset: 0 }}\n aria-hidden\n >\n <defs>\n {words.map((w) => {\n const { target } = orbit(w);\n return (\n <linearGradient\n key={w.index}\n id={`${uid}t${w.index}`}\n gradientUnits=\"userSpaceOnUse\"\n x1={origin.x}\n y1={origin.y}\n x2={target.x}\n y2={target.y}\n >\n <stop offset=\"0\" stopColor={p.trail} stopOpacity={0} />\n <stop offset=\"0.35\" stopColor={p.trail} stopOpacity={0.45} />\n <stop offset=\"1\" stopColor={p.trail} stopOpacity={1} />\n </linearGradient>\n );\n })}\n </defs>\n {words.map((w) => {\n const { target, control } = orbit(w);\n const raw01 = interpolate(\n frame,\n [launch(w.index), land(w.index)],\n [0, 1],\n CLAMP,\n );\n if (raw01 <= 0) return null;\n const t = EASE_FLIGHT(raw01);\n const head = quad(origin, control, target, t);\n const tail = Math.max(0, t - 0.22);\n const landed = frame - land(w.index);\n const trailOp = interpolate(cool, [0, 1], [0.75, 0.42]);\n const headR = interpolate(landed, [-3, 5], [0.05, 0], CLAMP) * fs;\n const tailOp = interpolate(landed, [-2, 6], [1, 0], CLAMP);\n return (\n <g key={w.index}>\n <path\n d={quadSlice(origin, control, target, 0, t)}\n fill=\"none\"\n stroke={`url(#${uid}t${w.index})`}\n strokeWidth={trailW}\n strokeLinecap=\"round\"\n opacity={trailOp}\n />\n {tailOp > 0 ? (\n <path\n d={quadSlice(origin, control, target, tail, t)}\n fill=\"none\"\n stroke={p.head}\n strokeWidth={trailW * 2.2}\n strokeLinecap=\"round\"\n opacity={0.55 * tailOp}\n />\n ) : null}\n {headR > 0.1 ? (\n <circle cx={head.x} cy={head.y} r={headR} fill={p.head} />\n ) : null}\n {landed >= 0 && landed < 16 ? (\n <circle\n cx={target.x}\n cy={target.y}\n r={\n interpolate(landed, [0, 16], [0.06, 0.62], {\n ...CLAMP,\n easing: EASE_OUT,\n }) * fs\n }\n fill=\"none\"\n stroke={p.trail}\n strokeWidth={trailW}\n opacity={interpolate(landed, [0, 16], [0.8, 0], CLAMP)}\n />\n ) : null}\n </g>\n );\n })}\n </svg>\n\n {eyebrow ? (\n <div\n style={{\n position: \"absolute\",\n left,\n top,\n height: eyeFs * 1.3,\n display: \"flex\",\n alignItems: \"center\",\n gap: eyeFs * 0.7,\n clipPath: `inset(-20% ${(1 - eyeT) * 100}% -20% 0)`,\n }}\n >\n <div\n style={{\n width: eyeFs * 0.48,\n height: eyeFs * 0.48,\n borderRadius: 999,\n background: theme === \"dark\" ? LIMB[1] : accent,\n }}\n />\n <span\n style={{\n fontFamily: mono.fontFamily,\n fontWeight: 500,\n fontSize: eyeFs,\n letterSpacing: \"0.1em\",\n textTransform: \"uppercase\",\n color: p.muted,\n whiteSpace: \"nowrap\",\n transform: `translateX(${(1 - eyeT) * -12 * s}px)`,\n }}\n >\n {eyebrow}\n </span>\n </div>\n ) : null}\n\n {words.map((w) => {\n const k = interpolate(\n frame,\n [land(w.index) - 2, land(w.index) + 12],\n [0, 1],\n {\n ...CLAMP,\n easing: EASE_OUT,\n },\n );\n if (k <= 0) return null;\n const wght = 100 + 400 * k;\n const track = TRACK + (1 - k) * 0.05;\n const chars = Math.max(1, w.text.length);\n const shift = (-(track - TRACK) * chars * fs) / 2;\n const hl = w.hl\n ? highlightFill(w.hl, drift, p.highlight(accent))\n : { color: p.fg };\n return (\n <div\n key={w.index}\n style={{\n position: \"absolute\",\n left: left + w.x * fs + shift,\n top: headTop + w.line * lh,\n height: lh,\n lineHeight: `${lh}px`,\n fontFamily: sora.fontFamily,\n fontWeight: 500,\n fontVariationSettings: `\"wght\" ${wght.toFixed(1)}`,\n fontSize: fs,\n letterSpacing: `${track.toFixed(4)}em`,\n whiteSpace: \"nowrap\",\n opacity: interpolate(k, [0, 0.35], [0, 1], CLAMP),\n filter:\n k < 0.98\n ? `blur(${((1 - k) * 0.05 * fs).toFixed(2)}px)`\n : undefined,\n paddingRight: \"0.06em\",\n ...hl,\n }}\n >\n {w.text}\n </div>\n );\n })}\n\n {subhead ? (\n <div\n style={{\n position: \"absolute\",\n left,\n top: headTop + lines * lh + subGap,\n width: subMax,\n fontFamily: sora.fontFamily,\n fontWeight: 400,\n fontSize: subFs,\n lineHeight: 1.4,\n letterSpacing: \"-0.008em\",\n color: p.muted,\n textWrap: \"balance\",\n opacity: subT,\n transform: `translateY(${(1 - subT) * 14 * s}px)`,\n filter: `blur(${(1 - subT) * 6 * s}px)`,\n }}\n >\n {subhead}\n </div>\n ) : null}\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 eyebrow: {\n type: \"text-content\",\n default: \"New in remocn\",\n description: \"Eyebrow\",\n },\n headline: {\n type: \"text-content\",\n default: \"Every launch beat, already in orbit.\",\n description: \"Headline\",\n },\n highlight: {\n type: \"text-content\",\n default: \"in orbit\",\n description: \"Highlight\",\n },\n subhead: {\n type: \"text-content\",\n default: \"Reveals, feature heads and stats as drop-in Remotion scenes.\",\n description: \"Subhead\",\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\",\"eyebrow\",\"headline\",\"highlight\",\"subhead\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n eyebrow: \"New in remocn\",\n headline: \"Every launch beat, already in orbit.\",\n highlight: \"in orbit\",\n subhead: \"Reveals, feature heads and stats as drop-in Remotion scenes.\",\n speed: 1,\n};\n\ntype CometHeadlineElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CometHeadlineBase>;\n\nconst CometHeadlineInner = forwardRef<\n HTMLDivElement,\n CometHeadlineElementProps & { 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 ?? \"<CometHeadline>\"}\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 <CometHeadlineBase\n {...(componentProps as unknown as ComponentProps<typeof CometHeadlineBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CometHeadline = Interactive.withSchema({\n Component: CometHeadlineInner,\n componentName: \"<CometHeadline>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 81,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 81
}