);
}
function findNodeById(
sections: import('./types').DiagramSection[],
nodeId: string,
): import('../../api/queries/diagrams').DiagramNode | undefined {
for (const section of sections) {
for (const node of section.nodes) {
if (node.id === nodeId) return node;
if (node.children) {
const found = findInChildren(node.children, nodeId);
if (found) return found;
}
}
}
return undefined;
}
function findInChildren(
nodes: import('../../api/queries/diagrams').DiagramNode[],
nodeId: string,
): import('../../api/queries/diagrams').DiagramNode | undefined {
for (const n of nodes) {
if (n.id === nodeId) return n;
if (n.children) {
const found = findInChildren(n.children, nodeId);
if (found) return found;
}
}
return undefined;
}
/** Returns true if the edge connects two top-level nodes (not inside any compound). */
function topLevelEdge(
edge: import('../../api/queries/diagrams').DiagramEdge,
nodes: import('../../api/queries/diagrams').DiagramNode[],
): boolean {
// Collect all IDs that are children of compound nodes (at any depth)
const compoundChildIds = new Set();
for (const n of nodes) {
if (n.children && n.children.length > 0) {
collectDescendantIds(n.children, compoundChildIds);
}
}
return !compoundChildIds.has(edge.sourceId) && !compoundChildIds.has(edge.targetId);
}
function collectDescendantIds(
nodes: import('../../api/queries/diagrams').DiagramNode[],
set: Set,
) {
for (const n of nodes) {
if (n.id) set.add(n.id);
if (n.children) collectDescendantIds(n.children, set);
}
}