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": "Negation Drop",
"initialProps": null,
"slug": "negation-drop",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/BarlowCondensed\";\nimport React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, continueRender, delayRender, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst barlow = loadFont(\"normal\", { weights: [\"500\"], subsets: [\"latin\"] });\n\ninterface NegationDropProps {\n lines?: string[];\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n dark: {\n bg: \"#000000\",\n ink: \"#FFFFFF\",\n dim: \"#4A4A4A\",\n accent: \"#D4FF00\",\n onBlock: \"#000000\",\n },\n light: {\n bg: \"#D4FF00\",\n ink: \"#000000\",\n dim: \"#8FAD00\",\n accent: \"#000000\",\n onBlock: \"#D4FF00\",\n },\n} as const;\n\nconst TRACK = -0.01;\nconst LINE_H = 0.88;\nconst ENTER_AT = -4;\nconst ENTER_STAGGER = 6;\nconst ENTER_LEN = 16;\nconst FLIP_AT = 44;\nconst FLIP_GAP = 14;\nconst FALL_LEN = 9;\nconst CLOSE_DELAY = 6;\nconst LIT_DELAY = 6;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_FALL = Easing.bezier(0.55, 0, 0.9, 0.45);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst DEFAULT_LINES = [\n \"You can’t animate.\",\n \"You don’t have a team.\",\n \"It isn’t done.\",\n];\n\ntype PartKind = \"plain\" | \"keep\" | \"drop\";\ninterface Part {\n text: string;\n kind: PartKind;\n}\n\nfunction splitLine(line: string): Part[][] {\n const words = line.trim().split(/\\s+/);\n let flipped = false;\n return words.map((w) => {\n if (!flipped) {\n const can = w.match(/^(can)([’']t)(\\W*)$/i);\n const nt =\n can || /^(won|shan)[’']t/i.test(w)\n ? null\n : w.match(/^(\\w+)(n[’']t)(\\W*)$/i);\n const hit = can ?? nt;\n if (hit) {\n flipped = true;\n const parts: Part[] = [\n { text: hit[1], kind: \"keep\" },\n { text: hit[2].replace(\"'\", \"’\"), kind: \"drop\" },\n ];\n if (hit[3]) parts.push({ text: hit[3], kind: \"plain\" });\n return parts;\n }\n }\n return [{ text: w, kind: \"plain\" }];\n });\n}\n\nconst upper = (s: string) => s.toUpperCase();\n\nfunction useWidths(strings: string[]) {\n const key = strings.join(\"\\u0001\");\n const [state, setState] = useState<{\n key: string;\n w: Map<string, number>;\n space: number;\n baseline: number;\n capTop: number;\n } | null>(null);\n const [handle] = useState(() => delayRender(\"negation-drop: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n barlow.waitUntilDone(),\n document.fonts.load(`500 100px \"${barlow.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n const probe = document.createElement(\"span\");\n Object.assign(probe.style, {\n position: \"absolute\",\n left: \"-99999px\",\n top: \"0\",\n visibility: \"hidden\",\n whiteSpace: \"pre\",\n fontFamily: `\"${barlow.fontFamily}\"`,\n fontWeight: \"500\",\n fontSize: \"100px\",\n lineHeight: \"1\",\n letterSpacing: `${TRACK}em`,\n });\n document.body.appendChild(probe);\n const w = new Map<string, number>();\n for (const s of key.split(\"\\u0001\")) {\n probe.textContent = upper(s);\n w.set(s, probe.getBoundingClientRect().width / 100);\n }\n probe.textContent = \"A A\";\n const aa = probe.getBoundingClientRect().width;\n probe.textContent = \"AA\";\n const space = Math.max(\n 0.2,\n ((aa - probe.getBoundingClientRect().width) / 100) * 1.5,\n );\n probe.remove();\n\n let baseline = 0.8;\n let capTop = 0.7;\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n if (ctx) {\n ctx.font = `500 200px \"${barlow.fontFamily}\"`;\n const fm = ctx.measureText(\"H\");\n const asc = fm.fontBoundingBoxAscent / 200;\n const desc = fm.fontBoundingBoxDescent / 200;\n baseline = (1 - (asc + desc)) / 2 + asc;\n capTop = fm.actualBoundingBoxAscent / 200;\n }\n setState({ key, w, space, baseline, capTop });\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 : null;\n}\n\nfunction NegationDropBase({\n lines = DEFAULT_LINES,\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: NegationDropProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const c = THEMES[theme];\n const block = accent ?? c.accent;\n\n const rows = useMemo(() => lines.map(splitLine), [lines]);\n const strings = useMemo(() => {\n const set = new Set<string>();\n for (const r of rows) for (const w of r) for (const p of w) set.add(p.text);\n return [...set];\n }, [rows]);\n const m = useWidths(strings);\n\n const transparent = background === \"transparent\";\n const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n if (!m) {\n return (\n <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n );\n }\n\n const portrait = H > W * 1.1;\n const wOf = (s: string) => m.w.get(s) ?? 0;\n\n const lineEm = rows.map((r) => {\n let full = 0;\n let drop = 0;\n r.forEach((word, wi) => {\n if (wi > 0) full += m.space;\n for (const p of word) {\n full += wOf(p.text);\n if (p.kind === \"drop\") drop += wOf(p.text);\n }\n });\n return { full, drop };\n });\n\n const flipAt = (i: number) => FLIP_AT + i * FLIP_GAP;\n const close = rows.map((_, i) =>\n spring({\n frame: t - flipAt(i) - CLOSE_DELAY,\n fps,\n config: { damping: 15, stiffness: 150, mass: 0.8 },\n }),\n );\n\n const padX = W * (portrait ? 0.035 : 0.025);\n const measureW = W - padX * 2;\n const fitF = lineEm.map(\n (l, i) => measureW / Math.max(0.3, l.full - l.drop * close[i]),\n );\n const restF = lineEm.map((l) => measureW / Math.max(0.3, l.full - l.drop));\n const maxBlockH = H * (portrait ? 0.72 : 0.9);\n const restH = restF.reduce((a, f) => a + f * LINE_H, 0);\n const k = Math.min(1, maxBlockH / Math.max(1, restH));\n const sizes = fitF.map((f) => f * k);\n const blockH = sizes.reduce((a, f) => a + f * LINE_H, 0);\n const blockTop = (H - blockH) / 2 + (sizes[0] ?? 0) * 0.04;\n\n let lineTop = blockTop;\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n {rows.map((r, i) => {\n const F = sizes[i];\n const top = lineTop;\n lineTop += F * LINE_H;\n const enter = interpolate(\n t,\n [\n ENTER_AT + i * ENTER_STAGGER,\n ENTER_AT + i * ENTER_STAGGER + ENTER_LEN,\n ],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const f0 = flipAt(i);\n const tint = interpolate(t, [f0 - 8, f0 - 1], [0, 1], CLAMP);\n const fall = interpolate(t, [f0, f0 + FALL_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_FALL,\n });\n const lit = interpolate(\n t,\n [f0 + LIT_DELAY, f0 + LIT_DELAY + 10],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n const clipTop = top - F * 0.2;\n const baseY = top + m.baseline * F;\n const clipBottom = baseY + F * 0.1;\n const lineW = (lineEm[i].full - lineEm[i].drop * close[i]) * F;\n const left = (W - lineW) / 2;\n const bpad = F * 0.05;\n\n const pieces: React.ReactNode[] = [];\n let x = 0;\n let passedDrop = false;\n r.forEach((word, wi) => {\n if (wi > 0) x += m.space * F;\n for (const p of word) {\n const pw = wOf(p.text) * F;\n const shift = passedDrop ? -lineEm[i].drop * F * close[i] : 0;\n const style: React.CSSProperties = {\n position: \"absolute\",\n left: left + x + shift,\n top: top - clipTop,\n height: F,\n lineHeight: `${F}px`,\n whiteSpace: \"pre\",\n color: c.ink,\n };\n if (p.kind === \"drop\") {\n style.color = interpolateHex(c.ink, c.dim, tint);\n style.transform = `translateY(${(fall * F * 0.95).toFixed(2)}px)`;\n passedDrop = true;\n }\n if (p.kind === \"keep\" && lit > 0) {\n style.color = `color-mix(in oklab, ${c.ink} ${((1 - lit) * 100).toFixed(1)}%, ${c.onBlock})`;\n pieces.push(\n <div\n key={`b${wi}`}\n style={{\n position: \"absolute\",\n left: left + x - bpad,\n top: baseY - m.capTop * F - bpad - clipTop,\n width: pw + bpad * 2,\n height: m.capTop * F + bpad * 2,\n background: block,\n transformOrigin: \"0 50%\",\n transform: `scaleX(${lit.toFixed(4)})`,\n }}\n />,\n );\n }\n pieces.push(\n <span key={`${wi}-${p.kind}-${p.text}`} style={style}>\n {upper(p.text)}\n </span>,\n );\n x += pw;\n }\n });\n\n return (\n <div\n key={i}\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: clipTop,\n height: clipBottom - clipTop,\n overflow: \"hidden\",\n fontFamily: barlow.fontFamily,\n fontWeight: 500,\n fontSize: F,\n letterSpacing: `${TRACK}em`,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n transform: `translateY(${((1 - enter) * (clipBottom - clipTop + F * 0.05)).toFixed(2)}px)`,\n }}\n >\n {pieces}\n </div>\n </div>\n );\n })}\n </AbsoluteFill>\n );\n}\n\nfunction interpolateHex(a: string, b: string, k: number) {\n const pa = hex(a);\n const pb = hex(b);\n if (!pa || !pb) return k < 0.5 ? a : b;\n const mix = pa.map((v, i) => Math.round(v + (pb[i] - v) * k));\n return `rgb(${mix[0]}, ${mix[1]}, ${mix[2]})`;\n}\n\nfunction hex(s: string) {\n const mm = s.trim().match(/^#?([0-9a-f]{6})$/i);\n if (!mm) return null;\n const n = Number.parseInt(mm[1], 16);\n return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\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 NegationDropElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof NegationDropBase>;\n\nconst NegationDropInner = forwardRef<\n HTMLDivElement,\n NegationDropElementProps & { 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 ?? \"<NegationDrop>\"}\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 <NegationDropBase\n {...(componentProps as unknown as ComponentProps<typeof NegationDropBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const NegationDrop = Interactive.withSchema({\n Component: NegationDropInner,\n componentName: \"<NegationDrop>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 94,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 94
}