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": "Filler Cut",
"initialProps": null,
"slug": "filler-cut",
"sourceCode": "import { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadSchibsted } from \"@remotion/google-fonts/SchibstedGrotesk\";\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 grotesk = loadSchibsted(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\nconst mono = loadMono(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\n\ninterface FillerCutProps {\n transcript?: string;\n keep?: string;\n highlight?: string;\n showTime?: boolean;\n accent?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst HALO = [\"#fff4ec\", \"#ffb36b\", \"#e2457a\", \"#3d4dff\"] as const;\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n ink: \"#F4F3F0\",\n muted: \"#8E8D94\",\n filler: \"rgba(244, 243, 240, 0.26)\",\n stops: [HALO[1], HALO[2]],\n glow: 0.16,\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n ink: \"#111113\",\n muted: \"#77746E\",\n filler: \"rgba(17, 17, 19, 0.22)\",\n stops: [\"#f08a2c\", HALO[2]],\n glow: 0.1,\n grain: 0.035,\n },\n} as const;\n\nconst SPEAK_TRACK = -0.01;\nconst HEAD_TRACK = -0.04;\nconst SPEAK_LEAD = 1.32;\nconst HEAD_LEAD = 1.02;\n\nconst SPEAK_AT = 4;\nconst SPEAK_PER = 2;\nconst SPEAK_MAX = 28;\nconst MARK_AT = 34;\nconst MARK_TO_CUT = 10;\nconst CUT_GAP = 6;\nconst CUT_LEN = 10;\nconst REFLOW_GAP = 2;\nconst REFLOW_LEN = 12;\nconst SET_GAP = 4;\nconst SET_LEN = 24;\nconst SEC_PER_WORD = 0.38;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_CUT = Easing.bezier(0.6, 0, 0.2, 1);\nconst EASE_SET = Easing.bezier(0.7, 0, 0.16, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst norm = (s: string) => s.toLowerCase().replace(/[^\\p{L}\\p{N}]/gu, \"\");\n\ninterface Token {\n said: string;\n keep: number;\n cut: number;\n}\n\nfunction plan(transcript: string, keep: string) {\n const said = transcript.split(/\\s+/).filter(Boolean);\n const kept = keep.split(/\\s+/).filter(Boolean);\n const tokens: Token[] = said.map((s) => ({ said: s, keep: -1, cut: -1 }));\n let j = 0;\n for (let i = 0; i < tokens.length && j < kept.length; i++)\n if (norm(tokens[i].said) === norm(kept[j])) tokens[i].keep = j++;\n const extra = kept.map((_, q) => q).filter((q) => q >= j);\n let cuts = 0;\n tokens.forEach((tk, i) => {\n if (tk.keep >= 0) return;\n tk.cut = i > 0 && tokens[i - 1].cut >= 0 ? tokens[i - 1].cut : cuts++;\n });\n return { tokens, kept, extra, cuts };\n}\n\ninterface Metrics {\n said: number[];\n head: number[];\n space400: number;\n space500: number;\n}\n\nfunction measure(said: string[], kept: string[]): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n const fam = `\"${grotesk.fontFamily}\"`;\n if (!ctx)\n return {\n said: said.map((s) => s.length * 0.5),\n head: kept.map((s) => s.length * 0.52),\n space400: 0.25,\n space500: 0.25,\n };\n const width = (s: string, track: number) =>\n ctx.measureText(s).width / 1000 + track * Array.from(s).length;\n ctx.font = `400 1000px ${fam}`;\n const s400 = said.map((s) => width(s, SPEAK_TRACK));\n const space400 = ctx.measureText(\" \").width / 1000;\n ctx.font = `500 1000px ${fam}`;\n const h500 = kept.map((s) => width(s, HEAD_TRACK));\n const space500 = ctx.measureText(\" \").width / 1000;\n return { said: s400, head: h500, space400, space500 };\n}\n\nfunction useMetrics(said: string[], kept: string[]) {\n const [metrics, setMetrics] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"filler-cut: measuring\"));\n const released = useRef(false);\n const key = `${said.join(\" \")}\\n${kept.join(\" \")}`;\n useEffect(() => {\n let live = true;\n Promise.all([\n grotesk.waitUntilDone(),\n mono.waitUntilDone(),\n document.fonts.load(`400 100px \"${grotesk.fontFamily}\"`),\n document.fonts.load(`500 100px \"${grotesk.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const [a, b] = key.split(\"\\n\");\n setMetrics(\n measure(a.split(\" \").filter(Boolean), b.split(\" \").filter(Boolean)),\n );\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [key, handle]);\n return metrics;\n}\n\nfunction wrap(widths: number[], space: number, size: number, maxW: number) {\n const line: number[] = [];\n let li = 0;\n let x = 0;\n widths.forEach((w, i) => {\n const add = (x > 0 ? space : 0) * size + w * size;\n if (x > 0 && x + add > maxW) {\n li++;\n x = w * size;\n } else x += add;\n line[i] = li;\n });\n return line;\n}\n\nfunction headlineBreaks(\n widths: number[],\n space: number,\n maxW: number,\n cap: number,\n) {\n const n = widths.length;\n let best: { line: number[]; size: number } | null = null;\n const tries: { line: number[]; size: number }[] = [];\n for (let mask = 0; mask < 1 << Math.max(0, n - 1); mask++) {\n let k = 1;\n for (let q = 0; q < n - 1; q++) if (mask & (1 << q)) k++;\n if (k > 3) continue;\n const line: number[] = [0];\n const lw = [widths[0]];\n for (let q = 1; q < n; q++) {\n if (mask & (1 << (q - 1))) {\n line.push(line[q - 1] + 1);\n lw.push(widths[q]);\n } else {\n line.push(line[q - 1]);\n lw[lw.length - 1] += space + widths[q];\n }\n }\n const widest = Math.max(...lw);\n const spread = widest - Math.min(...lw);\n tries.push({ line, size: Math.min(cap, maxW / widest) - spread * 0.001 });\n }\n const top = Math.max(...tries.map((r) => r.size));\n for (const r of tries) {\n const k = r.line[r.line.length - 1] + 1;\n const bk = best ? best.line[best.line.length - 1] + 1 : 99;\n if (r.size < top * 0.9) continue;\n if (!best || k < bk || (k === bk && r.size > best.size)) best = r;\n }\n return best ?? { line: widths.map(() => 0), size: cap };\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `fc${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={9}\n />\n <feColorMatrix type=\"saturate\" values=\"0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\nconst lerp = (a: number, b: number, p: number) => a + (b - a) * p;\n\nconst shade = (a: string, b: string, p: number) =>\n p <= 0\n ? b\n : p >= 1\n ? a\n : `color-mix(in oklab, ${a} ${(p * 100).toFixed(1)}%, ${b})`;\n\nconst clock = (sec: number) => {\n const s = Math.max(0, sec);\n const whole = Math.floor(s);\n const tenth = Math.floor((s - whole) * 10);\n return `0:${String(whole).padStart(2, \"0\")}.${tenth}`;\n};\n\nfunction FillerCutBase({\n transcript = \"So, um, ship your, like, launch video, uh, today. You know?\",\n keep = \"Ship your launch video today.\",\n highlight = \"today.\",\n showTime = true,\n accent = \"#3B5BFD\",\n speed = 1,\n theme = \"dark\",\n}: FillerCutProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const P = useMemo(() => plan(transcript, keep), [transcript, keep]);\n const m = useMetrics(\n P.tokens.map((tk) => tk.said),\n P.kept,\n );\n\n if (!m) {\n return <div style={{ position: \"absolute\", inset: 0, background: c.bg }} />;\n }\n\n const portrait = H > W;\n const unit = Math.min(W, H);\n const left = W * (portrait ? 0.08 : 0.1);\n const maxW = W - left * 2;\n const sA = portrait ? W * 0.075 : unit * 0.084;\n const lineA = wrap(m.said, m.space400, sA, maxW);\n const nLinesA = (lineA[lineA.length - 1] ?? 0) + 1;\n\n const n = P.tokens.length;\n const speakPer = Math.min(SPEAK_PER, SPEAK_MAX / Math.max(1, n - 1));\n const markAt = Math.max(MARK_AT, SPEAK_AT + (n - 1) * speakPer + 8);\n const cutAt = markAt + MARK_TO_CUT;\n const cutP = (k: number) =>\n interpolate(\n t,\n [cutAt + k * CUT_GAP, cutAt + k * CUT_GAP + CUT_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_CUT },\n );\n const collapse = P.tokens.map((tk) => (tk.cut >= 0 ? cutP(tk.cut) : 0));\n\n const ripple = (col: number[]) => {\n const lineH = new Array(nLinesA).fill(0);\n for (let li = 0; li < nLinesA; li++) {\n let h = 0;\n for (let i = 0; i < n; i++)\n if (lineA[i] === li) h = Math.max(h, 1 - col[i]);\n lineH[li] = h * SPEAK_LEAD * sA;\n }\n const total = lineH.reduce((a, b) => a + b, 0);\n const top = H * 0.5 - total / 2;\n const xs: number[] = [];\n const ys: number[] = [];\n let y = top;\n for (let li = 0; li < nLinesA; li++) {\n let x = left;\n P.tokens.forEach((_, i) => {\n if (lineA[i] !== li) return;\n xs[i] = x;\n ys[i] = y + (SPEAK_LEAD * sA) / 2;\n x += (m.said[i] + m.space400) * sA * (1 - col[i]);\n });\n y += lineH[li];\n }\n return { xs, ys, total, top };\n };\n const live = ripple(collapse);\n const cutDone = ripple(P.tokens.map((tk) => (tk.cut >= 0 ? 1 : 0)));\n\n const cap = portrait ? W * 0.15 : H * 0.19;\n const hb = headlineBreaks(m.head, m.space500, maxW, cap);\n const sC = hb.size;\n const nLinesC = (hb.line[hb.line.length - 1] ?? 0) + 1;\n const blockC = nLinesC * HEAD_LEAD * sC;\n const topC = H * 0.5 - blockC / 2;\n const headX: number[] = [];\n const headY: number[] = [];\n {\n let x = left;\n let prev = -1;\n P.kept.forEach((_, q) => {\n if (hb.line[q] !== prev) {\n x = left;\n prev = hb.line[q];\n }\n headX[q] = x;\n headY[q] = topC + (hb.line[q] + 0.5) * HEAD_LEAD * sC;\n x += (m.head[q] + m.space500) * sC;\n });\n }\n\n const cutEnd = cutAt + Math.max(0, P.cuts - 1) * CUT_GAP + CUT_LEN;\n const reflowAt = cutEnd + REFLOW_GAP;\n const reflowEarly = interpolate(\n t,\n [reflowAt, reflowAt + REFLOW_LEN * 0.6],\n [0, 1],\n { ...CLAMP, easing: EASE_SET },\n );\n const reflowLate = interpolate(\n t,\n [reflowAt + REFLOW_LEN * 0.4, reflowAt + REFLOW_LEN],\n [0, 1],\n { ...CLAMP, easing: EASE_SET },\n );\n const reflowP = reflowEarly;\n const keptIdx = P.tokens.flatMap((tk, i) => (tk.keep >= 0 ? [i] : []));\n const lineB = wrap(\n keptIdx.map((i) => m.said[i]),\n m.space400,\n sA,\n maxW,\n );\n const nLinesB = (lineB[lineB.length - 1] ?? 0) + 1;\n const topB = H * 0.5 - (nLinesB * SPEAK_LEAD * sA) / 2;\n const reX: number[] = [];\n const reY: number[] = [];\n {\n let x = left;\n let prev = -1;\n keptIdx.forEach((i, r) => {\n if (lineB[r] !== prev) {\n x = left;\n prev = lineB[r];\n }\n reX[i] = x;\n reY[i] = topB + (lineB[r] + 0.5) * SPEAK_LEAD * sA;\n x += (m.said[i] + m.space400) * sA;\n });\n }\n const setAt = reflowAt + REFLOW_LEN + SET_GAP;\n const setP = interpolate(t, [setAt, setAt + SET_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_SET,\n });\n const setY = interpolate(t, [setAt, setAt + SET_LEN * 0.7], [0, 1], {\n ...CLAMP,\n easing: EASE_SET,\n });\n const markP = interpolate(t, [markAt, markAt + 8], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const hiP = interpolate(\n t,\n [setAt + SET_LEN - 6, setAt + SET_LEN + 10],\n [0, 1],\n {\n ...CLAMP,\n easing: EASE_OUT,\n },\n );\n const hiStart = highlight ? keep.lastIndexOf(highlight) : -1;\n const isHi = (q: number) => {\n if (hiStart < 0) return false;\n let at = 0;\n const words = keep.split(/\\s+/).filter(Boolean);\n for (let i = 0; i < q; i++)\n at = keep.indexOf(words[i], at) + words[i].length;\n const s = keep.indexOf(words[q], at);\n return s < hiStart + highlight.length && s + words[q].length > hiStart;\n };\n const fill = `linear-gradient(100deg, ${c.stops[0]} 0%, ${c.stops[1]} 55%, ${accent} 100%)`;\n\n const els: React.ReactNode[] = [];\n P.tokens.forEach((tk, i) => {\n const spoken = interpolate(\n t,\n [SPEAK_AT + i * speakPer, SPEAK_AT + i * speakPer + 8],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const survivor = tk.keep >= 0;\n if (!survivor) {\n const col = collapse[i];\n if (col >= 1) return;\n els.push(\n <div\n key={`s${i}`}\n style={{\n position: \"absolute\",\n left: live.xs[i],\n top: live.ys[i] - sA * 0.5,\n fontFamily: grotesk.fontFamily,\n fontWeight: 400,\n fontSize: sA,\n lineHeight: `${sA}px`,\n letterSpacing: `${SPEAK_TRACK}em`,\n whiteSpace: \"pre\",\n color: shade(c.filler, c.muted, markP),\n opacity: spoken * (1 - col) ** 0.6,\n transformOrigin: \"0% 50%\",\n transform: `translateY(${((1 - spoken) * sA * 0.4).toFixed(2)}px) scaleX(${(1 - col).toFixed(4)})`,\n }}\n >\n {tk.said}\n </div>,\n );\n return;\n }\n const q = tk.keep;\n const p = setP;\n const size = lerp(sA, sC, p);\n const up = reY[i] < cutDone.ys[i] - 1;\n const preX =\n reflowP > 0\n ? lerp(cutDone.xs[i], reX[i], up ? reflowEarly : reflowLate)\n : live.xs[i];\n const preY =\n reflowP > 0\n ? lerp(cutDone.ys[i], reY[i], up ? reflowLate : reflowEarly)\n : live.ys[i];\n const x = lerp(preX, headX[q], p);\n const yMid = lerp(preY, headY[q], setY);\n const head = p >= 0.5;\n const hi = isHi(q);\n const textStyle: React.CSSProperties = {\n position: \"absolute\",\n left: x,\n top: yMid - size * 0.5,\n fontFamily: grotesk.fontFamily,\n fontWeight: head ? 500 : 400,\n fontSize: size,\n lineHeight: `${size}px`,\n letterSpacing: `${lerp(SPEAK_TRACK, HEAD_TRACK, p)}em`,\n whiteSpace: \"pre\",\n transform: `translateY(${((1 - spoken) * sA * 0.4).toFixed(2)}px)`,\n opacity: spoken,\n };\n const ink = shade(c.ink, c.muted, markP);\n const word = head ? P.kept[q] : tk.said;\n els.push(\n <div key={`k${i}`} style={{ ...textStyle, color: ink }}>\n {word}\n </div>,\n );\n if (hi && hiP > 0)\n els.push(\n <div\n key={`h${i}`}\n style={{\n ...textStyle,\n color: \"transparent\",\n backgroundImage: fill,\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n opacity: hiP,\n }}\n >\n {word}\n </div>,\n );\n });\n for (const q of P.extra) {\n const a = interpolate(t, [setAt + 8, setAt + SET_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n els.push(\n <div\n key={`x${q}`}\n style={{\n position: \"absolute\",\n left: headX[q],\n top: headY[q] - sC * 0.5 + (1 - a) * sC * 0.3,\n fontFamily: grotesk.fontFamily,\n fontWeight: 500,\n fontSize: sC,\n lineHeight: `${sC}px`,\n letterSpacing: `${HEAD_TRACK}em`,\n whiteSpace: \"pre\",\n color: c.ink,\n opacity: a,\n }}\n >\n {P.kept[q]}\n </div>,\n );\n }\n\n const gone = P.tokens.reduce(\n (acc, tk, i) => acc + (tk.cut >= 0 ? collapse[i] : 0),\n 0,\n );\n const secs = (n - gone) * SEC_PER_WORD;\n const timeOn =\n interpolate(t, [SPEAK_AT + 4, SPEAK_AT + 18], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n }) *\n (1 - interpolate(t, [setAt, setAt + 10], [0, 1], CLAMP));\n const timeSize = Math.max(unit * 0.024, 11);\n const blockTop = live.top;\n\n const glow = `radial-gradient(60% 50% at 30% 55%, color-mix(in oklab, ${c.stops[1]} ${(c.glow * 100 * hiP).toFixed(1)}%, transparent) 0%, transparent 70%)`;\n\n return (\n <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n <div style={{ position: \"absolute\", inset: 0, backgroundImage: glow }} />\n {els}\n {showTime ? (\n <div\n style={{\n position: \"absolute\",\n left,\n top: blockTop - timeSize * 2.6,\n display: \"flex\",\n gap: timeSize * 1.2,\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: timeSize,\n lineHeight: 1,\n letterSpacing: \"0.04em\",\n color: c.muted,\n fontVariantNumeric: \"tabular-nums\",\n opacity: timeOn,\n whiteSpace: \"pre\",\n }}\n >\n <span style={{ color: c.ink }}>{clock(secs)}</span>\n <span>{gone > 0.05 ? `−${clock(gone * SEC_PER_WORD)}` : \"\"}</span>\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 transcript: {\n type: \"text-content\",\n default: \"So, um, ship your, like, launch video, uh, today. You know?\",\n description: \"Transcript\",\n },\n keep: {\n type: \"text-content\",\n default: \"Ship your launch video today.\",\n description: \"Keep\",\n },\n highlight: {\n type: \"text-content\",\n default: \"today.\",\n description: \"Highlight\",\n },\n showTime: {\n type: \"boolean\",\n default: true,\n description: \"Show time\",\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\",\"transcript\",\"keep\",\"highlight\",\"showTime\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n transcript: \"So, um, ship your, like, launch video, uh, today. You know?\",\n keep: \"Ship your launch video today.\",\n highlight: \"today.\",\n showTime: true,\n speed: 1,\n};\n\ntype FillerCutElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof FillerCutBase>;\n\nconst FillerCutInner = forwardRef<\n HTMLDivElement,\n FillerCutElementProps & { 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 ?? \"<FillerCut>\"}\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 <FillerCutBase\n {...(componentProps as unknown as ComponentProps<typeof FillerCutBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const FillerCut = Interactive.withSchema({\n Component: FillerCutInner,\n componentName: \"<FillerCut>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 114,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 114
}