Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "graph-relayout",
"title": "Graph Relayout",
"description": "A node graph re-lays itself out to fan one prompt into voice, music and every aspect ratio.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/graph-relayout/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadGeist } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport type React from \"react\";\nimport { useId } from \"react\";\nimport {\n AbsoluteFill,\n Easing,\n spring,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst geist = loadGeist(\"normal\", {\n weights: [\"300\", \"400\"],\n subsets: [\"latin\"],\n});\nconst mono = loadMono(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport type NodeIcon =\n | \"doc\"\n | \"captions\"\n | \"frame\"\n | \"image\"\n | \"play\"\n | \"spark\"\n | \"wave\"\n | \"music\"\n | \"palette\"\n | \"wide\"\n | \"tall\"\n | \"square\"\n | \"upload\";\n\nexport type NodeTint =\n | \"blue\"\n | \"violet\"\n | \"cyan\"\n | \"green\"\n | \"pink\"\n | \"amber\"\n | \"coral\";\n\nconst TINTS: Record<\"dark\" | \"light\", Record<NodeTint, string>> = {\n dark: {\n blue: \"#7b95ff\",\n violet: \"#b39bff\",\n cyan: \"#62c9ff\",\n green: \"#5fdc8f\",\n pink: \"#f27ad3\",\n amber: \"#ffbc62\",\n coral: \"#ff8a6b\",\n },\n light: {\n blue: \"#3b5bfd\",\n violet: \"#7a4df0\",\n cyan: \"#1b86d6\",\n green: \"#18a058\",\n pink: \"#d23a9f\",\n amber: \"#d6801f\",\n coral: \"#e0553a\",\n },\n};\n\ntype Palette = {\n ink: string;\n muted: string;\n dot: string;\n boardFill: string;\n boardStroke: string;\n nodeBase: string;\n field: string;\n handle: string;\n shadow: string;\n accent: string;\n onAccent: string;\n ground: Partial<GradientParams>;\n};\n\nconst THEMES: Record<\"dark\" | \"light\", Palette> = {\n dark: {\n ink: \"#eef1fa\",\n muted: \"rgba(226,232,248,0.5)\",\n dot: \"rgba(255,255,255,0.085)\",\n boardFill: \"rgba(255,255,255,0.025)\",\n boardStroke: \"rgba(255,255,255,0.18)\",\n nodeBase: \"rgba(13,17,29,0.86)\",\n field: \"rgba(255,255,255,0.035)\",\n handle: \"#0b0e17\",\n shadow:\n \"inset 0 1px 0 rgba(255,255,255,0.06), 0 2px 6px rgba(0,0,0,0.3), 0 14px 32px rgba(0,0,0,0.35)\",\n accent: \"#3b5bfd\",\n onAccent: \"#ffffff\",\n ground: {\n kind: \"mist\",\n colors: [\"#3557f0\", \"#1a2a8c\", \"#0b1240\", \"#04060f\"],\n background: \"#03050c\",\n speed: 0.5,\n loopSeconds: 18,\n scale: 0.75,\n warp: 0.35,\n blur: 0.8,\n grain: 0.1,\n seed: 9,\n },\n },\n light: {\n ink: \"#16181d\",\n muted: \"rgba(22,24,29,0.5)\",\n dot: \"rgba(30,34,52,0.14)\",\n boardFill: \"rgba(255,255,255,0.5)\",\n boardStroke: \"rgba(30,34,52,0.18)\",\n nodeBase: \"rgba(255,255,255,0.92)\",\n field: \"#ffffff\",\n handle: \"#ffffff\",\n shadow:\n \"0 1px 2px rgba(30,40,80,0.06), 0 6px 18px rgba(30,40,80,0.07), 0 20px 40px rgba(30,40,80,0.05)\",\n accent: \"#3b5bfd\",\n onAccent: \"#ffffff\",\n ground: {\n kind: \"mist\",\n colors: [\"#c9d3ff\", \"#e6e9fb\", \"#f6efe4\", \"#9fb0f5\"],\n background: \"#f4f1ea\",\n speed: 0.5,\n loopSeconds: 18,\n scale: 0.8,\n warp: 0.35,\n blur: 0.75,\n grain: 0.22,\n seed: 4,\n },\n },\n};\n\nconst MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst EXIT = Easing.bezier(0.55, 0, 1, 0.45);\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst CHIP = { mass: 0.5, damping: 12, stiffness: 200 };\n\nconst TILE = 40;\nconst TILE_GAP = 8;\nconst PAD = 12;\nconst LABEL = 15;\nconst FIELD_TEXT = 15;\n\nconst clamp01 = (v: number) => Math.min(1, Math.max(0, v));\nconst lerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\nfunction alpha(hex: string, a: number) {\n const h = hex.replace(\"#\", \"\");\n if (h.length !== 6) return hex;\n const n = Number.parseInt(h, 16);\n return `rgba(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255},${a})`;\n}\n\nfunction NodeGlyph({\n icon,\n size,\n color,\n frame = 0,\n}: {\n icon: NodeIcon;\n size: number;\n color: string;\n frame?: number;\n}) {\n const common = {\n fill: \"none\",\n stroke: color,\n strokeWidth: 1.5,\n strokeLinecap: \"round\" as const,\n strokeLinejoin: \"round\" as const,\n };\n let body: React.ReactNode = null;\n if (icon === \"doc\") {\n body = (\n <>\n <rect x={5} y={3} width={14} height={18} rx={2.5} {...common} />\n <path d=\"M8.5 8h7M8.5 12h7M8.5 16h4\" {...common} />\n </>\n );\n } else if (icon === \"captions\") {\n body = (\n <>\n <rect x={3} y={5} width={18} height={14} rx={3} {...common} />\n <path d=\"M7 11h4M13 11h4M7 15h7\" {...common} />\n </>\n );\n } else if (icon === \"frame\") {\n body = (\n <>\n <rect x={3} y={5} width={18} height={14} rx={2.5} {...common} />\n <path d=\"M7.5 5v14M16.5 5v14M3 12h4.5M16.5 12H21\" {...common} />\n </>\n );\n } else if (icon === \"image\") {\n body = (\n <>\n <rect x={3} y={4} width={18} height={16} rx={3} {...common} />\n <circle cx={9} cy={10} r={1.8} {...common} />\n <path d=\"M21 16l-5-5-9 9\" {...common} />\n </>\n );\n } else if (icon === \"play\") {\n body = (\n <>\n <circle cx={12} cy={12} r={9} {...common} />\n <path d=\"M10 8.6l5.2 3.4-5.2 3.4z\" {...common} />\n </>\n );\n } else if (icon === \"spark\") {\n const step = Math.floor(frame / 3) % 8;\n body = Array.from({ length: 8 }, (_, i) => {\n const a = (i * Math.PI) / 4;\n const o = 0.25 + 0.75 * (((i - step + 8) % 8) / 7);\n return (\n <path\n key={`r${i}`}\n d={`M${12 + Math.cos(a) * 4} ${12 + Math.sin(a) * 4}L${12 + Math.cos(a) * 8.5} ${12 + Math.sin(a) * 8.5}`}\n {...common}\n strokeOpacity={o}\n />\n );\n });\n } else if (icon === \"wave\") {\n body = <path d=\"M4 10v4M8 7v10M12 4v16M16 8v8M20 10.5v3\" {...common} />;\n } else if (icon === \"music\") {\n body = (\n <>\n <path d=\"M9 18V6l10-2v12\" {...common} />\n <circle cx={6.5} cy={18} r={2.5} {...common} />\n <circle cx={16.5} cy={16} r={2.5} {...common} />\n </>\n );\n } else if (icon === \"palette\") {\n body = (\n <>\n <path\n d=\"M12 3a9 9 0 1 0 0 18c1.2 0 1.8-.9 1.8-1.8 0-1.3-1-1.6-1-2.7 0-1 .8-1.7 1.8-1.7H17a4 4 0 0 0 4-4C21 6.6 17 3 12 3z\"\n {...common}\n />\n <circle cx={7.5} cy={11} r={1.2} {...common} />\n <circle cx={10.5} cy={7.2} r={1.2} {...common} />\n <circle cx={15} cy={7.6} r={1.2} {...common} />\n </>\n );\n } else if (icon === \"wide\") {\n body = <rect x={2.5} y={7} width={19} height={10.5} rx={2} {...common} />;\n } else if (icon === \"tall\") {\n body = <rect x={7} y={2.5} width={10} height={19} rx={2} {...common} />;\n } else if (icon === \"square\") {\n body = <rect x={5} y={5} width={14} height={14} rx={2} {...common} />;\n } else if (icon === \"upload\") {\n body = <path d=\"M12 15.5V4M7 8.5L12 4l5 4.5M5 20h14\" {...common} />;\n }\n return (\n <svg\n viewBox=\"0 0 24 24\"\n width={size}\n height={size}\n style={{ display: \"block\", overflow: \"visible\" }}\n aria-hidden\n >\n {body}\n </svg>\n );\n}\n\nfunction Handles({\n w,\n h,\n k,\n color,\n fill,\n t,\n}: {\n w: number;\n h: number;\n k: number;\n color: string;\n fill: string;\n t: number;\n}) {\n if (t <= 0.001) return null;\n const s = 7 * k;\n const corners = [\n [0, 0],\n [w, 0],\n [0, h],\n [w, h],\n ];\n return (\n <>\n {corners.map(([cx, cy], i) => (\n <div\n key={`h${cx}-${cy}`}\n style={{\n position: \"absolute\",\n left: cx - s / 2,\n top: cy - s / 2,\n width: s,\n height: s,\n background: fill,\n border: `${1.25 * k}px solid ${color}`,\n borderRadius: 1.5 * k,\n transform: `scale(${Math.max(0, t - i * 0.04)})`,\n boxSizing: \"border-box\",\n }}\n />\n ))}\n </>\n );\n}\n\ntype Pt = { x: number; y: number };\n\nexport type GraphNodeSpec = {\n label: string;\n icons?: NodeIcon[];\n tint?: NodeTint;\n cols?: number;\n input?: string;\n};\n\nexport type GraphLayout = {\n title: string;\n nodes: Record<string, [number, number]>;\n edges: [string, string][];\n note?: { node: string; text: string };\n};\n\nexport type GraphRelayoutProps = {\n theme?: \"dark\" | \"light\";\n accent?: string;\n catalog?: Record<string, GraphNodeSpec>;\n layouts?: GraphLayout[];\n kicker?: string;\n cursorName?: string;\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n};\n\nconst DEFAULT_CATALOG: Record<string, GraphNodeSpec> = {\n prompt: { label: \"Prompt\", input: \"New launch\" },\n brand: { label: \"Brand kit\", icons: [\"palette\"], tint: \"amber\" },\n script: { label: \"Script\", icons: [\"doc\"], tint: \"violet\" },\n scenes: { label: \"Scenes\", icons: [\"frame\", \"image\"], tint: \"cyan\", cols: 2 },\n voice: { label: \"Voice\", icons: [\"wave\"], tint: \"green\" },\n music: { label: \"Music\", icons: [\"music\"], tint: \"coral\" },\n captions: { label: \"Captions\", icons: [\"captions\"], tint: \"violet\" },\n render: { label: \"Render\", icons: [\"spark\", \"play\"], tint: \"green\", cols: 2 },\n wide: { label: \"16:9\", icons: [\"wide\"], tint: \"pink\" },\n tall: { label: \"9:16\", icons: [\"tall\"], tint: \"pink\" },\n square: { label: \"1:1\", icons: [\"square\"], tint: \"pink\" },\n publish: { label: \"Publish\", icons: [\"upload\"], tint: \"blue\" },\n};\n\nconst DEFAULT_LAYOUTS: GraphLayout[] = [\n {\n title: \"A launch film\",\n nodes: {\n prompt: [0.08, 0.5],\n script: [0.3, 0.5],\n scenes: [0.5, 0.5],\n render: [0.7, 0.5],\n wide: [0.9, 0.5],\n },\n edges: [\n [\"prompt\", \"script\"],\n [\"script\", \"scenes\"],\n [\"scenes\", \"render\"],\n [\"render\", \"wide\"],\n ],\n },\n {\n title: \"Social cutdowns\",\n nodes: {\n prompt: [0.08, 0.26],\n brand: [0.08, 0.74],\n script: [0.29, 0.5],\n scenes: [0.5, 0.26],\n voice: [0.5, 0.74],\n render: [0.71, 0.5],\n wide: [0.91, 0.26],\n tall: [0.91, 0.74],\n },\n edges: [\n [\"prompt\", \"script\"],\n [\"brand\", \"script\"],\n [\"script\", \"scenes\"],\n [\"script\", \"voice\"],\n [\"scenes\", \"render\"],\n [\"voice\", \"render\"],\n [\"render\", \"wide\"],\n [\"render\", \"tall\"],\n ],\n },\n {\n title: \"Captions in every language\",\n nodes: {\n prompt: [0.08, 0.3],\n script: [0.28, 0.3],\n scenes: [0.49, 0.3],\n captions: [0.49, 0.78],\n render: [0.7, 0.3],\n wide: [0.9, 0.3],\n },\n edges: [\n [\"prompt\", \"script\"],\n [\"script\", \"scenes\"],\n [\"script\", \"captions\"],\n [\"scenes\", \"render\"],\n [\"captions\", \"render\"],\n [\"render\", \"wide\"],\n ],\n note: { node: \"captions\", text: \"12 languages, synced to voice\" },\n },\n {\n title: \"Every format at once\",\n nodes: {\n prompt: [0.07, 0.5],\n scenes: [0.28, 0.16],\n voice: [0.28, 0.5],\n music: [0.28, 0.84],\n render: [0.5, 0.5],\n wide: [0.72, 0.16],\n tall: [0.72, 0.5],\n square: [0.72, 0.84],\n publish: [0.93, 0.5],\n },\n edges: [\n [\"prompt\", \"scenes\"],\n [\"prompt\", \"voice\"],\n [\"prompt\", \"music\"],\n [\"scenes\", \"render\"],\n [\"voice\", \"render\"],\n [\"music\", \"render\"],\n [\"render\", \"wide\"],\n [\"render\", \"tall\"],\n [\"render\", \"square\"],\n [\"wide\", \"publish\"],\n [\"tall\", \"publish\"],\n [\"square\", \"publish\"],\n ],\n },\n];\n\nconst FIRST_HOLD = 36;\nconst STEP_GAPS = [34, 30, 28, 26];\nconst FINAL_HOLD = 58;\n\nexport function graphRelayoutTimeline(count: number) {\n const starts: number[] = [];\n let t = FIRST_HOLD;\n for (let i = 1; i < count; i++) {\n starts.push(t);\n t += STEP_GAPS[Math.min(i - 1, STEP_GAPS.length - 1)];\n }\n const last = starts.length ? starts[starts.length - 1] : 0;\n return { starts, end: last + FINAL_HOLD };\n}\n\nexport const GRAPH_RELAYOUT_DURATION = graphRelayoutTimeline(\n DEFAULT_LAYOUTS.length,\n).end;\n\nfunction sizeOf(spec: GraphNodeSpec) {\n if (spec.input !== undefined) {\n return {\n w: 14 + spec.input.length * 0.6 * FIELD_TEXT + 12 + 30 + 9,\n h: 48,\n };\n }\n const n = Math.max(1, spec.icons?.length ?? 1);\n const c = Math.max(1, Math.min(spec.cols ?? n, n));\n const r = Math.ceil(n / c);\n return {\n w: c * TILE + (c - 1) * TILE_GAP + PAD * 2,\n h: r * TILE + (r - 1) * TILE_GAP + PAD * 2,\n };\n}\n\nfunction curve(p0: Pt, p3: Pt, tall: boolean, k: number) {\n if (tall) {\n const d = Math.max(30 * k, Math.abs(p3.y - p0.y) * 0.5);\n return [p0, { x: p0.x, y: p0.y + d }, { x: p3.x, y: p3.y - d }, p3];\n }\n const d = Math.max(30 * k, Math.abs(p3.x - p0.x) * 0.5);\n return [p0, { x: p0.x + d, y: p0.y }, { x: p3.x - d, y: p3.y }, p3];\n}\n\nfunction sampleCurve(c: Pt[], frac: number) {\n const N = 36;\n const pts: Pt[] = [];\n for (let i = 0; i <= N; i++) {\n const t = i / N;\n const m = 1 - t;\n pts.push({\n x:\n m * m * m * c[0].x +\n 3 * m * m * t * c[1].x +\n 3 * m * t * t * c[2].x +\n t * t * t * c[3].x,\n y:\n m * m * m * c[0].y +\n 3 * m * m * t * c[1].y +\n 3 * m * t * t * c[2].y +\n t * t * t * c[3].y,\n });\n }\n const cum = [0];\n for (let i = 1; i <= N; i++) {\n cum.push(\n cum[i - 1] + Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y),\n );\n }\n const target = cum[N] * clamp01(frac);\n if (target < 0.5) return \"\";\n let d = `M${pts[0].x.toFixed(2)} ${pts[0].y.toFixed(2)}`;\n for (let i = 1; i <= N; i++) {\n if (cum[i] <= target) {\n d += `L${pts[i].x.toFixed(2)} ${pts[i].y.toFixed(2)}`;\n } else {\n const seg = cum[i] - cum[i - 1];\n const t = seg > 0 ? (target - cum[i - 1]) / seg : 0;\n d += `L${lerp(pts[i - 1].x, pts[i].x, t).toFixed(2)} ${lerp(pts[i - 1].y, pts[i].y, t).toFixed(2)}`;\n break;\n }\n }\n return d;\n}\n\nfunction Cursor({\n x,\n y,\n s,\n name,\n color,\n ink,\n edge,\n u,\n}: {\n x: number;\n y: number;\n s: number;\n name: string;\n color: string;\n ink: string;\n edge: string;\n u: number;\n}) {\n const size = 22 * u;\n return (\n <div\n style={{\n position: \"absolute\",\n left: x,\n top: y,\n transform: `scale(${s})`,\n transformOrigin: \"0 0\",\n filter: \"drop-shadow(0 2px 4px rgba(0,0,0,0.25))\",\n }}\n >\n <svg\n viewBox=\"0 0 24 24\"\n width={size}\n height={size}\n style={{ display: \"block\" }}\n aria-hidden\n >\n <path\n d=\"M3 2.5l7.2 18.2 2.6-7.6 7.7-2.7z\"\n fill={ink}\n stroke={edge}\n strokeWidth={1.5}\n strokeLinejoin=\"round\"\n />\n </svg>\n <div\n style={{\n position: \"absolute\",\n left: size * 0.75,\n top: size * 0.85,\n background: color,\n color: \"#ffffff\",\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: 15 * u,\n lineHeight: 1,\n padding: `${4 * u}px ${7 * u}px`,\n borderRadius: 6 * u,\n whiteSpace: \"nowrap\",\n }}\n >\n {name}\n </div>\n </div>\n );\n}\n\nexport function GraphRelayout({\n theme = \"dark\",\n accent,\n catalog = DEFAULT_CATALOG,\n layouts = DEFAULT_LAYOUTS,\n kicker = \"Use case\",\n cursorName = \"Mia\",\n ground,\n groundParams,\n}: GraphRelayoutProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, fps } = useVideoConfig();\n const uid = useId().replace(/:/g, \"\");\n const c = THEMES[theme];\n const tints = TINTS[theme];\n const acc = accent ?? (theme === \"dark\" ? tints.blue : c.accent);\n const btn = accent ?? c.accent;\n const tall = H > W * 1.1;\n const u = Math.min(W, H) / 720;\n const k = tall ? 1.42 * u : 1.34 * u;\n const labelU = tall ? 17 : LABEL;\n const { starts } = graphRelayoutTimeline(layouts.length);\n\n const rect = tall\n ? { x: 0.1 * W, y: 0.27 * H, w: 0.8 * W, h: 0.65 * H }\n : { x: 0.075 * W, y: 0.335 * H, w: 0.85 * W, h: 0.6 * H };\n const toPx = (p: [number, number]): Pt =>\n tall\n ? { x: rect.x + p[1] * rect.w, y: rect.y + p[0] * rect.h }\n : { x: rect.x + p[0] * rect.w, y: rect.y + p[1] * rect.h };\n\n const ids = Object.keys(catalog).filter((id) =>\n layouts.some((l) => l.nodes[id]),\n );\n const filled: Record<string, Pt[]> = {};\n for (const id of ids) {\n const arr: (Pt | null)[] = layouts.map((l) =>\n l.nodes[id] ? toPx(l.nodes[id]) : null,\n );\n let lastSeen: Pt | null = null;\n for (let i = 0; i < arr.length; i++) {\n if (arr[i]) lastSeen = arr[i];\n else if (lastSeen) arr[i] = lastSeen;\n }\n let nextSeen: Pt | null = null;\n for (let i = arr.length - 1; i >= 0; i--) {\n if (arr[i] && layouts[i].nodes[id]) nextSeen = arr[i];\n else if (!arr[i] && nextSeen) arr[i] = nextSeen;\n }\n filled[id] = arr.map((p) => p ?? { x: W / 2, y: H / 2 });\n }\n\n const dragged = starts.map((_, i) => {\n let best = \"\";\n let bestD = -1;\n for (const id of ids) {\n if (!layouts[i].nodes[id] || !layouts[i + 1].nodes[id]) continue;\n const a = filled[id][i];\n const b = filled[id][i + 1];\n const d = Math.hypot(a.x - b.x, a.y - b.y);\n if (d > bestD) {\n bestD = d;\n best = id;\n }\n }\n return best;\n });\n\n const order = (id: string) => {\n const p = layouts[0].nodes[id];\n return p ? p[0] : 0.5;\n };\n\n const nodeState = (id: string, f: number) => {\n const pts = filled[id];\n let x = pts[0].x;\n let y = pts[0].y;\n const firstIn = layouts[0].nodes[id] !== undefined;\n let vis = firstIn\n ? spring({\n frame: f + 5 - Math.round(order(id) * 12),\n fps,\n config: CARD,\n })\n : 0;\n for (let i = 0; i < starts.length; i++) {\n const s = starts[i];\n const lead = dragged[i] === id ? 0 : 1 + (ids.indexOf(id) % 3);\n const p = spring({\n frame: f - s - lead,\n fps,\n config: { mass: 0.8, damping: 15, stiffness: 150 },\n });\n x += (pts[i + 1].x - pts[i].x) * p;\n y += (pts[i + 1].y - pts[i].y) * p;\n const was = layouts[i].nodes[id] !== undefined;\n const is = layouts[i + 1].nodes[id] !== undefined;\n if (was && !is) vis -= EXIT(clamp01((f - s) / 8));\n if (!was && is) vis += spring({ frame: f - s - 6, fps, config: CHIP });\n }\n return { x, y, vis: Math.max(0, vis) };\n };\n\n const states: Record<string, { x: number; y: number; vis: number }> = {};\n for (const id of ids) states[id] = nodeState(id, frame);\n\n const specs: Record<\n string,\n Omit<GraphNodeSpec, \"tint\"> & { w: number; h: number; tint: string }\n > = {};\n for (const id of ids) {\n const sp = catalog[id];\n const sz = sizeOf(sp);\n specs[id] = {\n ...sp,\n ...sz,\n tint: sp.input !== undefined ? acc : tints[sp.tint ?? \"blue\"],\n };\n }\n\n const edgeKeys = new Map<string, [string, string]>();\n for (const l of layouts)\n for (const e of l.edges) edgeKeys.set(`${e[0]}>${e[1]}`, e);\n const edgeDraw = (key: string, f: number) => {\n const inL = (i: number) =>\n layouts[i].edges.some((e) => `${e[0]}>${e[1]}` === key);\n let v = 0;\n if (inL(0)) {\n const [a, b] = edgeKeys.get(key) ?? [\"\", \"\"];\n const t0 = 3 + Math.round(Math.max(order(a), order(b)) * 12);\n v = MOVE(clamp01((f - t0) / 10));\n }\n for (let i = 0; i < starts.length; i++) {\n const s = starts[i];\n const was = inL(i);\n const is = inL(i + 1);\n if (was && !is) v -= MOVE(clamp01((f - s) / 7));\n if (!was && is) v += MOVE(clamp01((f - s - 9) / 11));\n }\n return clamp01(v);\n };\n\n const port = (id: string, out: boolean): Pt => {\n const st = states[id];\n const sp = specs[id];\n const sc = 0.5 + 0.5 * Math.min(1, st.vis);\n if (tall)\n return { x: st.x, y: st.y + ((out ? 1 : -1) * sp.h * k * sc) / 2 };\n return { x: st.x + ((out ? 1 : -1) * sp.w * k * sc) / 2, y: st.y };\n };\n\n const restOf = (i: number): Pt => {\n const id = dragged[i];\n const p = filled[id][i + 1];\n const sp = specs[id];\n return { x: p.x + sp.w * k * 0.18, y: p.y + sp.h * k * 0.2 };\n };\n const grabOf = (i: number): Pt => {\n const id = dragged[i];\n const p = filled[id][i];\n const sp = specs[id];\n return { x: p.x + sp.w * k * 0.18, y: p.y + sp.h * k * 0.2 };\n };\n const cursorAt = (f: number) => {\n let pos: Pt = { x: W * 1.06, y: H * 1.08 };\n let press = 0;\n for (let i = 0; i < starts.length; i++) {\n const s = starts[i];\n const approach = ENTER(\n clamp01((f - (s - (i === 0 ? 18 : 12))) / (i === 0 ? 16 : 11)),\n );\n const g = grabOf(i);\n pos = { x: lerp(pos.x, g.x, approach), y: lerp(pos.y, g.y, approach) };\n if (f >= s) {\n const id = dragged[i];\n const st = nodeState(id, f);\n const sp = specs[id];\n const live = { x: st.x + sp.w * k * 0.18, y: st.y + sp.h * k * 0.2 };\n const rel = clamp01((f - s - 18) / 6);\n const r = restOf(i);\n pos = { x: lerp(live.x, r.x, rel), y: lerp(live.y, r.y, rel) };\n }\n press += clamp01((f - s + 3) / 3) - clamp01((f - s - 16) / 4);\n }\n const last = starts.length - 1;\n if (last >= 0) {\n const drift = ENTER(clamp01((f - starts[last] - 24) / 30));\n pos = { x: pos.x + drift * 70 * u, y: pos.y + drift * 46 * u };\n }\n return { ...pos, press: clamp01(press) };\n };\n const cursor = cursorAt(frame);\n\n const push = 1 + 0.03 * clamp01(frame / (GRAPH_RELAYOUT_DURATION + 10));\n const titleSize = tall ? 0.074 * W : 0.066 * H;\n const kickSize = (tall ? 18 : 16) * u;\n\n return (\n <AbsoluteFill style={{ background: c.ground.background }}>\n <GshGround\n preset={ground}\n params={\n ground && !groundParams ? undefined : (groundParams ?? c.ground)\n }\n timeOffset={7}\n timeScale={0.6}\n />\n <AbsoluteFill\n style={{\n transform: `scale(${push})`,\n transformOrigin: \"50% 60%\",\n }}\n >\n <svg\n width={W}\n height={H}\n style={{ position: \"absolute\", inset: 0, overflow: \"visible\" }}\n aria-hidden\n >\n <defs>\n <pattern\n id={`${uid}-dots`}\n width={24 * k}\n height={24 * k}\n patternUnits=\"userSpaceOnUse\"\n >\n <circle cx={12 * k} cy={12 * k} r={1.1 * k} fill={c.dot} />\n </pattern>\n </defs>\n <rect x={0} y={0} width={W} height={H} fill={`url(#${uid}-dots)`} />\n {[...edgeKeys.entries()].map(([key, [a, b]], ei) => {\n const v = edgeDraw(key, frame);\n if (v <= 0.001 || !states[a] || !states[b]) return null;\n const p0 = port(a, true);\n const p3 = port(b, false);\n const d = sampleCurve(curve(p0, p3, tall, k), v);\n if (!d) return null;\n const gid = `${uid}-g${ei}`;\n return (\n <g key={key}>\n <defs>\n <linearGradient\n id={gid}\n gradientUnits=\"userSpaceOnUse\"\n x1={p0.x}\n y1={p0.y}\n x2={p3.x + 0.01}\n y2={p3.y + 0.01}\n >\n <stop offset=\"0\" stopColor={specs[a].tint} />\n <stop offset=\"1\" stopColor={specs[b].tint} />\n </linearGradient>\n </defs>\n <path\n d={d}\n fill=\"none\"\n stroke={`url(#${gid})`}\n strokeWidth={1.6 * k}\n strokeDasharray={`${5 * k} ${5 * k}`}\n strokeDashoffset={-frame * 0.4 * k}\n strokeLinecap=\"round\"\n />\n </g>\n );\n })}\n </svg>\n\n {ids.map((id) => {\n const st = states[id];\n if (st.vis <= 0.005) return null;\n const sp = specs[id];\n const pw = sp.w * k;\n const ph = sp.h * k;\n const scale = 0.5 + 0.5 * st.vis;\n const isDrag = starts.some(\n (s, i) => dragged[i] === id && frame >= s - 3 && frame < s + 20,\n );\n const dragT = starts.reduce((acc, s, i) => {\n if (dragged[i] !== id) return acc;\n return Math.max(\n acc,\n spring({ frame: frame - s + 3, fps, config: CHIP }) -\n EXIT(clamp01((frame - s - 18) / 6)),\n );\n }, 0);\n const labelSize = labelU * k;\n const ins = [...edgeKeys.entries()].some(\n ([key, [, b]]) => b === id && edgeDraw(key, frame) > 0,\n );\n const outs = [...edgeKeys.entries()].some(\n ([key, [a]]) => a === id && edgeDraw(key, frame) > 0,\n );\n const portR = 3.4 * k;\n const portStyle = (x: number, y: number): React.CSSProperties => ({\n position: \"absolute\",\n left: x - portR,\n top: y - portR,\n width: portR * 2,\n height: portR * 2,\n borderRadius: portR,\n background: c.handle,\n border: `${1.4 * k}px solid ${sp.tint}`,\n boxSizing: \"border-box\",\n });\n const labelBox: React.CSSProperties = tall\n ? {\n left: -80 * k,\n width: pw + 160 * k,\n bottom: ph + 6 * k,\n justifyContent: \"center\",\n }\n : {\n left: -60 * k,\n width: pw + 120 * k,\n bottom: ph + 8 * k,\n justifyContent: \"center\",\n };\n return (\n <div\n key={id}\n style={{\n position: \"absolute\",\n left: st.x - pw / 2,\n top: st.y - ph / 2,\n width: pw,\n height: ph,\n opacity: clamp01(st.vis * 1.6),\n transform: `scale(${scale * (1 + 0.04 * (isDrag ? dragT : 0))})`,\n zIndex: isDrag ? 2 : 1,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n display: \"flex\",\n whiteSpace: \"nowrap\",\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: labelSize,\n lineHeight: 1,\n color: sp.tint,\n ...labelBox,\n }}\n >\n <span\n style={\n tall\n ? {\n background: c.handle,\n padding: `${3 * k}px ${6 * k}px`,\n borderRadius: 4 * k,\n }\n : undefined\n }\n >\n {sp.label}\n </span>\n </div>\n {sp.input !== undefined ? (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n borderRadius: 10 * k,\n background: c.field,\n border: `${1.5 * k}px solid ${sp.tint}`,\n boxShadow: c.shadow,\n display: \"flex\",\n alignItems: \"center\",\n paddingLeft: 14 * k,\n boxSizing: \"border-box\",\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: FIELD_TEXT * k,\n color: c.ink,\n whiteSpace: \"pre\",\n }}\n >\n {sp.input}\n <div\n style={{\n position: \"absolute\",\n right: 8 * k,\n top: ph / 2 - 15 * k,\n width: 30 * k,\n height: 30 * k,\n borderRadius: 15 * k,\n background: btn,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <svg\n viewBox=\"0 0 24 24\"\n width={16 * k}\n height={16 * k}\n aria-hidden\n >\n <path\n d=\"M5 12h14M13 6l6 6-6 6\"\n fill=\"none\"\n stroke={c.onAccent}\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n </div>\n </div>\n ) : (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n borderRadius: 6 * k,\n background: `linear-gradient(${alpha(sp.tint, theme === \"dark\" ? 0.12 : 0.09)}, ${alpha(sp.tint, theme === \"dark\" ? 0.12 : 0.09)}), ${c.nodeBase}`,\n border: `${1.5 * k}px solid ${sp.tint}`,\n boxShadow: c.shadow,\n boxSizing: \"border-box\",\n padding: (PAD - 1.5) * k,\n display: \"grid\",\n gridTemplateColumns: `repeat(${Math.max(1, Math.min(sp.cols ?? sp.icons?.length ?? 1, sp.icons?.length ?? 1))}, ${TILE * k}px)`,\n gridAutoRows: TILE * k,\n gap: TILE_GAP * k,\n }}\n >\n {(sp.icons ?? []).map((ic, j) => (\n <div\n key={`${id}-${ic}-${j}`}\n style={{\n width: TILE * k,\n height: TILE * k,\n borderRadius: 7 * k,\n border: `${1.2 * k}px dashed ${alpha(sp.tint, 0.6)}`,\n background: alpha(\n sp.tint,\n theme === \"dark\" ? 0.08 : 0.07,\n ),\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n boxSizing: \"border-box\",\n }}\n >\n <NodeGlyph\n icon={ic}\n size={21 * k}\n color={sp.tint}\n frame={frame}\n />\n </div>\n ))}\n </div>\n )}\n {ins ? (\n <div\n style={tall ? portStyle(pw / 2, 0) : portStyle(0, ph / 2)}\n />\n ) : null}\n {outs ? (\n <div\n style={tall ? portStyle(pw / 2, ph) : portStyle(pw, ph / 2)}\n />\n ) : null}\n <Handles\n w={pw}\n h={ph}\n k={k}\n color={sp.tint}\n fill={c.handle}\n t={isDrag ? dragT : 0}\n />\n </div>\n );\n })}\n\n {layouts.map((l, li) => {\n if (!l.note || !states[l.note.node]) return null;\n const s0 = li === 0 ? 0 : starts[li - 1];\n const s1 = li < starts.length ? starts[li] : 1e9;\n const inT = ENTER(clamp01((frame - s0 - 16) / 12));\n const outT = EXIT(clamp01((frame - s1) / 7));\n const v = inT * (1 - outT);\n if (v <= 0.001) return null;\n const st = states[l.note.node];\n const sp = specs[l.note.node];\n const size = (tall ? 20 : 17) * u;\n const textW = l.note.text.length * 0.6 * size;\n const pos: React.CSSProperties = tall\n ? {\n left: Math.min(\n Math.max(st.x - textW / 2, rect.x),\n rect.x + rect.w - textW,\n ),\n top: st.y + (sp.h * k) / 2 + 22 * k,\n }\n : {\n left: st.x + (sp.w * k) / 2 + 22 * k,\n top: st.y - size / 2,\n };\n return (\n <div\n key={`note-${l.title}`}\n style={{\n position: \"absolute\",\n ...pos,\n display: \"flex\",\n alignItems: \"center\",\n gap: 10 * k,\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: size,\n lineHeight: 1,\n color: c.ink,\n whiteSpace: \"nowrap\",\n opacity: v,\n transform: `translate${tall ? \"Y\" : \"X\"}(${(1 - inT) * 14 * k}px)`,\n }}\n >\n {tall ? null : (\n <span\n style={{\n width: 26 * k * inT,\n height: Math.max(1, 1.25 * k),\n background: c.boardStroke,\n }}\n />\n )}\n {l.note.text}\n </div>\n );\n })}\n\n <Cursor\n x={cursor.x}\n y={cursor.y}\n s={1 - 0.12 * cursor.press}\n name={cursorName}\n color={btn}\n ink={theme === \"dark\" ? \"#ffffff\" : \"#16181d\"}\n edge={theme === \"dark\" ? \"#16181d\" : \"#ffffff\"}\n u={tall ? 1.4 * u : u}\n />\n\n <div\n style={{\n position: \"absolute\",\n left: tall ? 0.08 * W : 0.075 * W,\n top: tall ? 0.075 * H : 0.1 * H,\n width: tall ? 0.84 * W : 0.85 * W,\n }}\n >\n {layouts.map((l, li) => {\n const s0 = li === 0 ? -14 : starts[li - 1];\n const s1 = li < starts.length ? starts[li] : 1e9;\n const inT = ENTER(clamp01((frame - s0 - 6) / 12));\n const outT = EXIT(clamp01((frame - s1) / 7));\n if (inT <= 0 || outT >= 1) return null;\n return (\n <div\n key={`t-${l.title}`}\n style={{ position: \"absolute\", left: 0, top: 0, width: \"100%\" }}\n >\n <div style={{ overflow: \"hidden\", paddingBottom: 4 * u }}>\n <div\n style={{\n fontFamily: mono.fontFamily,\n fontWeight: 400,\n fontSize: kickSize,\n lineHeight: 1.2,\n color: c.muted,\n transform: `translateY(${((1 - inT) * 1.2 - outT * 1.2) * kickSize}px)`,\n }}\n >\n {`${kicker} ${String(li + 1).padStart(2, \"0\")} / ${String(layouts.length).padStart(2, \"0\")}`}\n </div>\n </div>\n <div\n style={{\n overflow: \"hidden\",\n marginTop: 10 * u,\n paddingBottom: titleSize * 0.2,\n }}\n >\n <div\n style={{\n fontFamily: geist.fontFamily,\n fontWeight: 300,\n fontSize: titleSize,\n letterSpacing: \"-0.035em\",\n lineHeight: 1.06,\n color: c.ink,\n textWrap: \"balance\",\n transform: `translateY(${((1 - inT) * 1.15 - outT * 1.15) * titleSize * (tall ? 2.2 : 1)}px)`,\n filter: `blur(${(1 - inT + outT) * 4}px)`,\n }}\n >\n {l.title}\n </div>\n </div>\n </div>\n );\n })}\n </div>\n </AbsoluteFill>\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/graph-relayout.tsx"
}
],
"type": "registry:component"
}