project-graph-mcp 2.2.6 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +81 -0
- package/CHANGELOG.md +57 -0
- package/README.md +9 -4
- package/package.json +4 -13
- package/project-graph-mcp-2.3.0.tgz +0 -0
- package/src/compact/expand.js +1 -1
- package/src/core/graph-builder.js +2 -2
- package/src/core/parser.js +2 -2
- package/src/network/server.js +1 -2
- package/src/network/web-server.js +1 -1
- package/vendor/symbiote-node/CHANGELOG.md +31 -0
- package/vendor/symbiote-node/LICENSE +21 -0
- package/vendor/symbiote-node/README.md +206 -0
- package/vendor/symbiote-node/canvas/AutoLayout.js +725 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.css.js +73 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.js +93 -0
- package/vendor/symbiote-node/canvas/Breadcrumb/Breadcrumb.tpl.js +9 -0
- package/vendor/symbiote-node/canvas/CanvasConnectionRenderer.js +962 -0
- package/vendor/symbiote-node/canvas/ConnectionRenderer.js +1468 -0
- package/vendor/symbiote-node/canvas/FlowSimulator.js +323 -0
- package/vendor/symbiote-node/canvas/ForceLayout.js +189 -0
- package/vendor/symbiote-node/canvas/ForceWorker.js +1325 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.css.js +97 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.js +176 -0
- package/vendor/symbiote-node/canvas/GraphTabs/GraphTabs.tpl.js +12 -0
- package/vendor/symbiote-node/canvas/LODManager.js +88 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.css.js +71 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.js +207 -0
- package/vendor/symbiote-node/canvas/Minimap/Minimap.tpl.js +9 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.css.js +261 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.js +1840 -0
- package/vendor/symbiote-node/canvas/NodeCanvas/NodeCanvas.tpl.js +22 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.css.js +97 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.js +132 -0
- package/vendor/symbiote-node/canvas/NodeSearch/NodeSearch.tpl.js +21 -0
- package/vendor/symbiote-node/canvas/NodeViewManager.js +584 -0
- package/vendor/symbiote-node/canvas/PinExpansion.js +131 -0
- package/vendor/symbiote-node/canvas/PseudoConnection.js +80 -0
- package/vendor/symbiote-node/canvas/SubgraphManager.js +201 -0
- package/vendor/symbiote-node/canvas/SubgraphRouter.js +443 -0
- package/vendor/symbiote-node/canvas/ViewportActions.js +446 -0
- package/vendor/symbiote-node/core/Connection.js +45 -0
- package/vendor/symbiote-node/core/Editor.js +451 -0
- package/vendor/symbiote-node/core/Frame.js +31 -0
- package/vendor/symbiote-node/core/GraphMermaid.js +348 -0
- package/vendor/symbiote-node/core/GraphText.js +210 -0
- package/vendor/symbiote-node/core/Node.js +143 -0
- package/vendor/symbiote-node/core/Portal.js +104 -0
- package/vendor/symbiote-node/core/Socket.js +185 -0
- package/vendor/symbiote-node/core/SubgraphNode.js +125 -0
- package/vendor/symbiote-node/index.js +103 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.css.js +361 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.js +332 -0
- package/vendor/symbiote-node/inspector/InspectorPanel/InspectorPanel.tpl.js +96 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.css.js +104 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.js +133 -0
- package/vendor/symbiote-node/inspector/TemplatePreview/TemplatePreview.tpl.js +33 -0
- package/vendor/symbiote-node/interactions/ConnectFlow.js +307 -0
- package/vendor/symbiote-node/interactions/Drag.js +102 -0
- package/vendor/symbiote-node/interactions/Selector.js +132 -0
- package/vendor/symbiote-node/interactions/SnapGrid.js +65 -0
- package/vendor/symbiote-node/interactions/Zoom.js +140 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.css.js +88 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.js +254 -0
- package/vendor/symbiote-node/layout/ActionZone/ActionZone.tpl.js +11 -0
- package/vendor/symbiote-node/layout/Layout/Layout.css.js +88 -0
- package/vendor/symbiote-node/layout/Layout/Layout.js +622 -0
- package/vendor/symbiote-node/layout/Layout/Layout.tpl.js +25 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.css.js +293 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.js +467 -0
- package/vendor/symbiote-node/layout/LayoutNode/LayoutNode.tpl.js +33 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.css.js +46 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.js +102 -0
- package/vendor/symbiote-node/layout/LayoutPreview/LayoutPreview.tpl.js +6 -0
- package/vendor/symbiote-node/layout/LayoutRouter/LayoutRouter.js +156 -0
- package/vendor/symbiote-node/layout/LayoutRouter/routerSync.js +250 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.css.js +379 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.js +263 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/LayoutSidebar.tpl.js +20 -0
- package/vendor/symbiote-node/layout/LayoutSidebar/SidebarSection.js +183 -0
- package/vendor/symbiote-node/layout/LayoutTree.js +246 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.css.js +43 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.js +89 -0
- package/vendor/symbiote-node/layout/PanelMenu/PanelMenu.tpl.js +14 -0
- package/vendor/symbiote-node/layout/index.js +16 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.css.js +61 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.js +79 -0
- package/vendor/symbiote-node/menu/ContextMenu/ContextMenu.tpl.js +19 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.css.js +41 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.js +24 -0
- package/vendor/symbiote-node/node/CtrlItem/CtrlItem.tpl.js +16 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.css.js +65 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.js +29 -0
- package/vendor/symbiote-node/node/GraphFrame/GraphFrame.tpl.js +13 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.css.js +683 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.js +92 -0
- package/vendor/symbiote-node/node/GraphNode/GraphNode.tpl.js +17 -0
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.js +25 -0
- package/vendor/symbiote-node/node/NodeSocket/NodeSocket.tpl.js +7 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.css.js +90 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.js +87 -0
- package/vendor/symbiote-node/node/PortItem/PortItem.tpl.js +10 -0
- package/vendor/symbiote-node/package.json +59 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.css.js +143 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.js +131 -0
- package/vendor/symbiote-node/palette/PaletteBrowser/PaletteBrowser.tpl.js +16 -0
- package/vendor/symbiote-node/plugins/History.js +384 -0
- package/vendor/symbiote-node/plugins/Readonly.js +59 -0
- package/vendor/symbiote-node/shapes/CircleShape.js +80 -0
- package/vendor/symbiote-node/shapes/CommentShape.js +35 -0
- package/vendor/symbiote-node/shapes/DiamondShape.js +115 -0
- package/vendor/symbiote-node/shapes/NodeShape.js +80 -0
- package/vendor/symbiote-node/shapes/PillShape.js +91 -0
- package/vendor/symbiote-node/shapes/RectShape.js +72 -0
- package/vendor/symbiote-node/shapes/SVGShape.js +494 -0
- package/vendor/symbiote-node/shapes/index.js +53 -0
- package/vendor/symbiote-node/themes/Palette.js +32 -0
- package/vendor/symbiote-node/themes/Skin.js +113 -0
- package/vendor/symbiote-node/themes/Theme.js +84 -0
- package/vendor/symbiote-node/themes/carbon.js +137 -0
- package/vendor/symbiote-node/themes/dark.js +137 -0
- package/vendor/symbiote-node/themes/ebook.js +138 -0
- package/vendor/symbiote-node/themes/grey.js +137 -0
- package/vendor/symbiote-node/themes/light.js +137 -0
- package/vendor/symbiote-node/themes/neon.js +138 -0
- package/vendor/symbiote-node/themes/pcb.js +273 -0
- package/vendor/symbiote-node/themes/synthwave.js +137 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.css.js +86 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.js +128 -0
- package/vendor/symbiote-node/toolbar/QuickToolbar/QuickToolbar.tpl.js +29 -0
- package/web/app.js +9 -5
- package/web/components/canvas-graph.js +1705 -0
- package/web/components/code-block.js +1 -1
- package/web/components/event-feed/CodeWidget.js +32 -0
- package/web/components/event-feed/EventWidget.js +97 -0
- package/web/components/event-feed/ListWidget.js +57 -0
- package/web/components/event-feed/MiniGraphWidget.js +159 -0
- package/web/components/follow-ribbon.js +134 -0
- package/web/dashboard.js +1 -1
- package/web/follow-controller.js +241 -0
- package/web/index.html +4 -0
- package/web/panels/ActionBoard/ActionBoard.js +1 -1
- package/web/panels/SettingsPanel/SettingsPanel.tpl.js +1 -1
- package/web/panels/code-viewer.js +50 -15
- package/web/panels/dep-graph.js +2691 -7
- package/web/panels/file-tree.js +5 -2
- package/web/panels/live-monitor.js +75 -3
- package/web/style.css +39 -0
- package/docs/img/explorer-compact.jpg +0 -0
- package/docs/img/explorer-expanded.jpg +0 -0
- package/src/.contextignore +0 -22
- package/src/.project-graph-cache.json +0 -1
- package/src/compact/.project-graph-cache.json +0 -1
- package/web/.project-graph-cache.json +0 -1
- package/web/panels/SettingsPanel/.project-graph-cache.json +0 -1
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FlowSimulator — sequential data flow animation
|
|
3
|
+
*
|
|
4
|
+
* Performs topological traversal of the node graph and animates
|
|
5
|
+
* nodes and connections step-by-step (like n8n execution).
|
|
6
|
+
*
|
|
7
|
+
* @module symbiote-node/canvas/FlowSimulator
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} FlowSimulatorConfig
|
|
12
|
+
* @property {import('../core/Editor.js').NodeEditor} editor
|
|
13
|
+
* @property {Object} canvas - NodeCanvas instance (for setFlowing, node views)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export class FlowSimulator {
|
|
17
|
+
|
|
18
|
+
/** @type {import('../core/Editor.js').NodeEditor} */
|
|
19
|
+
#editor;
|
|
20
|
+
|
|
21
|
+
/** @type {Object} */
|
|
22
|
+
#canvas;
|
|
23
|
+
|
|
24
|
+
/** @type {boolean} */
|
|
25
|
+
#running = false;
|
|
26
|
+
|
|
27
|
+
/** @type {AbortController|null} */
|
|
28
|
+
#abort = null;
|
|
29
|
+
|
|
30
|
+
/** @type {number} ms per node step */
|
|
31
|
+
speed = 800;
|
|
32
|
+
|
|
33
|
+
/** @type {boolean} follow active node with camera */
|
|
34
|
+
followActive = false;
|
|
35
|
+
|
|
36
|
+
/** @type {boolean} temporarily paused by manual interaction */
|
|
37
|
+
#followPaused = false;
|
|
38
|
+
|
|
39
|
+
/** @type {number|null} */
|
|
40
|
+
#followResumeTimer = null;
|
|
41
|
+
|
|
42
|
+
/** @type {number} ms before follow resumes after manual interaction */
|
|
43
|
+
followResumDelay = 3000;
|
|
44
|
+
|
|
45
|
+
/** Bound handler for manualviewport event */
|
|
46
|
+
#handleManualViewport = () => {
|
|
47
|
+
if (!this.followActive || !this.#running) return;
|
|
48
|
+
this.#followPaused = true;
|
|
49
|
+
if (this.#followResumeTimer) clearTimeout(this.#followResumeTimer);
|
|
50
|
+
this.#followResumeTimer = setTimeout(() => {
|
|
51
|
+
this.#followPaused = false;
|
|
52
|
+
this.#followResumeTimer = null;
|
|
53
|
+
}, this.followResumDelay);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {import('../core/Editor.js').NodeEditor} editor
|
|
58
|
+
* @param {Object} canvas - NodeCanvas instance
|
|
59
|
+
*/
|
|
60
|
+
constructor(editor, canvas) {
|
|
61
|
+
this.#editor = editor;
|
|
62
|
+
this.#canvas = canvas;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @returns {boolean} */
|
|
66
|
+
get running() {
|
|
67
|
+
return this.#running;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Run sequential flow animation
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
async run() {
|
|
75
|
+
if (this.#running) return;
|
|
76
|
+
this.#running = true;
|
|
77
|
+
this.#abort = new AbortController();
|
|
78
|
+
this.#followPaused = false;
|
|
79
|
+
this.#canvas.addEventListener('manualviewport', this.#handleManualViewport);
|
|
80
|
+
|
|
81
|
+
const order = this.#topologicalSort();
|
|
82
|
+
const connections = this.#editor.getConnections();
|
|
83
|
+
this.#editor.emit('flowstart', { nodes: order });
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
for (const nodeId of order) {
|
|
87
|
+
if (this.#abort.signal.aborted) break;
|
|
88
|
+
|
|
89
|
+
// Mark node as processing
|
|
90
|
+
this.#setNodeState(nodeId, 'processing');
|
|
91
|
+
this.#editor.emit('nodeprocessing', { nodeId });
|
|
92
|
+
|
|
93
|
+
// Smooth pan to active node
|
|
94
|
+
if (this.followActive && !this.#followPaused) {
|
|
95
|
+
this.#canvas.panToNode?.(nodeId);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Run inner flow for subgraph nodes
|
|
99
|
+
const node = this.#editor.getNode(nodeId);
|
|
100
|
+
if (node?._isSubgraph && node.innerEditor) {
|
|
101
|
+
await this.#runInnerFlow(nodeId, node);
|
|
102
|
+
} else {
|
|
103
|
+
await this.#wait(this.speed);
|
|
104
|
+
}
|
|
105
|
+
if (this.#abort.signal.aborted) break;
|
|
106
|
+
|
|
107
|
+
// Mark node as completed
|
|
108
|
+
this.#setNodeState(nodeId, 'completed');
|
|
109
|
+
this.#editor.emit('nodecompleted', { nodeId });
|
|
110
|
+
|
|
111
|
+
// Animate outgoing connections
|
|
112
|
+
const outgoing = connections.filter((c) => c.from === nodeId);
|
|
113
|
+
for (const conn of outgoing) {
|
|
114
|
+
this.#canvas.setFlowing(conn.id, true);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await this.#wait(this.speed * 0.5);
|
|
118
|
+
if (this.#abort.signal.aborted) break;
|
|
119
|
+
|
|
120
|
+
// Stop flowing
|
|
121
|
+
for (const conn of outgoing) {
|
|
122
|
+
this.#canvas.setFlowing(conn.id, false);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Emit completion
|
|
127
|
+
if (!this.#abort.signal.aborted) {
|
|
128
|
+
this.#editor.emit('flowcomplete', {});
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
this.#running = false;
|
|
132
|
+
this.#abort = null;
|
|
133
|
+
this.#canvas.removeEventListener('manualviewport', this.#handleManualViewport);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Stop animation and clear all states */
|
|
138
|
+
stop() {
|
|
139
|
+
if (this.#abort) this.#abort.abort();
|
|
140
|
+
this.#running = false;
|
|
141
|
+
this.#canvas.removeEventListener('manualviewport', this.#handleManualViewport);
|
|
142
|
+
if (this.#followResumeTimer) {
|
|
143
|
+
clearTimeout(this.#followResumeTimer);
|
|
144
|
+
this.#followResumeTimer = null;
|
|
145
|
+
}
|
|
146
|
+
this.#followPaused = false;
|
|
147
|
+
|
|
148
|
+
// Clear all node states
|
|
149
|
+
for (const node of this.#editor.getNodes()) {
|
|
150
|
+
this.#clearNodeState(node.id);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Clear all flowing
|
|
154
|
+
this.#canvas.setAllFlowing(false);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Topological sort — Kahn's algorithm
|
|
159
|
+
* Returns node IDs ordered from sources to sinks
|
|
160
|
+
* @returns {string[]}
|
|
161
|
+
*/
|
|
162
|
+
#topologicalSort() {
|
|
163
|
+
const nodes = this.#editor.getNodes();
|
|
164
|
+
const connections = this.#editor.getConnections();
|
|
165
|
+
|
|
166
|
+
// Collect only nodes that participate in connections
|
|
167
|
+
/** @type {Set<string>} */
|
|
168
|
+
const connectedIds = new Set();
|
|
169
|
+
for (const conn of connections) {
|
|
170
|
+
connectedIds.add(conn.from);
|
|
171
|
+
connectedIds.add(conn.to);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Build adjacency + in-degree for connected nodes only
|
|
175
|
+
/** @type {Map<string, string[]>} */
|
|
176
|
+
const adj = new Map();
|
|
177
|
+
/** @type {Map<string, number>} */
|
|
178
|
+
const inDeg = new Map();
|
|
179
|
+
|
|
180
|
+
for (const node of nodes) {
|
|
181
|
+
if (!connectedIds.has(node.id)) continue;
|
|
182
|
+
adj.set(node.id, []);
|
|
183
|
+
inDeg.set(node.id, 0);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const conn of connections) {
|
|
187
|
+
adj.get(conn.from)?.push(conn.to);
|
|
188
|
+
inDeg.set(conn.to, (inDeg.get(conn.to) || 0) + 1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Start from nodes with no incoming connections
|
|
192
|
+
/** @type {string[]} */
|
|
193
|
+
const queue = [];
|
|
194
|
+
for (const [id, deg] of inDeg) {
|
|
195
|
+
if (deg === 0) queue.push(id);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** @type {string[]} */
|
|
199
|
+
const result = [];
|
|
200
|
+
while (queue.length > 0) {
|
|
201
|
+
const id = queue.shift();
|
|
202
|
+
result.push(id);
|
|
203
|
+
for (const next of adj.get(id) || []) {
|
|
204
|
+
const newDeg = (inDeg.get(next) || 1) - 1;
|
|
205
|
+
inDeg.set(next, newDeg);
|
|
206
|
+
if (newDeg === 0) queue.push(next);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Animate inner nodes of a subgraph sequentially in its preview canvas
|
|
215
|
+
* @param {string} nodeId - Parent subgraph node ID
|
|
216
|
+
* @param {import('../core/SubgraphNode.js').SubgraphNode} node
|
|
217
|
+
*/
|
|
218
|
+
async #runInnerFlow(nodeId, node) {
|
|
219
|
+
const el = this.#canvas._getNodeView?.(nodeId);
|
|
220
|
+
if (!el) {
|
|
221
|
+
await this.#wait(this.speed);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const innerEditor = node.innerEditor;
|
|
226
|
+
const innerNodes = innerEditor.getNodes();
|
|
227
|
+
const innerConns = innerEditor.getConnections();
|
|
228
|
+
|
|
229
|
+
if (innerNodes.length === 0) {
|
|
230
|
+
await this.#wait(this.speed);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Topological sort of inner nodes
|
|
235
|
+
const adj = new Map();
|
|
236
|
+
const inDeg = new Map();
|
|
237
|
+
for (const n of innerNodes) {
|
|
238
|
+
adj.set(n.id, []);
|
|
239
|
+
inDeg.set(n.id, 0);
|
|
240
|
+
}
|
|
241
|
+
for (const conn of innerConns) {
|
|
242
|
+
adj.get(conn.from)?.push(conn.to);
|
|
243
|
+
inDeg.set(conn.to, (inDeg.get(conn.to) || 0) + 1);
|
|
244
|
+
}
|
|
245
|
+
const queue = [];
|
|
246
|
+
for (const [id, deg] of inDeg) {
|
|
247
|
+
if (deg === 0) queue.push(id);
|
|
248
|
+
}
|
|
249
|
+
const innerOrder = [];
|
|
250
|
+
while (queue.length > 0) {
|
|
251
|
+
const id = queue.shift();
|
|
252
|
+
innerOrder.push(id);
|
|
253
|
+
for (const next of adj.get(id) || []) {
|
|
254
|
+
const newDeg = (inDeg.get(next) || 1) - 1;
|
|
255
|
+
inDeg.set(next, newDeg);
|
|
256
|
+
if (newDeg === 0) queue.push(next);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Distribute speed across inner nodes
|
|
261
|
+
const stepTime = this.speed / Math.max(innerOrder.length, 1);
|
|
262
|
+
el._innerFlowStates = {};
|
|
263
|
+
|
|
264
|
+
for (const innerId of innerOrder) {
|
|
265
|
+
if (this.#abort.signal.aborted) break;
|
|
266
|
+
|
|
267
|
+
el._innerFlowStates[innerId] = 'processing';
|
|
268
|
+
el._redrawPreview?.();
|
|
269
|
+
|
|
270
|
+
await this.#wait(stepTime * 0.6);
|
|
271
|
+
if (this.#abort.signal.aborted) break;
|
|
272
|
+
|
|
273
|
+
el._innerFlowStates[innerId] = 'completed';
|
|
274
|
+
el._redrawPreview?.();
|
|
275
|
+
|
|
276
|
+
await this.#wait(stepTime * 0.4);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Set visual state on a node element
|
|
282
|
+
* @param {string} nodeId
|
|
283
|
+
* @param {'processing'|'completed'} state
|
|
284
|
+
*/
|
|
285
|
+
#setNodeState(nodeId, state) {
|
|
286
|
+
const el = this.#canvas._getNodeView?.(nodeId);
|
|
287
|
+
if (!el) return;
|
|
288
|
+
el.removeAttribute('data-processing');
|
|
289
|
+
el.removeAttribute('data-completed');
|
|
290
|
+
el.setAttribute(`data-${state}`, '');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Clear visual state from a node element
|
|
295
|
+
* @param {string} nodeId
|
|
296
|
+
*/
|
|
297
|
+
#clearNodeState(nodeId) {
|
|
298
|
+
const el = this.#canvas._getNodeView?.(nodeId);
|
|
299
|
+
if (!el) return;
|
|
300
|
+
el.removeAttribute('data-processing');
|
|
301
|
+
el.removeAttribute('data-completed');
|
|
302
|
+
// Clear inner flow states for subgraph nodes
|
|
303
|
+
if (el._innerFlowStates) {
|
|
304
|
+
el._innerFlowStates = {};
|
|
305
|
+
el._redrawPreview?.();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Cancellable delay
|
|
311
|
+
* @param {number} ms
|
|
312
|
+
* @returns {Promise<void>}
|
|
313
|
+
*/
|
|
314
|
+
#wait(ms) {
|
|
315
|
+
return new Promise((resolve) => {
|
|
316
|
+
const timer = setTimeout(resolve, ms);
|
|
317
|
+
this.#abort?.signal.addEventListener('abort', () => {
|
|
318
|
+
clearTimeout(timer);
|
|
319
|
+
resolve();
|
|
320
|
+
}, { once: true });
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ForceLayout — Main-thread wrapper for the ForceWorker.
|
|
3
|
+
*
|
|
4
|
+
* Manages Web Worker lifecycle and streams position updates
|
|
5
|
+
* to the canvas via requestAnimationFrame batching.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const force = new ForceLayout(canvas);
|
|
9
|
+
* force.start({ nodes, edges, groups, options });
|
|
10
|
+
* force.onTick = (positions) => { ... };
|
|
11
|
+
* force.stop();
|
|
12
|
+
*
|
|
13
|
+
* @module symbiote-node/canvas/ForceLayout
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export class ForceLayout {
|
|
17
|
+
/** @type {Worker|null} */
|
|
18
|
+
#worker = null;
|
|
19
|
+
|
|
20
|
+
/** @type {boolean} */
|
|
21
|
+
#running = false;
|
|
22
|
+
|
|
23
|
+
/** @type {boolean} */
|
|
24
|
+
#paused = false;
|
|
25
|
+
|
|
26
|
+
/** @type {object|null} */
|
|
27
|
+
#latestPositions = null;
|
|
28
|
+
|
|
29
|
+
/** @type {number|null} */
|
|
30
|
+
#rafId = null;
|
|
31
|
+
|
|
32
|
+
/** @type {string[]|null} Node ID order for unpacking Float32Array */
|
|
33
|
+
#nodeIds = null;
|
|
34
|
+
|
|
35
|
+
/** @type {Function|null} */
|
|
36
|
+
onTick = null;
|
|
37
|
+
|
|
38
|
+
/** @type {Function|null} */
|
|
39
|
+
onDone = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} workerUrl - URL to ForceWorker.js
|
|
43
|
+
*/
|
|
44
|
+
constructor(workerUrl) {
|
|
45
|
+
this._workerUrl = workerUrl;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Start force simulation.
|
|
50
|
+
* @param {object} data
|
|
51
|
+
* @param {Array<{id: string, x?: number, y?: number, mass?: number, group?: string}>} data.nodes
|
|
52
|
+
* @param {Array<{from: string, to: string, strength?: number}>} data.edges
|
|
53
|
+
* @param {Object<string, string[]>} [data.groups] - { groupId: [nodeId, ...] }
|
|
54
|
+
* @param {object} [data.options] - Override simulation parameters (mode: 'converge'|'continuous')
|
|
55
|
+
*/
|
|
56
|
+
start(data) {
|
|
57
|
+
this.stop();
|
|
58
|
+
|
|
59
|
+
this.#worker = new Worker(this._workerUrl);
|
|
60
|
+
this.#running = true;
|
|
61
|
+
this.#paused = false;
|
|
62
|
+
this.#nodeIds = null;
|
|
63
|
+
|
|
64
|
+
this.#worker.onmessage = (e) => {
|
|
65
|
+
const msg = e.data;
|
|
66
|
+
|
|
67
|
+
// Continuous mode: receive node ID order once for Float32Array unpacking
|
|
68
|
+
if (msg.type === 'nodeIds') {
|
|
69
|
+
this.#nodeIds = msg.ids;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (msg.type === 'tick') {
|
|
74
|
+
// Unpack Float32Array if present (continuous mode)
|
|
75
|
+
if (msg.packed && this.#nodeIds) {
|
|
76
|
+
const buf = new Float32Array(msg.packed);
|
|
77
|
+
const positions = {};
|
|
78
|
+
for (let i = 0; i < this.#nodeIds.length; i++) {
|
|
79
|
+
positions[this.#nodeIds[i]] = {
|
|
80
|
+
x: Math.round(buf[i * 2]),
|
|
81
|
+
y: Math.round(buf[i * 2 + 1]),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
this.#latestPositions = positions;
|
|
85
|
+
} else {
|
|
86
|
+
// Converge mode: positions as plain object
|
|
87
|
+
this.#latestPositions = msg.positions;
|
|
88
|
+
}
|
|
89
|
+
this.#scheduleRender();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (msg.type === 'done') {
|
|
93
|
+
this.#latestPositions = msg.positions;
|
|
94
|
+
this.#flushRender();
|
|
95
|
+
this.#running = false;
|
|
96
|
+
this.#paused = false;
|
|
97
|
+
this.onDone?.(msg.positions, msg.iteration);
|
|
98
|
+
this.#cleanup();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
this.#worker.onerror = (err) => {
|
|
103
|
+
console.error('[ForceLayout] Worker error:', err);
|
|
104
|
+
this.#running = false;
|
|
105
|
+
this.#paused = false;
|
|
106
|
+
this.#cleanup();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
this.#worker.postMessage({ type: 'init', ...data });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Stop simulation and terminate Worker. */
|
|
113
|
+
stop() {
|
|
114
|
+
if (this.#worker) {
|
|
115
|
+
this.#worker.postMessage({ type: 'stop' });
|
|
116
|
+
}
|
|
117
|
+
this.#cleanup();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Pause simulation (continuous mode). Worker stays alive. */
|
|
121
|
+
pause() {
|
|
122
|
+
if (!this.#worker || !this.#running || this.#paused) return;
|
|
123
|
+
this.#paused = true;
|
|
124
|
+
this.#worker.postMessage({ type: 'pause' });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Resume simulation (continuous mode). Gentle reheat. */
|
|
128
|
+
resume() {
|
|
129
|
+
if (!this.#worker || !this.#running || !this.#paused) return;
|
|
130
|
+
this.#paused = false;
|
|
131
|
+
this.#worker.postMessage({ type: 'resume' });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Pin a node at a fixed position (for drag interactions).
|
|
136
|
+
* In continuous mode, triggers local reheat.
|
|
137
|
+
* @param {string} id
|
|
138
|
+
* @param {number} x
|
|
139
|
+
* @param {number} y
|
|
140
|
+
*/
|
|
141
|
+
pin(id, x, y) {
|
|
142
|
+
if (!this.#worker || !this.#running) return;
|
|
143
|
+
this.#worker.postMessage({ type: 'pin', id, x, y });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Release a pinned node.
|
|
148
|
+
* @param {string} id
|
|
149
|
+
*/
|
|
150
|
+
unpin(id) {
|
|
151
|
+
if (!this.#worker || !this.#running) return;
|
|
152
|
+
this.#worker.postMessage({ type: 'unpin', id });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** @returns {boolean} */
|
|
156
|
+
get running() { return this.#running; }
|
|
157
|
+
|
|
158
|
+
/** @returns {boolean} */
|
|
159
|
+
get paused() { return this.#paused; }
|
|
160
|
+
|
|
161
|
+
#scheduleRender() {
|
|
162
|
+
if (this.#rafId !== null) return;
|
|
163
|
+
this.#rafId = requestAnimationFrame(() => {
|
|
164
|
+
this.#rafId = null;
|
|
165
|
+
this.#flushRender();
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#flushRender() {
|
|
170
|
+
if (this.#latestPositions) {
|
|
171
|
+
this.onTick?.(this.#latestPositions);
|
|
172
|
+
this.#latestPositions = null;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#cleanup() {
|
|
177
|
+
if (this.#rafId !== null) {
|
|
178
|
+
cancelAnimationFrame(this.#rafId);
|
|
179
|
+
this.#rafId = null;
|
|
180
|
+
}
|
|
181
|
+
if (this.#worker) {
|
|
182
|
+
this.#worker.terminate();
|
|
183
|
+
this.#worker = null;
|
|
184
|
+
}
|
|
185
|
+
this.#running = false;
|
|
186
|
+
this.#paused = false;
|
|
187
|
+
this.#nodeIds = null;
|
|
188
|
+
}
|
|
189
|
+
}
|