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": "Crosshair Lock",
"initialProps": null,
"slug": "crosshair-lock",
"sourceCode": "import { loadFont as loadMono } from \"@remotion/google-fonts/JetBrainsMono\";\nimport { loadFont as loadDisplay } from \"@remotion/google-fonts/SpaceGrotesk\";\nimport React, { forwardRef, useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst { fontFamily: display } = loadDisplay(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\nconst { fontFamily: mono } = loadMono(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\ninterface CrosshairLockProps {\n x?: number;\n y?: number;\n label?: string;\n value?: string;\n accent?: string;\n theme?: \"dark\" | \"light\";\n speed?: number;\n}\n\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\n\nconst V_AT = 14;\nconst H_AT = 18;\nconst SLIDE = 26;\nconst LOCK = H_AT + SLIDE;\nconst LEAD_AT = LOCK + 8;\nconst POP_AT = LEAD_AT + 10;\n\nconst THEMES = {\n dark: {\n bg: \"#0A0A0B\",\n fg: \"#F3F2EF\",\n muted: \"#8B8A90\",\n hair: \"rgba(255,255,255,0.55)\",\n axis: \"rgba(255,255,255,0.2)\",\n dotRGB: \"#FFFFFF\",\n dotA: 0.26,\n // gradients.sh \"mesh\": blooms out of the locked peak\n mesh: [\"#ECDCF2\", \"#8796EE\", \"#2E45B7\"],\n grain: 0.055,\n },\n light: {\n bg: \"#F5F4F0\",\n fg: \"#121214\",\n muted: \"#6E6C67\",\n hair: \"rgba(18,18,20,0.55)\",\n axis: \"rgba(18,18,20,0.2)\",\n dotRGB: \"#121214\",\n dotA: 0.22,\n // gradients.sh \"mesh\", deep end first on off-white\n mesh: [\"#0E1645\", \"#2E45B7\", \"#8796EE\"],\n grain: 0.04,\n },\n} as const;\n\nfunction hash(n: number) {\n const s = Math.sin(n * 127.1 + 311.7) * 43758.5453;\n return s - Math.floor(s);\n}\n\nfunction parseValue(v: string) {\n const m = v.match(/([\\d.,]+)\\s*([kKmM])?/);\n if (!m) return null;\n const n = Number.parseFloat(m[1].replace(/,/g, \"\"));\n if (!Number.isFinite(n)) return null;\n const mult = m[2] ? (m[2].toLowerCase() === \"k\" ? 1e3 : 1e6) : 1;\n return n * mult;\n}\n\nfunction splitValue(v: string) {\n const m = v.match(/^(\\s*[^\\d]*[\\d.,]+\\s*[kKmMbB%×x]?)(.*)$/);\n if (!m) return { head: v, tail: \"\" };\n return { head: m[1], tail: m[2] };\n}\n\nfunction clock(f: number) {\n const mins = Math.round((9 * 60 + f * 12 * 60) / 5) * 5;\n const h = Math.floor(mins / 60);\n const m = mins % 60;\n return `${String(h).padStart(2, \"0\")}:${String(m).padStart(2, \"0\")}`;\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={41}\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\nfunction CrosshairLockBase({\n x = 0.7,\n y = 0.94,\n label = \"Peak\",\n value = \"2.4k/min\",\n accent = \"#3B5BFD\",\n theme = \"dark\",\n speed = 1,\n}: CrosshairLockProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const u = Math.min(W / 1280, H / 720);\n const p = THEMES[theme];\n\n const left = 0.14 * W;\n const right = 0.9 * W;\n const top = 0.42 * H;\n const bottom = 0.84 * H;\n const step = 16 * u;\n const cols = Math.floor((right - left) / step);\n const rows = Math.floor((bottom - top) / step);\n const fx = Math.min(0.97, Math.max(0.03, x));\n const fy = Math.min(1, Math.max(0.15, y));\n const peakCol = Math.round(fx * cols);\n\n const heights = Array.from({ length: cols + 1 }, (_, c) => {\n const f = c / cols;\n const base =\n 0.34 +\n 0.12 * Math.sin(f * 7.3 + 0.8) +\n 0.08 * Math.sin(f * 17.1 + 2.1) +\n 0.07 * (hash(c) - 0.5);\n const g = Math.exp(-(((f - fx) / 0.075) ** 2));\n const v = fy * (Math.min(0.66, Math.max(0.12, base)) * (1 - g) + g);\n return c === peakCol ? rows : Math.min(rows - 1, Math.round(v * rows));\n });\n const peakRows = Math.round(fy * rows);\n heights[peakCol] = peakRows;\n for (let c = 0; c <= cols; c++) {\n if (c !== peakCol) heights[c] = Math.min(heights[c], peakRows - 1);\n }\n\n const px = left + peakCol * step;\n const py = bottom - (peakRows - 1) * step;\n\n const vk = EASE_IO(interpolate(t, [V_AT, V_AT + SLIDE], [0, 1], CLAMP));\n const hk = EASE_IO(interpolate(t, [H_AT, H_AT + SLIDE], [0, 1], CLAMP));\n const fromLeft = fx > 0.5;\n const vStart = fromLeft ? left - 0.07 * W : right + 0.07 * W;\n const vx = vStart + (px - vStart) * vk;\n const hStart = bottom + 0.1 * H;\n const hy = hStart + (py - hStart) * hk;\n const vOn = interpolate(t, [V_AT, V_AT + 6], [0, 1], CLAMP);\n const hOn = interpolate(t, [H_AT, H_AT + 6], [0, 1], CLAMP);\n\n const ring = interpolate(t, [LOCK, LOCK + 20], [0, 1], {\n ...CLAMP,\n easing: Easing.bezier(0.22, 1, 0.36, 1),\n });\n const lock = spring({\n frame: t - LOCK,\n fps,\n config: { damping: 14, stiffness: 220, mass: 0.6 },\n });\n const locked = t >= LOCK;\n\n const num = parseValue(value);\n const yFrac = Math.max(0, (bottom - hy) / (bottom - py));\n const yRead =\n num === null\n ? (fy * yFrac).toFixed(2)\n : Math.round(num * yFrac).toLocaleString(\"en-US\");\n const xFrac = (vx - left) / (right - left);\n const xRead = clock(Math.min(1, Math.max(0, xFrac)));\n\n const dir = fx > 0.55 ? -1 : 1;\n const valueSize = 112 * u;\n const labelY = top - 96 * u;\n const diag = py - labelY;\n const run = 64 * u;\n const elbowX = px + dir * diag;\n const endX = elbowX + dir * run;\n const leadLen = Math.SQRT2 * diag + run;\n const lead = EASE_IO(interpolate(t, [LEAD_AT, LEAD_AT + 14], [0, 1], CLAMP));\n const pop = spring({\n frame: t - POP_AT,\n fps,\n config: { damping: 16, stiffness: 200, mass: 0.6 },\n });\n const popOp = interpolate(t, [POP_AT, POP_AT + 8], [0, 1], CLAMP);\n const { head, tail } = splitValue(value);\n const gradId = `mesh${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n const bloom = interpolate(t, [LOCK - 2, LOCK + 34], [0, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n const bloomR = Math.max(1, (0.06 + 0.34 * bloom) * W);\n\n const dots: React.ReactNode[] = [];\n for (let c = 0; c <= cols; c++) {\n const f = c / cols;\n const rise = EASE_OUT(interpolate(t, [f * 14, f * 14 + 12], [0, 1], CLAMP));\n const isPeak = c === peakCol;\n for (let r = 0; r < heights[c]; r++) {\n const top1 = isPeak && r === heights[c] - 1;\n if (top1 && locked) continue;\n dots.push(\n <circle\n key={`${c}-${r}`}\n cx={left + c * step}\n cy={bottom - r * step - (1 - rise) * 10 * u}\n r={2.2 * u}\n fill={`url(#${gradId})`}\n opacity={rise}\n />,\n );\n }\n }\n\n const hair = Math.max(1, 1.25 * u);\n const readout: React.CSSProperties = {\n position: \"absolute\",\n fontFamily: mono,\n fontWeight: 500,\n fontSize: 16 * u,\n fontVariantNumeric: \"tabular-nums\",\n letterSpacing: \"-0.01em\",\n whiteSpace: \"nowrap\",\n };\n\n return (\n <AbsoluteFill style={{ background: p.bg, overflow: \"hidden\" }}>\n <svg width={W} height={H} style={{ position: \"absolute\", inset: 0 }}>\n <defs>\n <radialGradient\n id={gradId}\n gradientUnits=\"userSpaceOnUse\"\n cx={px}\n cy={py}\n r={bloomR}\n gradientTransform={`translate(${px} ${py}) scale(1.35 1) translate(${-px} ${-py})`}\n >\n <stop offset=\"0\" stopColor={p.mesh[0]} stopOpacity={bloom} />\n <stop\n offset=\"0.28\"\n stopColor={p.mesh[1]}\n stopOpacity={0.95 * bloom}\n />\n <stop offset=\"0.62\" stopColor={p.mesh[2]} stopOpacity={0.6} />\n <stop offset=\"1\" stopColor={p.dotRGB} stopOpacity={p.dotA} />\n </radialGradient>\n </defs>\n <line\n x1={left - 8 * u}\n x2={right + 8 * u}\n y1={bottom + 14 * u}\n y2={bottom + 14 * u}\n stroke={p.axis}\n strokeWidth={hair}\n opacity={interpolate(t, [0, 10], [0, 1], CLAMP)}\n />\n {dots}\n <line\n x1={vx}\n x2={vx}\n y1={top - 24 * u}\n y2={bottom + 14 * u}\n stroke={p.hair}\n strokeWidth={hair}\n opacity={vOn}\n />\n <line\n x1={left - 8 * u}\n x2={right + 8 * u}\n y1={hy}\n y2={hy}\n stroke={p.hair}\n strokeWidth={hair}\n opacity={hOn}\n />\n <line\n x1={vx}\n x2={vx}\n y1={bottom + 14 * u}\n y2={bottom + 22 * u}\n stroke={p.fg}\n strokeWidth={hair * 1.6}\n opacity={vOn}\n />\n <line\n x1={left - 16 * u}\n x2={left - 8 * u}\n y1={hy}\n y2={hy}\n stroke={p.fg}\n strokeWidth={hair * 1.6}\n opacity={hOn}\n />\n {locked ? (\n <>\n <circle\n cx={px}\n cy={py}\n r={(10 + 34 * ring) * u}\n fill=\"none\"\n stroke={accent}\n strokeWidth={2 * u}\n opacity={0.9 * (1 - ring)}\n />\n <circle\n cx={px}\n cy={py}\n r={(14 - 3 * lock) * u}\n fill={p.bg}\n stroke={accent}\n strokeWidth={2 * u}\n opacity={Math.min(1, lock * 1.4)}\n />\n <circle cx={px} cy={py} r={(3 + 2 * lock) * u} fill={accent} />\n </>\n ) : null}\n {lead > 0 ? (\n <path\n d={`M ${px + dir * 14 * u * Math.SQRT1_2} ${py - 14 * u * Math.SQRT1_2} L ${elbowX} ${labelY} L ${endX} ${labelY}`}\n fill=\"none\"\n stroke={accent}\n strokeWidth={1.75 * u}\n strokeDasharray={leadLen}\n strokeDashoffset={leadLen * (1 - lead)}\n />\n ) : null}\n {lead > 0.98 ? (\n <circle cx={endX} cy={labelY} r={3 * u} fill={accent} />\n ) : null}\n </svg>\n\n <div\n style={{\n ...readout,\n left: vx,\n top: bottom + 30 * u,\n transform: \"translateX(-50%)\",\n color: locked ? p.fg : p.muted,\n opacity: vOn,\n }}\n >\n {xRead}\n </div>\n <div\n style={{\n ...readout,\n right: W - left + 24 * u,\n top: hy,\n transform: \"translateY(-50%)\",\n color: locked ? p.fg : p.muted,\n opacity: hOn,\n }}\n >\n {yRead}\n </div>\n\n <div\n style={{\n position: \"absolute\",\n ...(dir < 0\n ? { right: W - (endX - 18 * u) }\n : { left: endX + 18 * u }),\n top: labelY - valueSize * 0.5,\n height: valueSize,\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: dir < 0 ? \"flex-end\" : \"flex-start\",\n opacity: popOp,\n transform: `translateX(${dir * (1 - pop) * 14 * u}px) scale(${0.96 + 0.04 * pop})`,\n transformOrigin: dir < 0 ? \"100% 50%\" : \"0% 50%\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n bottom: \"100%\",\n marginBottom: 2 * u,\n display: \"flex\",\n alignItems: \"center\",\n gap: 8 * u,\n fontFamily: mono,\n fontWeight: 500,\n fontSize: 13 * u,\n letterSpacing: \"0.08em\",\n textTransform: \"uppercase\",\n color: p.muted,\n whiteSpace: \"nowrap\",\n }}\n >\n <span\n style={{\n width: 6 * u,\n height: 6 * u,\n borderRadius: \"50%\",\n background: accent,\n }}\n />\n {label}\n </div>\n <div\n style={{\n display: \"flex\",\n alignItems: \"baseline\",\n fontFamily: display,\n fontWeight: 500,\n lineHeight: 1,\n fontVariantNumeric: \"tabular-nums\",\n whiteSpace: \"nowrap\",\n }}\n >\n <span\n style={{\n fontSize: valueSize,\n letterSpacing: \"-0.04em\",\n color: p.fg,\n }}\n >\n {head}\n </span>\n {tail ? (\n <span\n style={{\n fontSize: valueSize * 0.36,\n fontWeight: 400,\n letterSpacing: \"-0.01em\",\n marginLeft: 0.08 * valueSize,\n color: p.muted,\n }}\n >\n {tail}\n </span>\n ) : null}\n </div>\n </div>\n\n <Grain opacity={p.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 label: {\n type: \"text-content\",\n default: \"Peak\",\n description: \"Label\",\n },\n value: {\n type: \"text-content\",\n default: \"2.4k/min\",\n description: \"Value\",\n },\n x: {\n type: \"number\",\n default: 0.7,\n min: 0,\n max: 2.1,\n step: 0.01,\n description: \"X\",\n hiddenFromList: false,\n },\n y: {\n type: \"number\",\n default: 0.94,\n min: 0,\n max: 2.82,\n step: 0.01,\n description: \"Y\",\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\",\"label\",\"value\",\"x\",\"y\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n label: \"Peak\",\n value: \"2.4k/min\",\n x: 0.7,\n y: 0.94,\n speed: 1,\n};\n\ntype CrosshairLockElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof CrosshairLockBase>;\n\nconst CrosshairLockInner = forwardRef<\n HTMLDivElement,\n CrosshairLockElementProps & { 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 ?? \"<CrosshairLock>\"}\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 <CrosshairLockBase\n {...(componentProps as unknown as ComponentProps<typeof CrosshairLockBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const CrosshairLock = Interactive.withSchema({\n Component: CrosshairLockInner,\n componentName: \"<CrosshairLock>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 82,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 82
}