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": "Magnitude Push",
"initialProps": null,
"slug": "magnitude-push",
"sourceCode": "import { loadFont as loadSchibsted } from \"@remotion/google-fonts/SchibstedGrotesk\";\nimport { forwardRef, useEffect, useId, 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 schibsted = loadSchibsted(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\ninterface MagnitudePushProps {\n value?: string;\n suffix?: string;\n label?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst BEAM = [\"#f4f7ff\", \"#8fb4ff\", \"#3d5bff\", \"#1a1660\"] as const;\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n ink: \"#F4F3F0\",\n muted: \"#8E8D94\",\n digit: (a: string) =>\n `linear-gradient(180deg, ${BEAM[0]} 8%, ${BEAM[1]} 46%, ${a} 92%)`,\n ground: 0.55,\n grain: 0.05,\n },\n light: {\n bg: \"#F5F4F0\",\n ink: \"#111113\",\n muted: \"#6E6C67\",\n digit: (a: string) =>\n `linear-gradient(180deg, ${BEAM[3]} 6%, ${a} 58%, #7f9bff 98%)`,\n ground: 0.22,\n grain: 0.035,\n },\n} as const;\n\nconst TRACK = -0.035;\nconst LABEL_TRACK = -0.012;\nconst FIT_W = 0.86;\nconst CAP_H = 0.7;\n\nconst RISE_AT = 2;\nconst RISE_LEN = 16;\nconst PUSH_AT = 30;\nconst PUSH_GAP = 15;\nconst CAM_LAG = 5;\nconst CAM_LEN = 16;\nconst LABEL_GAP = 4;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface Metrics {\n adv: number[];\n suffix: number;\n label: number;\n inkTop: number;\n inkBot: number;\n baseline: number;\n}\n\nconst FONT_PX = 400;\n\nfunction measure(chars: string[], suffix: string, label: string): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"magnitude-push: no 2d context\");\n const fam = `\"${schibsted.fontFamily}\"`;\n ctx.font = `500 ${FONT_PX}px ${fam}`;\n const adv = chars.map((ch) => ctx.measureText(ch).width / FONT_PX + TRACK);\n const suf = suffix\n ? ctx.measureText(suffix).width / FONT_PX +\n TRACK * Array.from(suffix).length\n : 0;\n const digits = ctx.measureText(\"0123456789\");\n const box = ctx.measureText(\"0\");\n const asc = box.fontBoundingBoxAscent / FONT_PX;\n const desc = box.fontBoundingBoxDescent / FONT_PX;\n ctx.font = `400 ${FONT_PX}px ${fam}`;\n const lab = label\n ? ctx.measureText(label).width / FONT_PX +\n LABEL_TRACK * Array.from(label).length\n : 0;\n return {\n adv,\n suffix: suf,\n label: lab,\n inkTop: -digits.actualBoundingBoxAscent / FONT_PX,\n inkBot: digits.actualBoundingBoxDescent / FONT_PX,\n baseline: (1 - (asc + desc)) / 2 + asc,\n };\n}\n\nfunction useMetrics(chars: string[], suffix: string, label: string) {\n const [metrics, setMetrics] = useState<Metrics | null>(null);\n const [handle] = useState(() => delayRender(\"magnitude-push: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n Promise.all([\n schibsted.waitUntilDone(),\n document.fonts.load(`500 100px \"${schibsted.fontFamily}\"`),\n document.fonts.load(`400 100px \"${schibsted.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setMetrics(measure(chars, suffix, label));\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [chars, suffix, label, handle]);\n return metrics;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `mp${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 }}\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 MagnitudePushBase({\n value = \"1000\",\n suffix = \"×\",\n label = \"fewer keyframes to set by hand\",\n accent = \"#3B5BFD\",\n background,\n speed = 1,\n theme = \"dark\",\n}: MagnitudePushProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const c = THEMES[theme];\n const bg = background ?? c.bg;\n const clear = bg === \"transparent\";\n\n const chars = useMemo(() => Array.from(value), [value]);\n const m = useMetrics(chars, suffix, label);\n\n if (!m) {\n return <div style={{ position: \"absolute\", inset: 0, background: bg }} />;\n }\n\n const pushes = chars.length - 1;\n const inkH = m.inkBot - m.inkTop;\n const sufGap = suffix ? 0.02 : 0;\n const widthAt = (k: number) =>\n m.adv.slice(0, k + 1).reduce((s, a) => s + a, 0) +\n sufGap +\n m.suffix -\n (suffix ? 0 : TRACK);\n const maxF = (H * CAP_H) / inkH;\n const fitAt = (k: number) => Math.min(maxF, (W * FIT_W) / widthAt(k));\n\n const open = chars.map((_, i) =>\n i === 0\n ? 1\n : spring({\n frame: t - (PUSH_AT + (i - 1) * PUSH_GAP),\n fps,\n config: { damping: 15, stiffness: 120, mass: 0.9 },\n }),\n );\n\n let F = fitAt(0);\n for (let i = 1; i <= pushes; i++) {\n const at = PUSH_AT + (i - 1) * PUSH_GAP + CAM_LAG;\n const k = interpolate(t, [at, at + CAM_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_IN_OUT,\n });\n F = F + (fitAt(i) - F) * k;\n }\n\n const endAt = PUSH_AT + Math.max(0, pushes - 1) * PUSH_GAP;\n const labelAt = endAt + (pushes > 0 ? 18 : 6);\n const rest = fitAt(pushes);\n const labelSize = Math.min(\n Math.max(rest * 0.2, H * 0.05),\n H * 0.076,\n (W * 0.86) / Math.max(0.1, m.label),\n );\n const labelGap = Math.max(rest * 0.16, H * 0.045);\n const blockH = inkH * rest + (label ? labelGap + labelSize * 1.2 : 0);\n const settle = interpolate(t, [labelAt - 6, labelAt + 18], [0, 1], {\n ...CLAMP,\n easing: EASE_IN_OUT,\n });\n const midY = H / 2 + (label ? (-blockH / 2 + (inkH * rest) / 2) * settle : 0);\n const baseY = midY - ((m.inkTop + m.inkBot) / 2) * F;\n\n const totalW =\n chars.reduce((s, _, i) => s + m.adv[i] * open[i], 0) +\n sufGap +\n m.suffix -\n (suffix ? 0 : TRACK);\n let x = W / 2 - (totalW * F) / 2;\n const lineTop = baseY - m.baseline * F;\n const maskTop = baseY + m.inkTop * F - F * 0.08;\n const maskBot = baseY + m.inkBot * F + F * 0.06;\n const maskH = maskBot - maskTop;\n\n const rise = (at: number) =>\n interpolate(t, [at, at + RISE_LEN], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const glyphBase = {\n position: \"absolute\" as const,\n top: lineTop - maskTop,\n fontFamily: schibsted.fontFamily,\n fontWeight: 500,\n fontSize: F,\n lineHeight: `${F}px`,\n letterSpacing: `${TRACK}em`,\n whiteSpace: \"pre\" as const,\n };\n\n const nodes = chars.map((ch, i) => {\n const gx = x;\n const w = m.adv[i] * open[i] * F;\n x += w;\n if (i === 0) {\n const p = rise(RISE_AT);\n return (\n <div\n key={`g-${i}`}\n style={{\n ...glyphBase,\n left: gx,\n color: c.ink,\n transform: `translateY(${((1 - p) * maskH * 1.05).toFixed(2)}px)`,\n }}\n >\n {ch}\n </div>\n );\n }\n const at = PUSH_AT + (i - 1) * PUSH_GAP;\n const p = rise(at + 3);\n const slot = Math.max(0, w);\n if (slot < 1) return null;\n return (\n <div\n key={`g-${i}`}\n style={{\n position: \"absolute\",\n left: gx,\n top: 0,\n width: slot,\n height: maskH,\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n ...glyphBase,\n left: (slot - m.adv[i] * F) / 2,\n backgroundImage: c.digit(accent),\n backgroundSize: `100% ${maskH}px`,\n backgroundPosition: `0 ${-(lineTop - maskTop)}px`,\n WebkitBackgroundClip: \"text\",\n backgroundClip: \"text\",\n color: \"transparent\",\n transform: `translateY(${((1 - p) * maskH * 1.1).toFixed(2)}px)`,\n }}\n >\n {ch}\n </div>\n </div>\n );\n });\n\n const sufP = rise(RISE_AT + 3);\n const sufNode = suffix ? (\n <div\n key=\"suffix\"\n style={{\n ...glyphBase,\n left: x + sufGap * F,\n color: c.ink,\n transform: `translateY(${((1 - sufP) * maskH * 1.05).toFixed(2)}px)`,\n }}\n >\n {suffix}\n </div>\n ) : null;\n\n const lit =\n pushes > 0 ? open.slice(1).reduce((s, o) => s + o, 0) / pushes : 1;\n const glow = c.ground * (0.25 + 0.75 * Math.min(1, lit));\n const drift = Math.sin(t / 40) * 3;\n const ground = `radial-gradient(${70 + 18 * lit}% ${46 + 22 * lit}% at ${50 + drift}% 112%, color-mix(in oklab, ${accent} 70%, ${BEAM[1]}) 0%, color-mix(in oklab, ${BEAM[2]} 55%, transparent) 38%, transparent 72%)`;\n\n const words = label.split(\" \");\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n {clear ? null : (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n backgroundImage: ground,\n opacity: glow,\n }}\n />\n )}\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: maskTop,\n height: maskH,\n overflow: \"visible\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top: 0,\n width: W,\n height: maskH,\n overflow: \"hidden\",\n }}\n >\n {nodes}\n {sufNode}\n </div>\n </div>\n {label ? (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n width: W,\n top: midY + (inkH * rest) / 2 + labelGap,\n display: \"flex\",\n justifyContent: \"center\",\n fontFamily: schibsted.fontFamily,\n fontWeight: 400,\n fontSize: labelSize,\n lineHeight: 1.2,\n letterSpacing: `${LABEL_TRACK}em`,\n color: c.ink,\n whiteSpace: \"pre\",\n }}\n >\n {words.map((w, k) => {\n const p = interpolate(\n t,\n [labelAt + k * LABEL_GAP, labelAt + k * LABEL_GAP + 16],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n return (\n <span\n key={`${w}-${k}`}\n style={{\n display: \"inline-block\",\n opacity: p,\n transform: `translateY(${((1 - p) * labelSize * 0.7).toFixed(2)}px)`,\n }}\n >\n {w}\n {k < words.length - 1 ? \" \" : \"\"}\n </span>\n );\n })}\n </div>\n ) : null}\n {clear ? null : <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 value: {\n type: \"text-content\",\n default: \"1000\",\n description: \"Value\",\n },\n suffix: {\n type: \"text-content\",\n default: \"×\",\n description: \"Suffix\",\n },\n label: {\n type: \"text-content\",\n default: \"fewer keyframes to set by hand\",\n description: \"Label\",\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\",\"value\",\"suffix\",\"label\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n value: \"1000\",\n suffix: \"×\",\n label: \"fewer keyframes to set by hand\",\n speed: 1,\n};\n\ntype MagnitudePushElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof MagnitudePushBase>;\n\nconst MagnitudePushInner = forwardRef<\n HTMLDivElement,\n MagnitudePushElementProps & { 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 ?? \"<MagnitudePush>\"}\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 <MagnitudePushBase\n {...(componentProps as unknown as ComponentProps<typeof MagnitudePushBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const MagnitudePush = Interactive.withSchema({\n Component: MagnitudePushInner,\n componentName: \"<MagnitudePush>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 114,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 114
}