feat: add render graph driven renderer architecture

Amp-Thread-ID: https://ampcode.com/threads/T-019f9d91-77c1-7206-a60f-ed6554ce92ab

Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
This commit is contained in:
Amp
2026-07-27 02:53:44 +00:00
co-authored by heaust
parent 8a8369706b
commit d4e8634f67
290 changed files with 48804 additions and 1995 deletions
+35
View File
@@ -0,0 +1,35 @@
import type { FxNodeDefinition, FxNodeSocketTypeDefinition, FxNodeStyleDefinition } from "@lib/index.js";
export const numberSocket = [
"number",
{ title: "Number", color: "#a8a8a8", acceptsFrom: ["number"] },
] as const satisfies readonly [string, FxNodeSocketTypeDefinition];
export const minimalStyles = { value: { header: "#4c6ef5" } } as const satisfies Readonly<
Record<string, FxNodeStyleDefinition>
>;
export const valueNode = [
"example.minimal.value",
{
version: 1,
title: "Number Value",
behavior: "standard",
style: "value",
parameters: { value: { type: "number", default: { kind: "number", value: 42 }, step: 1 } },
sockets: {
value: {
title: "Value",
direction: "output",
type: "number",
maxIncomingLinks: 0,
visible: true,
value: null,
showValue: false,
},
},
ui: [
{ kind: "parameter", parameter: "value" },
{ kind: "socket", socket: "value" },
],
muteBypass: [],
migrations: [],
},
] as const satisfies readonly [string, FxNodeDefinition];
+17
View File
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>fxnode minimal example</title>
<link rel="stylesheet" href="../shared/example.css" />
</head>
<body>
<main>
<h1>Minimal custom node</h1>
<p>The smallest useful custom number/value node.</p>
<canvas id="graph" width="1000" height="560" aria-label="Minimal node graph"></canvas>
</main>
<script type="module" src="./main.ts"></script>
</body>
</html>
+56
View File
@@ -0,0 +1,56 @@
import { createFxNode } from "@lib/index.js";
import { prepareFxNodeBrowserHost } from "../shared/browser-host.js";
import { exampleTheme } from "../shared/theme.js";
import { minimalStyles, numberSocket, valueNode } from "./definition.js";
const canvas = document.querySelector<HTMLCanvasElement>("#graph")!;
const host = prepareFxNodeBrowserHost({ canvas });
let cleanedUp = false;
function cleanup() {
window.removeEventListener("pagehide", cleanup);
cleanedUp = true;
const root = handle.root,
view = handle.view;
handle.root = null;
handle.view = null;
host.destroy();
const destroyRoot = () => root?.destroy();
if (view) void view.detach().then(destroyRoot, destroyRoot);
else destroyRoot();
}
const handle: StandaloneExampleHandle = {
root: null,
view: null,
host,
ready: Promise.resolve(),
cleanup,
};
window.fxnodeStandalone = handle;
window.addEventListener("pagehide", cleanup);
handle.ready = (async () => {
try {
const root = await createFxNode({
applicationId: "fxnode.example.minimal",
applicationVersion: 1,
resources: {},
});
if (cleanedUp) {
root.destroy();
return;
}
handle.root = root;
await root.setTheme(exampleTheme);
await root.setHeaderStyles(minimalStyles);
await root.composeSocket(...numberSocket);
await root.composeNode(...valueNode);
await root.setState({ graphId: "minimal", catalogVersion: 1, nodes: [], links: [], metadata: {} });
const view = await root.attachView({ canvas, viewport: host.initialViewport });
handle.view = view;
host.attach(root, view);
await view.addNode({ nodeId: "value", typeId: valueNode[0], viewPosition: { x: 360, y: 190 } });
await view.whenRendered();
} catch (error) {
handle.cleanup();
throw error;
}
})();