import { d as attr_style, y as bind_props, f as stringify } from './dev-BNpEUZI3.js';
import { o as onDestroy } from './index-server-DocJvixA.js';
import { H as Hover_label, A as ALL_EDGE_KINDS } from './no-face-up-DcejJLy-.js';
import '@cosmograph/cosmos';

//#region src/lib/graph/renderers/CosmosRenderer.svelte
function CosmosRenderer($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/**
		* Props consumed by the macro / community / ego / flow views.
		*/
		/** Graph nodes — must include a stable id for every entry. */
		/** Graph edges — invalid endpoints are dropped silently. */
		/** Optional cluster registry for the caption layer. */
		/** Edge kinds currently rendered. Absent kinds fade to zero alpha. */
		/** Node kinds currently rendered. Absent kinds fade to zero alpha. */
		/** Node id to focus (camera pan + selection ring). */
		/** Called when the user pointer enters / exits a node. */
		/** Click handler — receives the full node object. */
		/** Show the cluster-caption overlay. Default: true. */
		/**
		* Explicit reduced-motion toggle. When omitted, the component
		* reads `prefers-reduced-motion` at mount and on change.
		*/
		/** Canvas height. Default `100%`. */
		/** Fired when the renderer fails to initialise (WebGL2 unavailable). */
		/**
		* Optional base alpha for non-highlighted nodes/edges.  Useful for
		* the ego view to dim hop-2 while staying visible.
		*/
		let { nodes, edges, clusters = [], visibleEdgeKinds, visibleNodeKinds, highlightNodeId = null, onNodeHover, onNodeClick, showClusterLabels = true, reducedMotion, height = "100%", onInitFailed, baseAlpha = .85 } = $$props;
		let hovered = null;
		let hoverX = 0;
		let hoverY = 0;
		let hoverSecondary = null;
		onDestroy(() => {
		});
		/** Number of edge-kind buckets we can render — from the shared kit. */
		const edgeKindCount = ALL_EDGE_KINDS.length;
		$$renderer.push(`<div class="cosmos-wrap svelte-a42v6k"${attr_style(`height: ${stringify(height)};`)}><div class="cosmos-canvas svelte-a42v6k"></div> `);
		$$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--> `);
		Hover_label($$renderer, {
			node: hovered,
			x: hoverX,
			y: hoverY,
			secondary: hoverSecondary
		});
		$$renderer.push(`<!----> `);
		$$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></div>`);
		bind_props($$props, { edgeKindCount });
	});
}
//#endregion
//#region src/lib/graph/adapters/nexus-adapter.ts
/**
* Edge kinds that explicitly encode direction. All other kinds render as
* a non-arrow line by default (the kit overrides per-style below).
*/
var DIRECTIONAL_KINDS = new Set([
	"calls",
	"extends",
	"implements",
	"imports",
	"contains",
	"defines",
	"has_method",
	"has_property",
	"accesses",
	"member_of"
]);
/**
* Strict mapping from the nexus relation-type string → canonical
* {@link EdgeKind}. Any string that lands outside the mapping is folded
* into `relates_to` so the renderer never crashes on unknown input.
*/
var NEXUS_RELATION_TO_EDGE_KIND = {
	contains: "contains",
	defines: "defines",
	imports: "imports",
	accesses: "accesses",
	calls: "calls",
	extends: "extends",
	implements: "implements",
	method_overrides: "extends",
	method_implements: "implements",
	has_method: "has_method",
	has_property: "has_property",
	member_of: "member_of",
	documents: "documents",
	applies_to: "references",
	references: "references",
	cites: "cites",
	step_in_process: "calls",
	entry_point_of: "defines",
	handles_route: "calls",
	handles_tool: "calls",
	fetches: "calls",
	queries: "accesses",
	wraps: "derived_from"
};
/**
* Map a nexus relation-type string to the canonical kit edge kind.
*
* Exported for tests + to let server loaders pre-classify when building
* macro-view aggregates.
*
* @param type - The raw `nexus_relations.type` value.
* @returns A canonical {@link EdgeKind}. Unknown strings map to `relates_to`.
*/
function mapNexusRelationToEdgeKind(type) {
	return NEXUS_RELATION_TO_EDGE_KIND[type] ?? "relates_to";
}
/**
* Normalise caller-count into a 0-1 `weight`. Uses a log curve so
* a single call doesn't appear identical to a mega-hub.
*
* @param callers - Raw caller count.
*/
function normaliseWeight(callers) {
	if (callers <= 0) return .1;
	return Math.min(1, Math.log10(callers + 1) / 3);
}
/**
* Convert nexus node + relation rows into the kit-wide graph shape.
*
* The function DOES NOT assign positions — callers pipe the output
* into `layout/nexus-layout.ts` or let the cosmos simulation settle
* the points from a random seed.
*
* @param nodes - Raw nexus_nodes rows.
* @param relations - Raw nexus_relations rows.
* @param opts - Optional override knobs.
*/
function adaptNexusRows(nodes, relations, opts) {
	const nodeIndex = /* @__PURE__ */ new Map();
	const clusterIndex = /* @__PURE__ */ new Map();
	for (const row of nodes) {
		if (!row.id) continue;
		const isCommunity = row.kind === "community";
		const node = {
			id: row.id,
			substrate: "nexus",
			kind: row.kind || "symbol",
			label: row.label || row.id,
			category: row.communityId ?? null,
			weight: normaliseWeight(row.callerCount ?? 0),
			meta: {
				filePath: row.filePath ?? null,
				callerCount: row.callerCount ?? 0
			}
		};
		nodeIndex.set(row.id, node);
		if (isCommunity) {
			const cluster = {
				id: row.id,
				label: row.label || row.id,
				substrate: "nexus",
				memberIds: []
			};
			clusterIndex.set(row.id, cluster);
		}
	}
	for (const node of nodeIndex.values()) {
		if (!node.category) continue;
		const cluster = clusterIndex.get(node.category);
		if (cluster) cluster.memberIds.push(node.id);
	}
	const edges = [];
	for (let i = 0; i < relations.length; i++) {
		const row = relations[i];
		if (!row.source || !row.target) continue;
		if (row.source === row.target) continue;
		if (!nodeIndex.has(row.source) || !nodeIndex.has(row.target)) continue;
		const kind = mapNexusRelationToEdgeKind(row.type);
		edges.push({
			id: row.id ?? `nxr-${i}-${row.source}-${row.target}-${kind}`,
			source: row.source,
			target: row.target,
			kind,
			weight: typeof row.weight === "number" ? Math.min(1, Math.max(0, row.weight)) : void 0,
			directional: DIRECTIONAL_KINDS.has(kind)
		});
	}
	return {
		nodes: [...nodeIndex.values()],
		edges,
		clusters: [...clusterIndex.values()]
	};
}
/**
* Build a macro-view graph from pre-aggregated community rows.
*
* @param communities - One row per community.
* @param edges - One row per directional community pair.
*/
function adaptNexusMacro(communities, edges) {
	const graphNodes = communities.map((c) => ({
		id: c.id,
		substrate: "nexus",
		kind: "community",
		label: c.label,
		category: c.id,
		weight: Math.min(1, Math.log10(c.memberCount + 1) / 3),
		meta: {
			memberCount: c.memberCount,
			topKind: c.topKind
		}
	}));
	const clusters = communities.map((c) => ({
		id: c.id,
		label: c.label,
		substrate: "nexus",
		memberIds: [c.id]
	}));
	const nodeIds = new Set(graphNodes.map((n) => n.id));
	return {
		nodes: graphNodes,
		edges: edges.filter((e) => nodeIds.has(e.source) && nodeIds.has(e.target) && e.source !== e.target).map((e, idx) => ({
			id: `macro-${idx}-${e.source}-${e.target}`,
			source: e.source,
			target: e.target,
			kind: e.kind,
			weight: Math.min(1, e.weight / 100),
			directional: DIRECTIONAL_KINDS.has(e.kind)
		})),
		clusters
	};
}

export { CosmosRenderer as C, adaptNexusMacro as a, adaptNexusRows as b, mapNexusRelationToEdgeKind as m };
//# sourceMappingURL=nexus-adapter-9EL_VlGI.js.map
